2

If I deploy the following contract in Remix the bytes array test get stored at address 0x00 in storage.

contract parseBytes {
  bytes test = "\x20\x00\x10";
  function f() {
    assembly{
        test //should push address of test bytes array and offset to stack
        pop //should pop offset
    }
  }
}

If I extend the bytes array to longer than 31 bytes the storage looks:

0x0000000000000000000000000000000000000000000000000000000000000000: 41 0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563: a020001000100001000e238989d74a050072b08989d74a050040000f0204000000

So it seems that the 32bytes get stored elsewhere (at address 0x290...). How can I retrieve this address using inline assembly? Executing the function above the stack contains the values:

0: 0x2d //is not the address of the bytes array in storage

1: 0x26121ff0

3
pragma solidity ^0.4.8;

contract parseBytes {
  bytes test = "\x20\x00\x10\x10\x10";
  function f(){
    bytes32 adr;
    assembly{
        adr := sha3(0, 32)
    }
  }
}

Bytes and string are stored in storage at sha3(slot). So in this case slot is 0. In below code adr gives the address from which test is stored.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.