I noticed that some ether transfers use more that 21000 gas. Here is an example which transferring ether from an UOA to a contract used 21033 gas:
unusual transaction
While another transfer with same from and to addresses used exactly 21000 gas:
normal transaction
Until today, I always assumed that every ether transfer uses exactly 21000 gas, was I wrong about it?
1 Answer
That's because when the normal transaction took place, there was no contract code at this address (it was created here at block 15158470, but the tx is at block 15152542). So all that was paid was the cost of a simple transfer (21000 gas) and no additional cost for code execution as there was no code to execute at that point.
The unusual transaction is targeting a contract that implements an empty receive function (at block 15209900) :
contract Example {
receive() external payable {
}
}
You can try to send value to such a contract and see a gas cost of 21033. The 33 additional gas are just for the memory initialization code and calldata size check, Typically on a contract with nothing but a receive function :
- PUSH1 80 (3)
- PUSH1 40 (3)
- MSTORE (3 + 9 for memory expansion cost)
- CALLDATASIZE (2)
- PUSH1 0x?? (3)
- JUMPI (10)
- STOP (0)
Which makes for a total additional cost of 33 that is explained by code execution.
-
Thank you for the precise answer. But how come the address is used to receive ether before the contract get created on that address? Does it mean that the address was a UOA until block 15158470 and then is associated to newly created contract? Isn't it weird? Commented Jul 25, 2022 at 10:33
-
2Well you can know the address of a future contract deployment either with create (and a known nonce) so it's totally possible to send value, create the contract and send value again. Without code associated to it yes, it can be considered as an EAO until code is added to that address. It's not common for sure, but not impossible neither. Commented Jul 25, 2022 at 10:55