Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

(WIP)feat: eip 7212 #1439

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
110 changes: 73 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
@@ -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" }
10 changes: 7 additions & 3 deletions aggregator/src/aggregation/barycentric.rs
Original file line number Diff line number Diff line change
@@ -354,7 +354,7 @@ pub fn interpolate(z: Scalar, coefficients: &[Scalar; BLOB_WIDTH]) -> Scalar {
mod tests {
use super::*;
use crate::{
blob::{BatchData, KZG_TRUSTED_SETUP},
blob::BatchData,
eip4844::{get_blob_bytes, get_coefficients},
MAX_AGG_SNARKS,
};
@@ -423,8 +423,12 @@ mod tests {
.collect::<Vec<_>>(),
)
.unwrap();
let (_proof, y) =
KzgProof::compute_kzg_proof(&blob, &to_be_bytes(z).into(), &KZG_TRUSTED_SETUP).unwrap();
let (_proof, y) = KzgProof::compute_kzg_proof(
&blob,
&to_be_bytes(z).into(),
c_kzg::ethereum_kzg_settings(),
)
.unwrap();
from_canonical_be_bytes(*y)
}

16 changes: 6 additions & 10 deletions aggregator/src/blob.rs
Original file line number Diff line number Diff line change
@@ -43,16 +43,12 @@ pub const N_BLOB_BYTES: usize = BLOB_WIDTH * N_DATA_BYTES_PER_COEFFICIENT;
/// Allow up to 5x compression via zstd encoding of the batch data.
pub const N_BATCH_BYTES: usize = N_BLOB_BYTES * 5;

/// KZG trusted setup
pub static KZG_TRUSTED_SETUP: Lazy<Arc<c_kzg::KzgSettings>> = Lazy::new(|| {
Arc::new(
c_kzg::KzgSettings::load_trusted_setup(
&revm_primitives::kzg::G1_POINTS.0,
&revm_primitives::kzg::G2_POINTS.0,
)
.expect("failed to load trusted setup"),
)
});
// /// KZG trusted setup
// pub static KZG_TRUSTED_SETUP: Lazy<Arc<c_kzg::KzgSettings>> = Lazy::new(|| {
// Arc::new(
// c_kzg::ethereum_kzg_settings()
// )
// });

/// Helper struct to generate witness for the Batch Data Config.
#[derive(Clone, Debug)]
4 changes: 2 additions & 2 deletions aggregator/src/eip4844.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ use eth_types::{ToBigEndian, H256, U256};
use ethers_core::k256::sha2::{Digest, Sha256};
use revm_primitives::VERSIONED_HASH_VERSION_KZG;

use crate::blob::{BLOB_WIDTH, KZG_TRUSTED_SETUP, N_BLOB_BYTES, N_BYTES_U256};
use crate::blob::{BLOB_WIDTH, N_BLOB_BYTES, N_BYTES_U256};

/// Get the BLOB_WIDTH number of scalar field elements, as 32-bytes unsigned integers.
pub(crate) fn get_coefficients(blob_bytes: &[u8]) -> [U256; BLOB_WIDTH] {
@@ -30,7 +30,7 @@ pub(crate) fn get_versioned_hash(coefficients: &[U256; BLOB_WIDTH]) -> H256 {
.collect::<Vec<_>>(),
)
.expect("blob-coefficients to 4844 blob should succeed");
let c = c_kzg::KzgCommitment::blob_to_kzg_commitment(&blob, &KZG_TRUSTED_SETUP)
let c = c_kzg::KzgCommitment::blob_to_kzg_commitment(&blob, c_kzg::ethereum_kzg_settings())
.expect("blob to kzg commitment should succeed");
kzg_to_versioned_hash(&c)
}
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
@@ -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
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
@@ -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,
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/callop.rs
Original file line number Diff line number Diff line change
@@ -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.
1 change: 0 additions & 1 deletion bus-mapping/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Loading