diff --git a/crates/op-revm/src/precompiles.rs b/crates/op-revm/src/precompiles.rs index d7e2c8e4e3..e4e14b9082 100644 --- a/crates/op-revm/src/precompiles.rs +++ b/crates/op-revm/src/precompiles.rs @@ -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}, @@ -69,8 +69,8 @@ pub fn granite() -> &'static Precompiles { static INSTANCE: OnceLock = 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 }) } @@ -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, ) } @@ -234,7 +234,7 @@ mod tests { use std::vec; #[test] - fn test_bn128_pair() { + fn test_bn254_pair() { let input = hex::decode( "\ 1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59\ @@ -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 @@ -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] @@ -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) } diff --git a/crates/op-revm/tests/integration.rs b/crates/op-revm/tests/integration.rs index 2f7f2fcf96..a211d238d3 100644 --- a/crates/op-revm/tests/integration.rs +++ b/crates/op-revm/tests/integration.rs @@ -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::{ @@ -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, @@ -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, CfgEnv, EmptyDB, Journal, L1BlockInfo> { @@ -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), ) @@ -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(); @@ -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(); @@ -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] diff --git a/crates/precompile/bench/eip1962.rs b/crates/precompile/bench/eip1962.rs index 92b547da95..afcc0b77f4 100644 --- a/crates/precompile/bench/eip1962.rs +++ b/crates/precompile/bench/eip1962.rs @@ -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(group: &mut BenchmarkGroup<'_, M>) { +/// Add benches for the BN254 add precompile +pub fn add_bn254_add_benches(group: &mut BenchmarkGroup<'_, M>) { let ecadd_input = hex::decode( "\ 18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9\ @@ -21,13 +21,13 @@ pub fn add_bn128_add_benches(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(group: &mut BenchmarkGroup<'_, M>) { +/// Add benches for the BN254 mul precompile +pub fn add_bn254_mul_benches(group: &mut BenchmarkGroup<'_, M>) { let ecmul_input = hex::decode( "\ 18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9\ @@ -37,13 +37,13 @@ pub fn add_bn128_mul_benches(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(group: &mut BenchmarkGroup<'_, M>) { +/// Add benches for the BN254 pair precompile +pub fn add_bn254_pair_benches(group: &mut BenchmarkGroup<'_, M>) { let ecpair_input = hex::decode( "\ 1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59\ diff --git a/crates/precompile/bench/main.rs b/crates/precompile/bench/main.rs index 153dc40ad1..dcb1bc6675 100644 --- a/crates/precompile/bench/main.rs +++ b/crates/precompile/bench/main.rs @@ -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); diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn254.rs similarity index 91% rename from crates/precompile/src/bn128.rs rename to crates/precompile/src/bn254.rs index 089f6b05d3..035b25caf3 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn254.rs @@ -1,4 +1,4 @@ -//! BN128 precompiles added in [`EIP-1962`](https://eips.ethereum.org/EIPS/eip-1962) +//! BN254 precompiles added in [`EIP-1962`](https://eips.ethereum.org/EIPS/eip-1962) use crate::{ crypto, utilities::{bool_to_bytes32, right_pad}, @@ -16,72 +16,72 @@ cfg_if::cfg_if! { } } -/// Bn128 add precompile +/// Bn254 add precompile pub mod add { use super::*; - /// Bn128 add precompile address + /// Bn254 add precompile address pub const ADDRESS: Address = crate::u64_to_address(6); - /// Bn128 add precompile with ISTANBUL gas rules + /// Bn254 add precompile with ISTANBUL gas rules pub const ISTANBUL_ADD_GAS_COST: u64 = 150; - /// Bn128 add precompile with ISTANBUL gas rules + /// Bn254 add precompile with ISTANBUL gas rules pub const ISTANBUL: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, |input, gas_limit| { run_add(input, ISTANBUL_ADD_GAS_COST, gas_limit) }); - /// Bn128 add precompile with BYZANTIUM gas rules + /// Bn254 add precompile with BYZANTIUM gas rules pub const BYZANTIUM_ADD_GAS_COST: u64 = 500; - /// Bn128 add precompile with BYZANTIUM gas rules + /// Bn254 add precompile with BYZANTIUM gas rules pub const BYZANTIUM: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, |input, gas_limit| { run_add(input, BYZANTIUM_ADD_GAS_COST, gas_limit) }); } -/// Bn128 mul precompile +/// Bn254 mul precompile pub mod mul { use super::*; - /// Bn128 mul precompile address + /// Bn254 mul precompile address pub const ADDRESS: Address = crate::u64_to_address(7); - /// Bn128 mul precompile with ISTANBUL gas rules + /// Bn254 mul precompile with ISTANBUL gas rules pub const ISTANBUL_MUL_GAS_COST: u64 = 6_000; - /// Bn128 mul precompile with ISTANBUL gas rules + /// Bn254 mul precompile with ISTANBUL gas rules pub const ISTANBUL: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, |input, gas_limit| { run_mul(input, ISTANBUL_MUL_GAS_COST, gas_limit) }); - /// Bn128 mul precompile with BYZANTIUM gas rules + /// Bn254 mul precompile with BYZANTIUM gas rules pub const BYZANTIUM_MUL_GAS_COST: u64 = 40_000; - /// Bn128 mul precompile with BYZANTIUM gas rules + /// Bn254 mul precompile with BYZANTIUM gas rules pub const BYZANTIUM: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, |input, gas_limit| { run_mul(input, BYZANTIUM_MUL_GAS_COST, gas_limit) }); } -/// Bn128 pair precompile +/// Bn254 pair precompile pub mod pair { use super::*; - /// Bn128 pair precompile address + /// Bn254 pair precompile address pub const ADDRESS: Address = crate::u64_to_address(8); - /// Bn128 pair precompile with ISTANBUL gas rules + /// Bn254 pair precompile with ISTANBUL gas rules pub const ISTANBUL_PAIR_PER_POINT: u64 = 34_000; - /// Bn128 pair precompile with ISTANBUL gas rules + /// Bn254 pair precompile with ISTANBUL gas rules pub const ISTANBUL_PAIR_BASE: u64 = 45_000; - /// Bn128 pair precompile with ISTANBUL gas rules + /// Bn254 pair precompile with ISTANBUL gas rules pub const ISTANBUL: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, |input, gas_limit| { run_pair( @@ -92,13 +92,13 @@ pub mod pair { ) }); - /// Bn128 pair precompile with BYZANTIUM gas rules + /// Bn254 pair precompile with BYZANTIUM gas rules pub const BYZANTIUM_PAIR_PER_POINT: u64 = 80_000; - /// Bn128 pair precompile with BYZANTIUM gas rules + /// Bn254 pair precompile with BYZANTIUM gas rules pub const BYZANTIUM_PAIR_BASE: u64 = 100_000; - /// Bn128 pair precompile with BYZANTIUM gas rules + /// Bn254 pair precompile with BYZANTIUM gas rules pub const BYZANTIUM: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, |input, gas_limit| { run_pair( @@ -149,7 +149,7 @@ pub const MUL_INPUT_LEN: usize = G1_LEN + SCALAR_LEN; /// (128 bytes). pub const PAIR_ELEMENT_LEN: usize = G1_LEN + G2_LEN; -/// Run the Bn128 add precompile +/// Run the Bn254 add precompile pub fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { if gas_cost > gas_limit { return Err(PrecompileError::OutOfGas); @@ -159,12 +159,12 @@ pub fn run_add(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult let p1_bytes = &input[..G1_LEN]; let p2_bytes = &input[G1_LEN..]; - let output = crypto().bn128_g1_add(p1_bytes, p2_bytes)?; + let output = crypto().bn254_g1_add(p1_bytes, p2_bytes)?; Ok(PrecompileOutput::new(gas_cost, output.into())) } -/// Run the Bn128 mul precompile +/// Run the Bn254 mul precompile pub fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult { if gas_cost > gas_limit { return Err(PrecompileError::OutOfGas); @@ -174,12 +174,12 @@ pub fn run_mul(input: &[u8], gas_cost: u64, gas_limit: u64) -> PrecompileResult let point_bytes = &input[..G1_LEN]; let scalar_bytes = &input[G1_LEN..G1_LEN + SCALAR_LEN]; - let output = crypto().bn128_g1_mul(point_bytes, scalar_bytes)?; + let output = crypto().bn254_g1_mul(point_bytes, scalar_bytes)?; Ok(PrecompileOutput::new(gas_cost, output.into())) } -/// Run the Bn128 pair precompile +/// Run the Bn254 pair precompile pub fn run_pair( input: &[u8], pair_per_point_cost: u64, @@ -192,7 +192,7 @@ pub fn run_pair( } if !input.len().is_multiple_of(PAIR_ELEMENT_LEN) { - return Err(PrecompileError::Bn128PairLength); + return Err(PrecompileError::Bn254PairLength); } let elements = input.len() / PAIR_ELEMENT_LEN; @@ -213,7 +213,7 @@ pub fn run_pair( points.push((encoded_g1_element, encoded_g2_element)); } - let pairing_result = crypto().bn128_pairing_check(&points)?; + let pairing_result = crypto().bn254_pairing_check(&points)?; Ok(PrecompileOutput::new( gas_used, bool_to_bytes32(pairing_result), @@ -223,7 +223,7 @@ pub fn run_pair( #[cfg(test)] mod tests { use crate::{ - bn128::{ + bn254::{ add::BYZANTIUM_ADD_GAS_COST, mul::BYZANTIUM_MUL_GAS_COST, pair::{BYZANTIUM_PAIR_BASE, BYZANTIUM_PAIR_PER_POINT}, @@ -235,7 +235,7 @@ mod tests { use super::*; #[test] - fn test_alt_bn128_add() { + fn test_bn254_add() { let input = hex::decode( "\ 18b18acfb4c2c30276db5411368e7185b311dd124691610c5d3b74034e093dc9\ @@ -312,12 +312,12 @@ mod tests { let res = run_add(&input, BYZANTIUM_ADD_GAS_COST, 500); assert!(matches!( res, - Err(PrecompileError::Bn128AffineGFailedToCreate) + Err(PrecompileError::Bn254AffineGFailedToCreate) )); } #[test] - fn test_alt_bn128_mul() { + fn test_bn254_mul() { let input = hex::decode( "\ 2bd3e6d0f3b142924f5ca7b49ce5b9d54c4703d7ae5648e61d02268b1a0a9fb7\ @@ -389,12 +389,12 @@ mod tests { let res = run_mul(&input, BYZANTIUM_MUL_GAS_COST, 40_000); assert!(matches!( res, - Err(PrecompileError::Bn128AffineGFailedToCreate) + Err(PrecompileError::Bn254AffineGFailedToCreate) )); } #[test] - fn test_alt_bn128_pair() { + fn test_bn254_pair() { let input = hex::decode( "\ 1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f59\ @@ -485,7 +485,7 @@ mod tests { ); assert!(matches!( res, - Err(PrecompileError::Bn128AffineGFailedToCreate) + Err(PrecompileError::Bn254AffineGFailedToCreate) )); // Invalid input length @@ -504,7 +504,7 @@ mod tests { BYZANTIUM_PAIR_BASE, 260_000, ); - assert!(matches!(res, Err(PrecompileError::Bn128PairLength))); + assert!(matches!(res, Err(PrecompileError::Bn254PairLength))); // Test with point at infinity - should return true (identity element) // G1 point at infinity (0,0) followed by a valid G2 point diff --git a/crates/precompile/src/bn128/arkworks.rs b/crates/precompile/src/bn254/arkworks.rs similarity index 96% rename from crates/precompile/src/bn128/arkworks.rs rename to crates/precompile/src/bn254/arkworks.rs index 8ab430f484..1572ad3786 100644 --- a/crates/precompile/src/bn128/arkworks.rs +++ b/crates/precompile/src/bn254/arkworks.rs @@ -27,7 +27,7 @@ fn read_fq(input_be: &[u8]) -> Result { input_le.reverse(); Fq::deserialize_uncompressed(&input_le[..]) - .map_err(|_| PrecompileError::Bn128FieldPointNotAMember) + .map_err(|_| PrecompileError::Bn254FieldPointNotAMember) } /// Reads a Fq2 (quadratic extension field element) from the input slice. /// @@ -64,7 +64,7 @@ fn new_g1_point(px: Fq, py: Fq) -> Result { // We cannot use `G1Affine::new` because that triggers an assert if the point is not on the curve. let point = G1Affine::new_unchecked(px, py); if !point.is_on_curve() || !point.is_in_correct_subgroup_assuming_on_curve() { - return Err(PrecompileError::Bn128AffineGFailedToCreate); + return Err(PrecompileError::Bn254AffineGFailedToCreate); } Ok(point) } @@ -72,7 +72,7 @@ fn new_g1_point(px: Fq, py: Fq) -> Result { /// Creates a new `G2` point from the given Fq2 coordinates. /// -/// G2 points in BN128 are defined over a quadratic extension field Fq2. +/// G2 points in BN254 are defined over a quadratic extension field Fq2. /// This function takes two Fq2 elements representing the x and y coordinates /// and creates a G2 point. /// @@ -89,7 +89,7 @@ fn new_g2_point(x: Fq2, y: Fq2) -> Result { // We cannot use `G1Affine::new` because that triggers an assert if the point is not on the curve. let point = G2Affine::new_unchecked(x, y); if !point.is_on_curve() || !point.is_in_correct_subgroup_assuming_on_curve() { - return Err(PrecompileError::Bn128AffineGFailedToCreate); + return Err(PrecompileError::Bn254AffineGFailedToCreate); } point }; diff --git a/crates/precompile/src/bn128/substrate.rs b/crates/precompile/src/bn254/substrate.rs similarity index 96% rename from crates/precompile/src/bn128/substrate.rs rename to crates/precompile/src/bn254/substrate.rs index c0656d54f8..d4e18cec4b 100644 --- a/crates/precompile/src/bn128/substrate.rs +++ b/crates/precompile/src/bn254/substrate.rs @@ -14,7 +14,7 @@ use std::vec::Vec; /// Panics if the input is not at least 32 bytes long. #[inline] fn read_fq(input: &[u8]) -> Result { - Fq::from_slice(&input[..FQ_LEN]).map_err(|_| PrecompileError::Bn128FieldPointNotAMember) + Fq::from_slice(&input[..FQ_LEN]).map_err(|_| PrecompileError::Bn254FieldPointNotAMember) } /// Reads a Fq2 (quadratic extension field element) from the input slice. /// @@ -49,13 +49,13 @@ fn new_g1_point(px: Fq, py: Fq) -> Result { } else { AffineG1::new(px, py) .map(Into::into) - .map_err(|_| PrecompileError::Bn128AffineGFailedToCreate) + .map_err(|_| PrecompileError::Bn254AffineGFailedToCreate) } } /// Creates a new `G2` point from the given Fq2 coordinates. /// -/// G2 points in BN128 are defined over a quadratic extension field Fq2. +/// G2 points in BN254 are defined over a quadratic extension field Fq2. /// This function takes two Fq2 elements representing the x and y coordinates /// and creates a G2 point. /// @@ -69,7 +69,7 @@ fn new_g2_point(x: Fq2, y: Fq2) -> Result { let point = if x.is_zero() && y.is_zero() { G2::zero() } else { - G2::from(AffineG2::new(x, y).map_err(|_| PrecompileError::Bn128AffineGFailedToCreate)?) + G2::from(AffineG2::new(x, y).map_err(|_| PrecompileError::Bn254AffineGFailedToCreate)?) }; Ok(point) diff --git a/crates/precompile/src/interface.rs b/crates/precompile/src/interface.rs index a5279a5e91..f9a5b77163 100644 --- a/crates/precompile/src/interface.rs +++ b/crates/precompile/src/interface.rs @@ -88,22 +88,22 @@ pub trait Crypto: Send + Sync + Debug { output } - /// BN128 elliptic curve addition. + /// BN254 elliptic curve addition. #[inline] - fn bn128_g1_add(&self, p1: &[u8], p2: &[u8]) -> Result<[u8; 64], PrecompileError> { - crate::bn128::crypto_backend::g1_point_add(p1, p2) + fn bn254_g1_add(&self, p1: &[u8], p2: &[u8]) -> Result<[u8; 64], PrecompileError> { + crate::bn254::crypto_backend::g1_point_add(p1, p2) } - /// BN128 elliptic curve scalar multiplication. + /// BN254 elliptic curve scalar multiplication. #[inline] - fn bn128_g1_mul(&self, point: &[u8], scalar: &[u8]) -> Result<[u8; 64], PrecompileError> { - crate::bn128::crypto_backend::g1_point_mul(point, scalar) + fn bn254_g1_mul(&self, point: &[u8], scalar: &[u8]) -> Result<[u8; 64], PrecompileError> { + crate::bn254::crypto_backend::g1_point_mul(point, scalar) } - /// BN128 pairing check. + /// BN254 pairing check. #[inline] - fn bn128_pairing_check(&self, pairs: &[(&[u8], &[u8])]) -> Result { - crate::bn128::crypto_backend::pairing_check(pairs) + fn bn254_pairing_check(&self, pairs: &[(&[u8], &[u8])]) -> Result { + crate::bn254::crypto_backend::pairing_check(pairs) } /// secp256k1 ECDSA signature recovery. @@ -218,12 +218,12 @@ pub enum PrecompileError { ModexpModOverflow, /// Modexp limit all input sizes. ModexpEip7823LimitSize, - /// Bn128 errors - Bn128FieldPointNotAMember, - /// Bn128 affine g failed to create - Bn128AffineGFailedToCreate, - /// Bn128 pair length - Bn128PairLength, + /// Bn254 errors + Bn254FieldPointNotAMember, + /// Bn254 affine g failed to create + Bn254AffineGFailedToCreate, + /// Bn254 pair length + Bn254PairLength, // Blob errors /// The input length is not exactly 192 bytes BlobInvalidInputLength, @@ -261,9 +261,9 @@ impl fmt::Display for PrecompileError { Self::ModexpBaseOverflow => "modexp base overflow", Self::ModexpModOverflow => "modexp mod overflow", Self::ModexpEip7823LimitSize => "Modexp limit all input sizes.", - Self::Bn128FieldPointNotAMember => "field point not a member of bn128 curve", - Self::Bn128AffineGFailedToCreate => "failed to create affine g point for bn128 curve", - Self::Bn128PairLength => "bn128 invalid pair length", + Self::Bn254FieldPointNotAMember => "field point not a member of bn254 curve", + Self::Bn254AffineGFailedToCreate => "failed to create affine g point for bn254 curve", + Self::Bn254PairLength => "bn254 invalid pair length", Self::BlobInvalidInputLength => "invalid blob input length", Self::BlobMismatchedVersion => "mismatched blob version", Self::BlobVerifyKzgProofFailed => "verifying blob kzg proof failed", diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index bf0389c5ea..4968f74556 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -12,7 +12,7 @@ pub mod blake2; pub mod bls12_381; pub mod bls12_381_const; pub mod bls12_381_utils; -pub mod bn128; +pub mod bn254; pub mod hash; pub mod identity; pub mod interface; @@ -118,9 +118,9 @@ impl Precompiles { modexp::BYZANTIUM, // EIP-196: Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128. // EIP-197: Precompiled contracts for optimal ate pairing check on the elliptic curve alt_bn128. - bn128::add::BYZANTIUM, - bn128::mul::BYZANTIUM, - bn128::pair::BYZANTIUM, + bn254::add::BYZANTIUM, + bn254::mul::BYZANTIUM, + bn254::pair::BYZANTIUM, ]); precompiles }) @@ -133,9 +133,9 @@ impl Precompiles { let mut precompiles = Self::byzantium().clone(); precompiles.extend([ // EIP-1108: Reduce alt_bn128 precompile gas costs. - bn128::add::ISTANBUL, - bn128::mul::ISTANBUL, - bn128::pair::ISTANBUL, + bn254::add::ISTANBUL, + bn254::mul::ISTANBUL, + bn254::pair::ISTANBUL, // EIP-152: Add BLAKE2 compression function `F` precompile. blake2::FUN, ]);