Skip to content
Merged
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
46 changes: 23 additions & 23 deletions crates/op-revm/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use revm::{
handler::{EthPrecompiles, PrecompileProvider},
interpreter::{InputsImpl, InterpreterResult},
precompile::{
self, bn128, secp256r1, PrecompileError, PrecompileResult, PrecompileWithAddress,
self, bn254, secp256r1, PrecompileError, PrecompileResult, PrecompileWithAddress,
Precompiles,
},
primitives::{hardfork::SpecId, Address, OnceLock},
Expand Down Expand Up @@ -69,8 +69,8 @@ pub fn granite() -> &'static Precompiles {
static INSTANCE: OnceLock<Precompiles> = OnceLock::new();
INSTANCE.get_or_init(|| {
let mut precompiles = fjord().clone();
// Restrict bn256Pairing input size
precompiles.extend([bn128_pair::GRANITE]);
// Restrict bn254Pairing input size
precompiles.extend([bn254_pair::GRANITE]);
precompiles
})
}
Expand Down Expand Up @@ -137,27 +137,27 @@ impl Default for OpPrecompiles {
}
}

/// Bn128 pair precompile.
pub mod bn128_pair {
/// Bn254 pair precompile.
pub mod bn254_pair {
use super::*;

/// Max input size for the bn128 pair precompile.
/// Max input size for the bn254 pair precompile.
pub const GRANITE_MAX_INPUT_SIZE: usize = 112687;
/// Bn128 pair precompile.
/// Bn254 pair precompile.
pub const GRANITE: PrecompileWithAddress =
PrecompileWithAddress(bn128::pair::ADDRESS, |input, gas_limit| {
PrecompileWithAddress(bn254::pair::ADDRESS, |input, gas_limit| {
run_pair(input, gas_limit)
});

/// Run the bn128 pair precompile with Optimism input limit.
/// Run the bn254 pair precompile with Optimism input limit.
pub fn run_pair(input: &[u8], gas_limit: u64) -> PrecompileResult {
if input.len() > GRANITE_MAX_INPUT_SIZE {
return Err(PrecompileError::Bn128PairLength);
return Err(PrecompileError::Bn254PairLength);
}
bn128::run_pair(
bn254::run_pair(
input,
bn128::pair::ISTANBUL_PAIR_PER_POINT,
bn128::pair::ISTANBUL_PAIR_BASE,
bn254::pair::ISTANBUL_PAIR_PER_POINT,
bn254::pair::ISTANBUL_PAIR_BASE,
gas_limit,
)
}
Expand Down Expand Up @@ -234,7 +234,7 @@ mod tests {
use std::vec;

#[test]
fn test_bn128_pair() {
fn test_bn254_pair() {
let input = hex::decode(
"\
1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59\
Expand All @@ -254,7 +254,7 @@ mod tests {
let expected =
hex::decode("0000000000000000000000000000000000000000000000000000000000000001")
.unwrap();
let outcome = bn128_pair::run_pair(&input, 260_000).unwrap();
let outcome = bn254_pair::run_pair(&input, 260_000).unwrap();
assert_eq!(outcome.bytes, expected);

// Invalid input length
Expand All @@ -267,18 +267,18 @@ mod tests {
)
.unwrap();

let res = bn128_pair::run_pair(&input, 260_000);
assert!(matches!(res, Err(PrecompileError::Bn128PairLength)));
let res = bn254_pair::run_pair(&input, 260_000);
assert!(matches!(res, Err(PrecompileError::Bn254PairLength)));

// Valid input length shorter than 112687
let input = vec![1u8; 586 * bn128::PAIR_ELEMENT_LEN];
let res = bn128_pair::run_pair(&input, 260_000);
let input = vec![1u8; 586 * bn254::PAIR_ELEMENT_LEN];
let res = bn254_pair::run_pair(&input, 260_000);
assert!(matches!(res, Err(PrecompileError::OutOfGas)));

// Input length longer than 112687
let input = vec![1u8; 587 * bn128::PAIR_ELEMENT_LEN];
let res = bn128_pair::run_pair(&input, 260_000);
assert!(matches!(res, Err(PrecompileError::Bn128PairLength)));
let input = vec![1u8; 587 * bn254::PAIR_ELEMENT_LEN];
let res = bn254_pair::run_pair(&input, 260_000);
assert!(matches!(res, Err(PrecompileError::Bn254PairLength)));
}

#[test]
Expand All @@ -290,7 +290,7 @@ mod tests {
#[test]
fn test_cancun_precompiles_in_granite() {
// granite has p256verify (fjord)
// granite has modification of cancun's bn128 pair (doesn't count as new precompile)
// granite has modification of cancun's bn254 pair (doesn't count as new precompile)
assert_eq!(granite().difference(Precompiles::cancun()).len(), 1)
}

Expand Down
20 changes: 10 additions & 10 deletions crates/op-revm/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod common;

use common::compare_or_save_testdata;
use op_revm::{
precompiles::bn128_pair::GRANITE_MAX_INPUT_SIZE, DefaultOp, L1BlockInfo, OpBuilder,
precompiles::bn254_pair::GRANITE_MAX_INPUT_SIZE, DefaultOp, L1BlockInfo, OpBuilder,
OpHaltReason, OpSpecId, OpTransaction,
};
use revm::{
Expand All @@ -18,7 +18,7 @@ use revm::{
gas::{calculate_initial_tx_gas, InitialAndFloorGas},
Interpreter, InterpreterTypes,
},
precompile::{bls12_381_const, bls12_381_utils, bn128, secp256r1, u64_to_address},
precompile::{bls12_381_const, bls12_381_utils, bn254, secp256r1, u64_to_address},
primitives::{eip7825, Address, Bytes, Log, TxKind, U256},
state::Bytecode,
Context, ExecuteEvm, InspectEvm, Inspector, Journal,
Expand Down Expand Up @@ -161,7 +161,7 @@ fn test_halted_tx_call_p256verify() {
compare_or_save_testdata("test_halted_tx_call_p256verify.json", &output);
}

fn bn128_pair_test_tx(
fn bn254_pair_test_tx(
spec: OpSpecId,
) -> Context<BlockEnv, OpTransaction<TxEnv>, CfgEnv<OpSpecId>, EmptyDB, Journal<EmptyDB>, L1BlockInfo>
{
Expand All @@ -174,7 +174,7 @@ fn bn128_pair_test_tx(
OpTransaction::builder()
.base(
TxEnv::builder()
.kind(TxKind::Call(bn128::pair::ADDRESS))
.kind(TxKind::Call(bn254::pair::ADDRESS))
.data(input)
.gas_limit(initial_gas),
)
Expand All @@ -184,8 +184,8 @@ fn bn128_pair_test_tx(
}

#[test]
fn test_halted_tx_call_bn128_pair_fjord() {
let ctx = bn128_pair_test_tx(OpSpecId::FJORD);
fn test_halted_tx_call_bn254_pair_fjord() {
let ctx = bn254_pair_test_tx(OpSpecId::FJORD);

let mut evm = ctx.build_op();
let output = evm.replay().unwrap();
Expand All @@ -199,12 +199,12 @@ fn test_halted_tx_call_bn128_pair_fjord() {
}
));

compare_or_save_testdata("test_halted_tx_call_bn128_pair_fjord.json", &output);
compare_or_save_testdata("test_halted_tx_call_bn254_pair_fjord.json", &output);
}

#[test]
fn test_halted_tx_call_bn128_pair_granite() {
let ctx = bn128_pair_test_tx(OpSpecId::GRANITE);
fn test_halted_tx_call_bn254_pair_granite() {
let ctx = bn254_pair_test_tx(OpSpecId::GRANITE);

let mut evm = ctx.build_op();
let output = evm.replay().unwrap();
Expand All @@ -218,7 +218,7 @@ fn test_halted_tx_call_bn128_pair_granite() {
}
));

compare_or_save_testdata("test_halted_tx_call_bn128_pair_granite.json", &output);
compare_or_save_testdata("test_halted_tx_call_bn254_pair_granite.json", &output);
}

#[test]
Expand Down
20 changes: 10 additions & 10 deletions crates/precompile/bench/eip1962.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! Benchmarks for the BN128 precompiles
//! Benchmarks for the BN254 precompiles
use criterion::{measurement::Measurement, BenchmarkGroup};
use primitives::hex;
use primitives::Bytes;
use revm_precompile::bn128::{
use revm_precompile::bn254::{
add::ISTANBUL_ADD_GAS_COST,
mul::ISTANBUL_MUL_GAS_COST,
pair::{ISTANBUL_PAIR_BASE, ISTANBUL_PAIR_PER_POINT},
run_add, run_mul, run_pair,
};

/// Add benches for the BN128 add precompile
pub fn add_bn128_add_benches<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
/// Add benches for the BN254 add precompile
pub fn add_bn254_add_benches<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
let ecadd_input = hex::decode(
"\
18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9\
Expand All @@ -21,13 +21,13 @@ pub fn add_bn128_add_benches<M: Measurement>(group: &mut BenchmarkGroup<'_, M>)
.unwrap();
let input = Bytes::from(ecadd_input);

group.bench_function("bn128 add precompile", |b| {
group.bench_function("bn254 add precompile", |b| {
b.iter(|| run_add(&input, ISTANBUL_ADD_GAS_COST, 150).unwrap())
});
}

/// Add benches for the BN128 mul precompile
pub fn add_bn128_mul_benches<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
/// Add benches for the BN254 mul precompile
pub fn add_bn254_mul_benches<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
let ecmul_input = hex::decode(
"\
18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9\
Expand All @@ -37,13 +37,13 @@ pub fn add_bn128_mul_benches<M: Measurement>(group: &mut BenchmarkGroup<'_, M>)
.unwrap();
let input = Bytes::from(ecmul_input);

group.bench_function("bn128 mul precompile", |b| {
group.bench_function("bn254 mul precompile", |b| {
b.iter(|| run_mul(&input, ISTANBUL_MUL_GAS_COST, 6000).unwrap())
});
}

/// Add benches for the BN128 pair precompile
pub fn add_bn128_pair_benches<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
/// Add benches for the BN254 pair precompile
pub fn add_bn254_pair_benches<M: Measurement>(group: &mut BenchmarkGroup<'_, M>) {
let ecpair_input = hex::decode(
"\
1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59\
Expand Down
8 changes: 4 additions & 4 deletions crates/precompile/bench/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ pub fn benchmark_crypto_precompiles(c: &mut Criterion) {
eip2537::add_map_fp_to_g1_benches(&mut group);
eip2537::add_map_fp2_to_g2_benches(&mut group);

// Run BN128 benchmarks
eip1962::add_bn128_add_benches(&mut group);
eip1962::add_bn128_mul_benches(&mut group);
eip1962::add_bn128_pair_benches(&mut group);
// Run BN254 benchmarks
eip1962::add_bn254_add_benches(&mut group);
eip1962::add_bn254_mul_benches(&mut group);
eip1962::add_bn254_pair_benches(&mut group);

// Run secp256k1 benchmarks
ecrecover::add_benches(&mut group);
Expand Down
Loading
Loading