The Solidity Contract-Oriented Programming Language - By chatting here you agree to the https://github.com/ethereum/solidity/blob/develop/CODE_OF_CONDUCT.md
struct foo {
uint8 a
address b
uint8 b
}
It will be less optimal than packing them in the declaration right ?
Very specific question, if you have an idea without testing if I do :
address a;
uint16 b;
uint16 c;
uint32 d;
uint32 e;
uint32 f;
uint32 g;
uint32 h;
uint32 i;
Is it more or less optimal than
address a;
uint32 b;
uint32 c;
uint32 d;
uint32 e;
uint32 f;
uint32 g;
uint32 h;
uint32 i;
?
struct foo {
uint8 a
address b
uint8 b
}
or
ing the value into the mstore
's parameter.
@holiman
function clone(address _contractAddress, address _creatorAddress, uint4 _uniqueId) {
address retval;
assembly {
mstore(0x0, or (0x5880730000000000000000000000000000000000000000803b80938091923c77, mul(_contractAddress, 0x1000000000000000000)))
mstore(0x20, or (0x00000000000000000000000000000000000000000000000082529060200190F3 , mul( or (mul(_creatorAddress, 0x100000000), _uniqueId), 0x10000000000000000)))
retval := create(0,0, 64)
}
return retval;
}
This is what I got so far. I have not tried to run it yet.
PUSH24
to account for 20 bytes of the creator address and 4 byte integer tag. So the 24 bytes of data get stored at position 0 in the second mstore
. Using the entire 32 bytes of the second slot for something useful.
#python3 initcode.py
Bytecode: 60008073123456789a123456789a123456789a123456789a803b80938091923c61133882529060200190f3
/home/martin/go/src/github.com/ethereum/go-ethereum/build/bin/evm --code 60008073123456789a123456789a123456789a123456789a803b80938091923c61133882529060200190f3 --prestate /tmp/genesis-genesis-geth_5oQI3Twu.json --gas 65535 --json run
PUSH1 []
DUP1 ['0x0']
PUSH20 ['0x0', '0x0']
DUP1 ['0x0', '0x0', '0x123456789a123456789a123456789a123456789a']
EXTCODESIZE ['0x0', '0x0', '0x123456789a123456789a123456789a123456789a', '0x123456789a123456789a123456789a123456789a']
DUP1 ['0x0', '0x0', '0x123456789a123456789a123456789a123456789a', '0x2']
SWAP4 ['0x0', '0x0', '0x123456789a123456789a123456789a123456789a', '0x2', '0x2']
DUP1 ['0x2', '0x0', '0x123456789a123456789a123456789a123456789a', '0x2', '0x0']
SWAP2 ['0x2', '0x0', '0x123456789a123456789a123456789a123456789a', '0x2', '0x0', '0x0']
SWAP3 ['0x2', '0x0', '0x123456789a123456789a123456789a123456789a', '0x0', '0x0', '0x2']
EXTCODECOPY ['0x2', '0x0', '0x2', '0x0', '0x0', '0x123456789a123456789a123456789a123456789a']
PUSH2 ['0x2', '0x0']
DUP3 ['0x2', '0x0', '0x1338']
MSTORE ['0x2', '0x0', '0x1338', '0x2']
SWAP1 ['0x2', '0x0']
PUSH1 ['0x0', '0x2']
ADD ['0x0', '0x2', '0x20']
SWAP1 ['0x0', '0x22']
RETURN ['0x22', '0x0']
{"output":"13370000000000000000000000000000000000000000000000000000000000001338","gasUsed":"0x5b1","time":319959}
# geth = vm.GethVM("/home/martin/go/src/github.com/ethereum/go-ethereum/build/bin/evm")
geth = vm.GethVM("holiman/gethvm", docker=True)
docker pull holiman/gethvm
, otherwise it'll time out trying to download it within evmlab
geth
, this uses evm