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

(WIP)feat: eip 7212 #1439

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
131 changes: 94 additions & 37 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ strum_macros = "0.25"
subtle = "2.4"
tokio = { version = "1.13", features = ["macros", "rt-multi-thread"] }
url = "2.2"
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v40", default-features = false, features = ["std"] } # v40
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v40", default-features = false, features = ["std"] } # v40
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v49", default-features = false, features = ["std"] }
revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v49", default-features = false, features = ["std"] }
c-kzg = "1.0.2"

[patch.crates-io]
alloy-eip2930 = { git = "https://github.com/scroll-tech/alloy-eips", branch = "v0.3.2" }
alloy-eip7702 = { git = "https://github.com/scroll-tech/alloy-eips", branch = "v0.3.2" }
alloy-primitives = { git = "https://github.com/scroll-tech/alloy-core", branch = "v0.8.10" }
ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
ethers-providers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
ethers = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = "v2.0.7" }
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ impl<'a> CircuitInputStateRef<'a> {
// on top of the stack (step.stack.last())
// Therefore we postpone the oog handling to the implementor of callop.
if is_precompiled(&code_address) {
let precompile_call: PrecompileCalls = code_address[19].into();
let precompile_call: PrecompileCalls = code_address.into();
match precompile_call {
PrecompileCalls::Ripemd160 | PrecompileCalls::Blake2F => {
// Log the precompile address and gas left. Since this failure is mainly
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/begin_end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ pub fn gen_begin_tx_steps(state: &mut CircuitInputStateRef) -> Result<Vec<ExecSt
state.call_context_write(&mut exec_step, call.call_id, field, value)?;
}

let precompile_call: PrecompileCalls = call.address.0[19].into();
let precompile_call: PrecompileCalls = call.address.into();
let (result, precompile_call_gas_cost, has_oog_err) = execute_precompiled(
&precompile_call.into(),
&state.tx.input,
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<const N_ARGS: usize> Opcode for CallOpcode<N_ARGS> {
// 1. Call to precompiled.
(false, true, _) => {
let code_address = code_address.unwrap();
let precompile_call: PrecompileCalls = code_address.0[19].into();
let precompile_call: PrecompileCalls = code_address.into();

// get the result of the precompile call.
// For failed call, it will cost all gas provided.
Expand Down
1 change: 0 additions & 1 deletion bus-mapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@
#![allow(clippy::result_large_err)] // it's large, but what can we do?
#![allow(clippy::collapsible_else_if)]
#![allow(incomplete_features)]
#![feature(lazy_cell)]
#![feature(adt_const_params)]

extern crate alloc;
Expand Down
16 changes: 13 additions & 3 deletions bus-mapping/src/precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn execute_precompiled(
gas: u64,
) -> (Vec<u8>, u64, bool) {
#[cfg(feature = "scroll")]
let precompiles = Precompiles::bernoulli();
let precompiles = Precompiles::euclid();
#[cfg(not(feature = "scroll"))]
let precompiles = Precompiles::berlin();

Expand Down Expand Up @@ -62,6 +62,8 @@ pub enum PrecompileCalls {
Bn128Pairing = 0x08,
/// Compression function
Blake2F = 0x09,
/// secp256r1 verify
P256Verify = 0x100,
}

impl Default for PrecompileCalls {
Expand Down Expand Up @@ -90,8 +92,14 @@ impl From<PrecompileCalls> for usize {
}
}

impl From<u8> for PrecompileCalls {
fn from(value: u8) -> Self {
impl From<Address> for PrecompileCalls {
fn from(value: Address) -> Self {
u64::from_be_bytes(value.0[12..].try_into().unwrap()).into()
}
}

impl From<u64> for PrecompileCalls {
fn from(value: u64) -> Self {
match value {
0x01 => Self::Ecrecover,
0x02 => Self::Sha256,
Expand All @@ -102,6 +110,7 @@ impl From<u8> for PrecompileCalls {
0x07 => Self::Bn128Mul,
0x08 => Self::Bn128Pairing,
0x09 => Self::Blake2F,
0x100 => Self::P256Verify,
_ => unreachable!("precompile contracts only from 0x01 to 0x09"),
}
}
Expand All @@ -120,6 +129,7 @@ impl PrecompileCalls {
Self::Bn128Mul => GasCost::PRECOMPILE_BN256MUL,
Self::Bn128Pairing => GasCost::PRECOMPILE_BN256PAIRING,
Self::Blake2F => GasCost::PRECOMPILE_BLAKE2F,
Self::P256Verify => GasCost::PRECOMPILE_P256VERIFY,
}
}

Expand Down
2 changes: 2 additions & 0 deletions eth-types/src/evm_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ impl GasCost {
pub const PRECOMPILE_MODEXP_MIN: Self = Self(200);
/// Base gas cost for precompile call: BLAKE2F
pub const PRECOMPILE_BLAKE2F: Self = Self(0);
/// Base gas cost for precompile call: P256VERIFY
pub const PRECOMPILE_P256VERIFY: Self = Self(3450);
/// Gas cost per address in tx access list (EIP 2930)
pub const ACCESS_LIST_PER_ADDRESS: Self = Self(2400);
/// Gas cost per storage key in tx access list (EIP 2930)
Expand Down
Loading
Loading