Skip to content

Commit

Permalink
IPC-506: Fix GetCode and GetStorageAt for ethaccount (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh authored Jan 8, 2024
1 parent 0c5f8f7 commit 003ac8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
33 changes: 22 additions & 11 deletions fendermint/fendermint/eth/api/examples/ethers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,27 +601,38 @@ where
// We could calculate the storage location of the balance of the owner of the contract,
// but let's just see what it returns with at slot 0. See an example at
// https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getstorageat
let storage_location = {
let mut bz = [0u8; 32];
U256::zero().to_big_endian(&mut bz);
H256::from_slice(&bz)
};

request(
"eth_getStorageAt",
mw.get_storage_at(
contract.address(),
{
let mut bz = [0u8; 32];
U256::zero().to_big_endian(&mut bz);
H256::from_slice(&bz)
},
None,
)
.await,
mw.get_storage_at(contract.address(), storage_location, None)
.await,
|_| true,
)?;

request(
"eth_code",
"eth_getStorageAt /w account",
mw.get_storage_at(from.eth_addr, storage_location, None)
.await,
|_| true,
)?;

request(
"eth_getCode",
mw.get_code(contract.address(), None).await,
|bz| *bz == deployed_bytecode,
)?;

request(
"eth_getCode /w account",
mw.get_code(from.eth_addr, None).await,
|bz| bz.is_empty(),
)?;

request("eth_syncing", mw.syncing().await, |s| {
*s == SyncingStatus::IsFalse // There is only one node.
})?;
Expand Down
9 changes: 8 additions & 1 deletion fendermint/fendermint/eth/api/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,14 @@ where
.context("failed to call contract")?;

if result.value.code.is_err() {
return error(ExitCode::new(result.value.code.value()), result.value.info);
return match ExitCode::new(result.value.code.value()) {
ExitCode::USR_UNHANDLED_MESSAGE => {
// If the account is an ETHACCOUNT then it doesn't handle certain methods like `GetCode`.
// Let's make it work the same way as a PLACEHOLDER and return nothing.
Ok(None)
}
other => error(other, result.value.info),
};
}

tracing::debug!(addr = ?address, method_num, data = hex::encode(&result.value.data), "evm actor response");
Expand Down

0 comments on commit 003ac8f

Please sign in to comment.