Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVM: dont panic on invalid precompile address #1042

Merged
merged 4 commits into from
Jan 13, 2023

Conversation

mriise
Copy link
Contributor

@mriise mriise commented Jan 13, 2023

This:

  • Checks if address is in reserved precompile range, then will try to resolve the exact one, otherwise return fail and no return value
  • No longer panics in call/staticcall if precompile was found, instead return an ActorError
  • Documents behavior of get_contract_type (used by delagatecall) if precompile address is not a valid precompile, but still within precompile range.

@@ -66,6 +66,12 @@ impl U256 {
buf
}

/// Returns bottom 20 bytes
pub fn to_address_bytes(&self) -> [u8; 20] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl From<U256> for EthAddress {
fn from(v: U256) -> Self {
let mut bytes = [0u8; 32];
v.to_big_endian(&mut bytes);
Self(bytes[12..].try_into().unwrap())
}
}

We don't need a second way to do this (the existing way also avoids allocating).

Comment on lines 209 to 210
if precompiles::Precompiles::<RT>::is_precompile(&dst) {
match precompiles::Precompiles::call_precompile(system, dst, input_data, context) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call and have call_precompile return an error if the precompile doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would give us with Result<Result<Vec<u8>, PrecompileError>, ()> how about Option<Result<Vec<u8>, PrecompileError>> ?

@@ -61,8 +61,8 @@ const fn gen_native_precompiles<RT: Runtime>() -> [PrecompileFn<RT>; 4] {
}
}

pub fn is_reserved_precompile_address(addr: [u8; 20]) -> bool {
let [prefix, middle @ .., index] = addr;
pub fn is_reserved_precompile_address(addr: &U256) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than change this to a U256, I'd change it to an EthAddress. It'll be faster and will simplify a lot of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep.

…nstead of whatever insanity i did last night
@mriise mriise marked this pull request as ready for review January 13, 2023 17:58
@mriise mriise requested a review from Stebalien January 13, 2023 17:58
@Stebalien Stebalien enabled auto-merge (squash) January 13, 2023 18:11
}
}
None => {
log::warn!(target: "evm", "Non-existing precompile address: {:?}", EthAddress::from(dst));
(0, vec![])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this should actually return success.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Er, well... You know what? I don't care. Technically, we should return success.... but this is just so stupid.

Let's just return an error.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, people use the dead address. We need this to just work. More than that, we need to discard the funds????????

@Stebalien Stebalien merged commit e41d332 into next Jan 13, 2023
@Stebalien Stebalien deleted the fix/call-invalid-precompile-panic branch January 13, 2023 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

F26: CALL & STATICCALL panic when passed invalid precompile address
2 participants