-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conversation
actors/evm/src/interpreter/uints.rs
Outdated
@@ -66,6 +66,12 @@ impl U256 { | |||
buf | |||
} | |||
|
|||
/// Returns bottom 20 bytes | |||
pub fn to_address_bytes(&self) -> [u8; 20] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builtin-actors/actors/evm/src/interpreter/address.rs
Lines 19 to 25 in 54417ac
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).
if precompiles::Precompiles::<RT>::is_precompile(&dst) { | ||
match precompiles::Precompiles::call_precompile(system, dst, input_data, context) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
} | ||
} | ||
None => { | ||
log::warn!(target: "evm", "Non-existing precompile address: {:?}", EthAddress::from(dst)); | ||
(0, vec![]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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????????
This: