1

I have found the articles explaining how storage works and I understand that if I have a mapping that I need to know the key. What I'm trying to do is figure out how given, solidity code, abi, and storage that I can do one any of the following given:

contract test {
  uint16 public var1;
  uint16 public var2;
  mapping(address => int) public maps;
  address[] public mapItems;

  function test() {
      var1 = 4;
      var2 = 6;
      mapItems.push(0x7E57a31C7B88a92Be263f7a9Fd6D58E6a9CE4d7C);
      maps[0x7E57a31C7B88a92Be263f7a9Fd6D58E6a9CE4d7C] = 6;
  }


}
  1. Know that var 1 is in the first 16 bytes of the storage at index 0.
  2. Know that var 2 is in the second 16 bytes of the storage at index 0.
  3. Know that maps is at index 2 so that I can do the keccaking necessary to get the real index.
  4. Know that mapItmes is at index 3 so that i can do the keccacking necessary to get the real index.

I would assume that solc is calculating this at some point and integrating it into the bytecode, but does it every get output anywhere accessible. It doesn't seem to be in the ABI (although that would be a cool place to put it).

I know that I should create a getter and setter for these in my contracts, but if I'm analyzing someone else's that hasn't done this I'd like to still get this data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.