ethereum / aleth

Aleth – Ethereum C++ client, tools and libraries
GNU General Public License v3.0
3.96k stars 2.18k forks source link

Incorrect RETURNDATASIZE and RETURNDATACOPY implementation #5887

Closed jafri closed 4 years ago

jafri commented 4 years ago

https://github.com/ethereum/aleth/blob/093e9bc08cc241e6c144a0903c3920ed7c54ac8a/libaleth-interpreter/VMCalls.cpp#L148 it appears that in the case create, RETURNDATACOPY and RETURNDATASIZE return the entire output.

This appears to be contradictory to EIP 211, which states "As an exception, CREATE and CREATE2 are considered to return the empty buffer in the success case and the failure data in the failure case."

Cross-comparing to parity VM, where the success case does not set return data: https://github.com/paritytech/parity-ethereum/blob/654632264b81e0dbeffdbafbc96cfa4273f43a87/ethcore/evm/src/interpreter/mod.rs#L567-L575

gumb0 commented 4 years ago

Thank you for looking into this.

I think in the success case result.output_data stays empty, it has some data only in case of REVERT.

The code controlling this is in Executive::go (called inside m_host->call(m_context, &msg)) - you can see in the if (m_isCreation) branch result of execution is used as the code for the new contract, but m_output is not filled (it's filled only for non-creation and in case of revert exception) https://github.com/ethereum/aleth/blob/093e9bc08cc241e6c144a0903c3920ed7c54ac8a/libethereum/Executive.cpp#L495