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

Source mappings do not point to the correct location #5135

Closed
kaisert opened this issue Oct 2, 2018 · 5 comments
Closed

Source mappings do not point to the correct location #5135

kaisert opened this issue Oct 2, 2018 · 5 comments

Comments

@kaisert
Copy link

kaisert commented Oct 2, 2018

Description

The source mappings gained through solc --combined-json srcmap-runtime does not always give the correct translation from instruction offset to source code.

Environment

  • Compiler version: tested with 0.4.25, 0.4.24, 0.4.11, 0.4.18
  • Framework/IDE (e.g. Truffle or Remix): tested locally and on remix
  • Operating system: linux

Steps to Reproduce

Minimal example:

contract c {
    int[] a;
    function f() public {
        a.length = 1;
    } 
}

When checking to which source code offset the SSTORE instructions correspond to, the source mapping indicates the beginning of the contract. Expected would be a.length = 1.

@chriseth
Copy link
Contributor

chriseth commented Oct 2, 2018

Are you talking about the 8:9:-1 part? Note the -1 at the end which indicates "unknown file". The reason behind this is that the source for storing the number is an assembly library routine of the compiler whose code is not part of the initial source code.

@kaisert
Copy link
Author

kaisert commented Oct 2, 2018

So when compiling the given example, the complete source mapping is

0:82:0:-;;;;;;;;;;;;;;;;;;;;;;;;30:49;;8:9:-1;5:2;;;30:1;27;20:12;5:2;30:49:0;;;;;;;71:1;60;:12;;;;;:::i;:::-;;30:49::o;0:82::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o

. I am talking about the 0:82::- part, which points to the given source file (due to 30:49:0 a few entries before)

@chriseth
Copy link
Contributor

chriseth commented Oct 2, 2018

Ah right, that's a different helper routine, the "array resize routine". Since it can be used from multiple points, the closest source map that can be provided is the whole file.

@yann300 can you give some insights into source map cleanup / filtering that is done in remix for the break points?

@kaisert
Copy link
Author

kaisert commented Oct 2, 2018

So what is the difference between these two helper functions? Or in other words: Why is the first one deemed to be in an unknown file, while the second one references the whole file?

@chriseth
Copy link
Contributor

chriseth commented Oct 4, 2018

The first one is built using yul, the other one uses the old style code generator. The difference is that yul actually is source code, while the second is just a sequence of opcodes.

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

2 participants