The address is the last 20 bytes of sha3(publicKey)
In Solidity, using assembly if needed, how could I splice the first 12 bytes from sha3(publicKey)
and get the address? What I came up with runs out of gas:
bytes32 b = sha3(publicKey)
address signer;
assembly {
signer := mload(add(b, 0x0c) // skip the first 12 bytes, 0c in hex = 12
}
MLOAD(0XAB) loads the word (32 byte) located at the memory address 0XAB. Does my function fail because it is trying to load 20 byte only? Can MLOAD load only 20 byte?
sha3(pk)+12
, which is (very likely) a 256-bit number. You're running out of gas because expanding memory to such high a location eats all of it.add(b, 0x0c)
is analogous to pointer arithmetic. (It gives you the location in memory 12 bytes past the beginning ofb
.)