Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

srcmaps are byte-denominated, slither assumes char-denomination #586

Closed
bohendo opened this issue Jan 27, 2025 · 2 comments
Closed

srcmaps are byte-denominated, slither assumes char-denomination #586

bohendo opened this issue Jan 27, 2025 · 2 comments

Comments

@bohendo
Copy link
Contributor

bohendo commented Jan 27, 2025

This is the contract I'm investigating as a proof of concept:

contract Test {
  function one() external view returns(uint256) {
      return 1;
  }
  // ││ Unicode Comment ││
  function two() external view returns(uint256) {
      return 2;
  }
}

Notice that the four vertical lines of the unicode comment are ascii art box-drawing characters, each is 3 bytes long. This file is therefore 185 characters long and 193 bytes long. (difference of 8 = 4 * (3-1))

cat src/Test.sol | wc -c -m
    185     193

This python script:

from crytic_compile import CryticCompile

file = "src/Test.sol"
cc = CryticCompile(file);

for su in cc.compilation_units[file].source_units.items():
    print(su[1].srcmaps_runtime)

prints:

{'Test': ['0:192:0:-:0', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '123:67', '184:1', '123:67', '', '', '160:25:1', '', '', '148:2', '133:18', '123:67:0', '', '', '', '', '', '', '18', '79:1', '18:67', '']}

The first chunk from 0-192 shows that the srcmaps provided by the solc platform are byte-denominated.

Slither encode files as utf8, therefore offsets interpreted as char-denominated.

In particular, this misalignment causes slither-mutate to fail. For example, it will mutate the one function of Test.sol fine, but all mutations after the unicode comment will be off-by-8.

@bohendo
Copy link
Contributor Author

bohendo commented Jan 27, 2025

This bug seems to be downstream from solidity#14733

@bohendo
Copy link
Contributor Author

bohendo commented Jan 27, 2025

resolved by slither#2648

@bohendo bohendo closed this as completed Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant