Skip to content

Commit

Permalink
Fix in contract deployment
Browse files Browse the repository at this point in the history
In evm_host::create(), the evmc::result return object must have the
create_address member set to the new contract address (the VM does
not set it)

If left as 0x0, deployment of contracts by another contract (i.e. at
depth>0) is likely to fail such as in UniswapV3Factory.createPool()

Signed-off-by: Alexander Jung <104335080+AlexRamRam@users.noreply.github.com>
  • Loading branch information
AlexRamRam committed Jul 21, 2023
1 parent 287d00b commit 1605c22
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/3pc/agent/runners/evm/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace cbdc::threepc::agent::runner {
const evmc::bytes32& salt,
const cbdc::hash_t& bytecode_hash)
-> evmc::address {
// Specs: https://eips.ethereum.org/EIPS/eip-1014

auto new_addr = evmc::address();
auto buf = cbdc::buffer();
static constexpr uint8_t contract_address2_preimage_prefix = 0xFF;
Expand Down
7 changes: 7 additions & 0 deletions src/3pc/agent/runners/evm/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ namespace cbdc::threepc::agent::runner {
auto res = execute(call_msg, msg.input_data, msg.input_size);

if(res.status_code == EVMC_SUCCESS) {
// The VM does not populate res.create_address, and it must
// set to the address of the new contract.
// If left as 0x0, deployment of contracts by another contract
// (i.e. depth>0) is likely to fail (e.g.
// UniswapV3Factory.createPool())
res.create_address = new_addr;

auto maybe_acc = get_account(new_addr, !m_is_readonly_run);
if(!maybe_acc.has_value()) {
maybe_acc = evm_account();
Expand Down

0 comments on commit 1605c22

Please sign in to comment.