Skip to content

Commit

Permalink
EVM: Fix resolve address errors (#1031)
Browse files Browse the repository at this point in the history
* use precompile error value since it is now not actually returned and will log a more helpful reason than just empty vec. also add some logging

* fmt

* i hate clippy sometimes

* test was not actually testing for not found like it said it was
  • Loading branch information
mriise authored Jan 12, 2023
1 parent 0f4a75d commit b9333d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 8 additions & 2 deletions actors/evm/src/interpreter/precompiles/fvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,18 @@ pub(super) fn resolve_address<RT: Runtime>(
let len = input_params.next_param_padded::<u32>()? as usize;
let addr = match Address::from_bytes(&right_pad(input_params.remaining_slice(), len)) {
Ok(o) => o,
Err(_) => return Ok(Vec::new()),
Err(e) => {
log::debug!(target: "evm", "Address parsing failed: {e}");
return Err(PrecompileError::InvalidInput);
}
};
Ok(system
.rt
.resolve_address(&addr)
.map(|a| U256::from(a).to_bytes().to_vec())
.map(|a| {
log::debug!(target: "evm", "{addr} resolved to {a}");
U256::from(a).to_bytes().to_vec()
})
.unwrap_or_default())
}

Expand Down
10 changes: 9 additions & 1 deletion actors/evm/tests/precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,15 @@ fn test_precompile_failure() {

// not found succeeds with empty
rt.expect_gas_available(10_000_000_000u64);
let result = util::invoke_contract(&mut rt, &U256::from(111).to_bytes());
let input = {
let addr = FILAddress::new_delegated(111, b"foo").unwrap().to_bytes();
// first word is len
let mut v = U256::from(addr.len()).to_bytes().to_vec();
// then addr
v.extend_from_slice(&addr);
v
};
let result = util::invoke_contract(&mut rt, &input);
rt.verify();
assert_eq!(&[1u8], result.as_slice());
rt.reset();
Expand Down

0 comments on commit b9333d2

Please sign in to comment.