Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
34e7f7c
add read_scalar, point_add and point_mul into the wrapper
kevaundray Mar 20, 2025
d3aba76
modify bn128.rs to use new api methods
kevaundray Mar 20, 2025
ec1a3b4
preserve previous semantics
kevaundray Mar 20, 2025
1dc9404
initial commit to add matter-labs wrapper
kevaundray Mar 20, 2025
99edba1
feature gate matter-labs impl -- make substrate impl still default
kevaundray Mar 20, 2025
45e13e3
update revm and precompile cargo.toml file
kevaundray Mar 20, 2025
398910c
use cfg_if
kevaundray Mar 20, 2025
526103b
make bn an optional dependency
kevaundray Mar 20, 2025
8dfda37
cfg else -> else_if so that there is no silent fallback
kevaundray Mar 20, 2025
5b2fe79
follow same cfg_if pattern as other precompiles
kevaundray Mar 20, 2025
98b6488
fix optimism
kevaundray Mar 20, 2025
5becac4
add back `self` import
kevaundray Mar 20, 2025
f8be131
Push empty commit to trigger CI
kevaundray Mar 20, 2025
f4c8595
cargo fmt
kevaundray Mar 20, 2025
df64b70
clippy fix
kevaundray Mar 20, 2025
570d449
make `bn` the default with revm and revme
kevaundray Mar 20, 2025
e38b6e1
fix typo
kevaundray Mar 20, 2025
6b2a765
Merge branch 'main' into kw/add-matter-labs
kevaundray Mar 21, 2025
d672f23
Update crates/revm/Cargo.toml
kevaundray Mar 21, 2025
cfda7c4
Update crates/revm/Cargo.toml
kevaundray Mar 21, 2025
88ed53c
Update crates/precompile/src/lib.rs
kevaundray Mar 21, 2025
50f45cf
Update crates/optimism/Cargo.toml
kevaundray Mar 21, 2025
0fb0fdd
revert Cargo.toml formatting
kevaundray Mar 21, 2025
6d5348c
multi:
kevaundray Mar 21, 2025
b889f1c
revert crates/optimism/src/precompiles.rs
kevaundray Mar 21, 2025
7713162
revert crates/optimism/src/evm.rs
kevaundray Mar 21, 2025
6004b6c
revert unnecessary changes in crates/precompile/src/lib.rs
kevaundray Mar 21, 2025
a792687
revert Cargo.toml changes
kevaundray Mar 21, 2025
b840176
revert automatic Cargo.toml formatting
kevaundray Mar 21, 2025
a57920e
revert formatting on secp256k1 in Cargo.toml
kevaundray Mar 21, 2025
498502e
revert c-kzg formatting in Cargo.toml
kevaundray Mar 21, 2025
184151c
revert dev key in Cargo.toml
kevaundray Mar 21, 2025
f80171d
revert c-kzg feature in Cargo.toml
kevaundray Mar 21, 2025
b3e5bd1
Merge branch 'main' into kw/add-matter-labs
kevaundray Mar 21, 2025
f747766
Update crates/precompile/Cargo.toml
kevaundray Mar 21, 2025
1b20177
Apply suggestions from code review
kevaundray Mar 21, 2025
d56d192
Merge branch 'main' into kw/add-matter-labs
kevaundray Mar 25, 2025
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
65 changes: 65 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ cfg-if = { version = "1.0", default-features = false }
clap = "4"
criterion = { package = "codspeed-criterion-compat", version = "2.7" }
derive-where = { version = "1.2.7", default-features = false }
eth_pairings = { git = "https://github.com/matter-labs/eip1962", rev = "17ba98bdbdd7bdf239c09cd88ca46a486124f5e7", default-features = false }
enumn = "0.1"
k256 = { version = "0.13.3", default-features = false }
kzg-rs = { version = "0.2.4", default-features = false }
Expand Down
27 changes: 19 additions & 8 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ once_cell = { workspace = true, features = ["alloc"] }
# ecRecover
k256 = { workspace = true, features = ["ecdsa"] }
secp256k1 = { workspace = true, features = [
"alloc",
"recovery",
"rand",
"global-context",
"alloc",
"recovery",
"rand",
"global-context",
], optional = true }
libsecp256k1 = { workspace = true, features = [
"static-context",
"static-context",
], optional = true }

# SHA2-256 and RIPEMD-160
Expand All @@ -49,10 +49,11 @@ aurora-engine-modexp.workspace = true

# ecAdd, ecMul, ecPairing
bn.workspace = true
eth_pairings = { workspace = true, features = ["eip_196"], optional = true }

# KZG point evaluation precompile
c-kzg = { workspace = true, optional = true, features = [
"ethereum_kzg_settings",
"ethereum_kzg_settings",
] }

# Optionally use `kzg-rs` for a pure Rust implementation of KZG point evaluation.
Expand All @@ -77,7 +78,14 @@ serde_json.workspace = true
serde_derive.workspace = true

[features]
default = ["std", "c-kzg", "secp256k1", "portable", "blst"]
default = [
"std",
"c-kzg",
"secp256k1",
"portable",
"blst",
"matter-labs-eip1962",
]
std = [
"primitives/std",
"k256/std",
Expand All @@ -90,7 +98,7 @@ std = [
"aurora-engine-modexp/std",
"p256?/std",
"serde/std",
"serde_json/std"
"serde_json/std",
Comment thread
kevaundray marked this conversation as resolved.
Outdated
]
hashbrown = ["primitives/hashbrown"]
asm-keccak = ["primitives/asm-keccak"]
Expand Down Expand Up @@ -118,6 +126,9 @@ libsecp256k1 = ["dep:libsecp256k1"]
# Enables the BLS12-381 precompiles.
blst = ["dep:blst"]

# Use matter-labs implementation for BN128 operations (EIP1962)
matter-labs-eip1962 = ["dep:eth_pairings"]
Comment thread
kevaundray marked this conversation as resolved.

[[bench]]
name = "bench"
path = "benches/bench.rs"
Expand Down
26 changes: 19 additions & 7 deletions crates/precompile/src/bn128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ use crate::{
};
use std::vec::Vec;

use substrate::{encode_g1_point, pairing_check, read_g1_point, read_g2_point};
mod substrate;
cfg_if::cfg_if! {
if #[cfg(feature = "matter-labs-eip1962")] {
mod matter_labs;
use matter_labs::{
encode_g1_point, g1_point_add, g1_point_mul, pairing_check, read_g1_point, read_g2_point,
read_scalar,
};
} else {
mod substrate;
use substrate::{
encode_g1_point, g1_point_add, g1_point_mul, pairing_check, read_g1_point, read_g2_point,
read_scalar,
};

}
}

pub mod add {
use super::*;
Expand Down Expand Up @@ -121,7 +135,7 @@ pub fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult

let p1 = read_g1_point(&input[..G1_LEN])?;
let p2 = read_g1_point(&input[G1_LEN..])?;
let result = p1 + p2;
let result = g1_point_add(p1, p2);

let output = encode_g1_point(result);

Expand All @@ -137,10 +151,8 @@ pub fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult

let p = read_g1_point(&input[..G1_LEN])?;

// `Fr::from_slice` can only fail when the length is not 32.
let fr = bn::Fr::from_slice(&input[G1_LEN..G1_LEN + SCALAR_LEN]).unwrap();

let result = p * fr;
let scalar = read_scalar(&input[G1_LEN..G1_LEN + SCALAR_LEN]);
let result = g1_point_mul(p, scalar);

let output = encode_g1_point(result);

Expand Down
Loading