Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 138 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions actors/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude = ["/precompile-testdata", "/tests/measurements", "/tests/contracts"]
crate-type = ["cdylib", "lib"]

[dependencies]
p256 = { version = "0.13.2", features = ["ecdsa"], default-features = false }
fil_actors_runtime = { workspace = true }
fvm_shared = { workspace = true }
fvm_ipld_kamt = { workspace = true }
Expand All @@ -34,6 +35,7 @@ hex-literal = { workspace = true }
substrate-bn = { workspace = true }
thiserror = { workspace = true }
blst = "0.3.14"
alloy-core = { workspace = true }

[dev-dependencies]
hex = { workspace = true, features = ["serde"] }
Expand All @@ -44,6 +46,7 @@ alloy-core = { workspace = true }
serde_json = { workspace = true }
rand = { workspace = true }
once_cell = { workspace = true }
rstest = "0.26.0"


[features]
Expand Down
28 changes: 28 additions & 0 deletions actors/evm/src/interpreter/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ mod bls12_381;
mod bls_util;
mod evm;
mod fvm;
mod secp256r1;

use bls12_381::{
bls12_g1add, bls12_g1msm, bls12_g2add, bls12_g2msm, bls12_map_fp_to_g1, bls12_map_fp2_to_g2,
bls12_pairing,
};
use evm::{blake2f, ec_add, ec_mul, ec_pairing, ec_recover, identity, modexp, ripemd160, sha256};
use fvm::{call_actor, call_actor_id, get_randomness, lookup_delegated_address, resolve_address};
use secp256r1::p256_verify;

type PrecompileFn<RT> = fn(&mut System<RT>, &[u8], PrecompileContext) -> PrecompileResult;
pub type PrecompileResult = Result<Vec<u8>, PrecompileError>;
Expand All @@ -38,6 +40,16 @@ impl<RT: Runtime, const N: usize> PrecompileTable<RT, N> {
}

pub fn is_reserved_precompile_address(addr: &EthAddress) -> bool {
// Special case for secp256r1 (P-256) `P256VERIFY` precompile at 0x0100 (EIP-7951 / RIP-7212 interface).
if addr.0
== [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
]
{
return true;
}

let [prefix, middle @ .., index] = addr.0;
(prefix == 0x00 || prefix == NATIVE_PRECOMPILE_ADDRESS_PREFIX)
&& middle == [0u8; 18]
Expand Down Expand Up @@ -80,6 +92,15 @@ impl<RT: Runtime> Precompiles<RT> {
]);

fn lookup_precompile(addr: &EthAddress) -> Option<PrecompileFn<RT>> {
// Special-case secp256r1 (P-256) `P256VERIFY` precompile at 0x...0100 (EIP-7951 / RIP-7212 interface).
if addr.0[0] == 0x00
&& addr.0[1..18] == [0u8; 17]
&& addr.0[18] == 0x01
&& addr.0[19] == 0x00
{
return Some(p256_verify::<RT>);
}

let [prefix, _m @ .., index] = addr.0;
if is_reserved_precompile_address(addr) {
let index = index as usize - 1;
Expand Down Expand Up @@ -217,6 +238,13 @@ mod test {
assert!(!is_reserved_precompile_address(&addr));
}

#[test]
fn is_rip_7212_precompile() {

Choose a reason for hiding this comment

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

All mentions of RIP 7212 should be removed.

EIP-7951 is the formal Ethereum Improvement Proposal that supersedes RIP-7212.
References (https://eips.ethereum.org/EIPS/eip-7951):

This specification addresses critical security issues discovered in RIP-7212 while maintaining full interface compatibility with existing Layer 2 implementations.

This EIP supersedes RIP-7212 by implementing the same functionality with the same interface, but without the vulnerability.

Choose a reason for hiding this comment

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

Not sure if this should be part of this PR: but something like addr!(0x100) expanding to the full addr hex here should be easier for maintenance long term.

let addr = EthAddress(hex_literal::hex!("0000000000000000000000000000000000000100"));
assert!(Precompiles::<MockRuntime>::is_precompile(&addr));
assert!(is_reserved_precompile_address(&addr));
}

#[test]
fn zero_addr_precompile() {
let eth_addr = EthAddress(hex_literal::hex!("fe00000000000000000000000000000000000000"));
Expand Down
Loading