I'm currently completing the Ethernaut challenges, one of them is to deploy a small contract (runtime bytecode is 10 bytes long).
I'm running the tests on my local machine, and using Solidity to deploy the contract.
I'm using the CREATE
opcode to deploy the bytecode, which I have explicitly defined in the contract. The results are the same for CREATE2
.
When I use EXTCODESIZE
to get back the contract code size for my deployed contract, it is returning 32
, when the runtime bytecode size is for sure 10 (with initialization bytecode the size is 22
).
My code:
function Deploy() public returns(uint) {
bytes memory code = "\x60\x0a\x60\x0c\x60\x00\x39\x60\x20\x60\x00\xf3\x60\x42\x60\x80\x52\x60\x20\x60\x80\xf3";
address addr;
uint size;
assembly {
addr := create(0, add(code, 0x20), mload(code))
size := extcodesize(addr)
if iszero(extcodesize(addr)) {
revert(0, 0)
}
}
return size;
}
Why is it returning 32? I know this is the min word size but I am not padding the code
input with zeros. However, the returned result (via EXTCODECOPY
) is padded with zeros.