From db14503bf30723cb684903a6f3ed3280b1241180 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Mon, 15 Sep 2025 14:35:54 +0200 Subject: [PATCH] feat: upstream merge v86 --- Cargo.lock | 52 +++++++++++++-------------- src/instructions.rs | 19 +++++----- src/precompile/blake2.rs | 6 ++-- src/precompile/{bn128.rs => bn254.rs} | 18 +++++----- src/precompile/hash.rs | 18 +++++----- src/precompile/mod.rs | 26 +++++++------- src/precompile/modexp.rs | 9 ++--- src/system_call.rs | 15 ++++++++ 8 files changed, 91 insertions(+), 72 deletions(-) rename src/precompile/{bn128.rs => bn254.rs} (60%) diff --git a/Cargo.lock b/Cargo.lock index c6eb979..e736f52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1828,8 +1828,8 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "revm" -version = "27.1.0" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "29.0.0" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "revm-bytecode", "revm-context", @@ -1846,11 +1846,10 @@ dependencies = [ [[package]] name = "revm-bytecode" -version = "6.1.0" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "6.2.2" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "bitvec", - "once_cell", "phf", "revm-primitives", "serde", @@ -1858,9 +1857,10 @@ dependencies = [ [[package]] name = "revm-context" -version = "8.0.4" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "9.0.2" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ + "bitvec", "cfg-if", "derive-where", "revm-bytecode", @@ -1873,8 +1873,8 @@ dependencies = [ [[package]] name = "revm-context-interface" -version = "9.0.0" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "10.1.0" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "alloy-eip2930", "alloy-eip7702", @@ -1888,8 +1888,8 @@ dependencies = [ [[package]] name = "revm-database" -version = "7.0.2" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "7.0.5" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "alloy-eips", "revm-bytecode", @@ -1901,8 +1901,8 @@ dependencies = [ [[package]] name = "revm-database-interface" -version = "7.0.2" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "7.0.5" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "auto_impl", "either", @@ -1913,8 +1913,8 @@ dependencies = [ [[package]] name = "revm-handler" -version = "8.1.0" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "10.0.0" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "auto_impl", "derive-where", @@ -1931,8 +1931,8 @@ dependencies = [ [[package]] name = "revm-inspector" -version = "8.1.0" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "10.0.0" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "auto_impl", "either", @@ -1948,8 +1948,8 @@ dependencies = [ [[package]] name = "revm-interpreter" -version = "24.0.0" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "25.0.2" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "revm-bytecode", "revm-context-interface", @@ -1959,8 +1959,8 @@ dependencies = [ [[package]] name = "revm-precompile" -version = "25.0.0" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "27.0.0" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "ark-bls12-381", "ark-bn254", @@ -1975,7 +1975,6 @@ dependencies = [ "k256", "kzg-rs", "libsecp256k1", - "once_cell", "p256", "revm-primitives", "ripemd", @@ -1986,11 +1985,12 @@ dependencies = [ [[package]] name = "revm-primitives" -version = "20.1.0" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "20.2.1" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "alloy-primitives", "num_enum", + "once_cell", "serde", ] @@ -2009,8 +2009,8 @@ dependencies = [ [[package]] name = "revm-state" -version = "7.0.2" -source = "git+https://github.com/scroll-tech/revm#9cd9896c06a5bf6d4212906260d8789579873ba4" +version = "7.0.5" +source = "git+https://github.com/scroll-tech/revm#cc793301c260ce292d8deb59f61bc2a59bd0b991" dependencies = [ "bitflags", "revm-bytecode", diff --git a/src/instructions.rs b/src/instructions.rs index d2619f0..4d596a9 100644 --- a/src/instructions.rs +++ b/src/instructions.rs @@ -7,8 +7,8 @@ use revm::{ interpreter::{ _count, as_u64_saturated, as_usize_or_fail, gas, gas_or_fail, instruction_table, interpreter_types::{InputsTr, MemoryTr, RuntimeFlag, StackTr}, - popn, popn_top, push, require_non_staticcall, resize_memory, Host, InstructionContext, - InstructionResult, InstructionTable, InterpreterTypes, + popn, popn_top, push, require_non_staticcall, resize_memory, Host, Instruction, + InstructionContext, InstructionResult, InstructionTable, InterpreterTypes, }, primitives::{address, keccak256, Address, BLOCK_HASH_HISTORY, U256}, }; @@ -74,13 +74,14 @@ pub fn make_scroll_instruction_table(); // override the instructions - table[opcode::BLOCKHASH as usize] = blockhash::; - table[opcode::BASEFEE as usize] = basefee::; - table[opcode::TSTORE as usize] = tstore::; - table[opcode::TLOAD as usize] = tload::; - table[opcode::SELFDESTRUCT as usize] = selfdestruct::; - table[opcode::MCOPY as usize] = mcopy::; - table[opcode::DIFFICULTY as usize] = difficulty::; + // static gas values taken from + table[opcode::BLOCKHASH as usize] = Instruction::new(blockhash::, 20); + table[opcode::BASEFEE as usize] = Instruction::new(basefee::, 2); + table[opcode::TSTORE as usize] = Instruction::new(tstore::, 100); + table[opcode::TLOAD as usize] = Instruction::new(tload::, 100); + table[opcode::SELFDESTRUCT as usize] = Instruction::new(selfdestruct::, 0); + table[opcode::MCOPY as usize] = Instruction::new(mcopy::, 0); + table[opcode::DIFFICULTY as usize] = Instruction::new(difficulty::, 2); table } diff --git a/src/precompile/blake2.rs b/src/precompile/blake2.rs index 4ef6b2c..4395182 100644 --- a/src/precompile/blake2.rs +++ b/src/precompile/blake2.rs @@ -1,15 +1,15 @@ use super::precompile_not_implemented; use revm::{ - precompile::{blake2, PrecompileWithAddress}, + precompile::{u64_to_address, Precompile, PrecompileId}, primitives::Address, }; /// The BLAKE2 precompile address. -pub const ADDRESS: Address = blake2::FUN.0; +pub const ADDRESS: Address = u64_to_address(9); /// The BLAKE2 precompile is not implemented in the SHANGHAI hardfork. /// /// This precompile is not implemented and will return `PrecompileError::Other("Precompile not /// implemented".into())`. -pub const SHANGHAI: PrecompileWithAddress = precompile_not_implemented(ADDRESS); +pub const SHANGHAI: Precompile = precompile_not_implemented(PrecompileId::Blake2F, ADDRESS); diff --git a/src/precompile/bn128.rs b/src/precompile/bn254.rs similarity index 60% rename from src/precompile/bn128.rs rename to src/precompile/bn254.rs index 6f647db..5c8169d 100644 --- a/src/precompile/bn128.rs +++ b/src/precompile/bn254.rs @@ -1,22 +1,24 @@ use revm::precompile::{ - bn128::{self, run_pair, PAIR_ELEMENT_LEN}, - PrecompileError, PrecompileResult, PrecompileWithAddress, + bn254::{self, run_pair, PAIR_ELEMENT_LEN}, + PrecompileError, PrecompileResult, }; pub mod pair { use super::*; - pub use bn128::pair::{ADDRESS, ISTANBUL_PAIR_BASE, ISTANBUL_PAIR_PER_POINT}; + pub use bn254::pair::{ADDRESS, ISTANBUL_PAIR_BASE, ISTANBUL_PAIR_PER_POINT}; + use revm::precompile::{Precompile, PrecompileId}; /// The number of pairing inputs per pairing operation. If the inputs provided to the precompile /// call are < 4, we append (G1::infinity, G2::generator) until we have the required no. of /// inputs. const BERNOULLI_LEN_LIMIT: usize = 4; - /// The Bn128 pair precompile with BERNOULLI input rules. - pub const BERNOULLI: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, bernoulli_run); + /// The Bn254 pair precompile with BERNOULLI input rules. + pub const BERNOULLI: Precompile = + Precompile::new(PrecompileId::Bn254Pairing, ADDRESS, bernoulli_run); - /// The bernoulli Bn128 pair precompile implementation. + /// The bernoulli Bn254 pair precompile implementation. /// /// # Errors /// - `PrecompileError::Other("BN128PairingInputOverflow: input overflow".into())` if the input @@ -28,6 +30,6 @@ pub mod pair { run_pair(input, ISTANBUL_PAIR_PER_POINT, ISTANBUL_PAIR_BASE, gas_limit) } - /// The Bn128 pair precompile in FEYNMAN hardfork. - pub const FEYNMAN: PrecompileWithAddress = bn128::pair::ISTANBUL; + /// The Bn254 pair precompile in FEYNMAN hardfork. + pub const FEYNMAN: Precompile = bn254::pair::ISTANBUL; } diff --git a/src/precompile/hash.rs b/src/precompile/hash.rs index 1d84dce..5c7cc7b 100644 --- a/src/precompile/hash.rs +++ b/src/precompile/hash.rs @@ -1,32 +1,32 @@ use super::precompile_not_implemented; -use revm::{ - precompile::{hash, PrecompileWithAddress}, - primitives::Address, -}; +use revm::{precompile::hash, primitives::Address}; pub mod sha256 { use super::*; + use revm::precompile::{u64_to_address, Precompile, PrecompileId}; /// SHA-256 precompile address - pub const ADDRESS: Address = hash::SHA256.0; + pub const ADDRESS: Address = u64_to_address(2); /// The SHA256 precompile is not implemented in the Shanghai hardfork. - pub const SHANGHAI: PrecompileWithAddress = precompile_not_implemented(ADDRESS); + pub const SHANGHAI: Precompile = precompile_not_implemented(PrecompileId::Sha256, ADDRESS); /// The bernoulli SHA256 precompile implementation with address. - pub const BERNOULLI: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, hash::sha256_run); + pub const BERNOULLI: Precompile = + Precompile::new(PrecompileId::Sha256, ADDRESS, hash::sha256_run); } pub mod ripemd160 { use super::*; + use revm::precompile::{u64_to_address, Precompile, PrecompileId}; /// The RIPEMD160 precompile address. - pub const ADDRESS: Address = hash::RIPEMD160.0; + pub const ADDRESS: Address = u64_to_address(3); /// The shanghai RIPEMD160 precompile is not implemented in the Shanghai hardfork. /// /// This precompile is not implemented and will return `PrecompileError::Other("Precompile not /// implemented".into())`. - pub const SHANGHAI: PrecompileWithAddress = precompile_not_implemented(ADDRESS); + pub const SHANGHAI: Precompile = precompile_not_implemented(PrecompileId::Ripemd160, ADDRESS); } diff --git a/src/precompile/mod.rs b/src/precompile/mod.rs index 7121d8c..1028d9b 100644 --- a/src/precompile/mod.rs +++ b/src/precompile/mod.rs @@ -6,13 +6,13 @@ use revm::{ context::{Cfg, ContextTr}, handler::{EthPrecompiles, PrecompileProvider}, interpreter::{InputsImpl, InterpreterResult}, - precompile::{self, secp256r1, PrecompileError, PrecompileWithAddress, Precompiles}, + precompile::{self, secp256r1, Precompile, PrecompileError, PrecompileId, Precompiles}, primitives::Address, }; use revm_primitives::hardfork::SpecId; mod blake2; -mod bn128; +mod bn254; mod hash; mod modexp; @@ -44,8 +44,8 @@ impl ScrollPrecompileProvider { /// A helper function that creates a precompile that returns `PrecompileError::Other("Precompile not /// implemented".into())` for a given address. -const fn precompile_not_implemented(address: Address) -> PrecompileWithAddress { - PrecompileWithAddress(address, |_input: &[u8], _gas_limit: u64| { +const fn precompile_not_implemented(id: PrecompileId, address: Address) -> Precompile { + Precompile::new(id, address, |_input: &[u8], _gas_limit: u64| { Err(PrecompileError::Other("NotImplemented: Precompile not implemented".into())) }) } @@ -62,9 +62,9 @@ pub(crate) fn pre_bernoulli() -> &'static Precompiles { hash::ripemd160::SHANGHAI, precompile::identity::FUN, modexp::BERNOULLI, - precompile::bn128::add::ISTANBUL, - precompile::bn128::mul::ISTANBUL, - bn128::pair::BERNOULLI, + precompile::bn254::add::ISTANBUL, + precompile::bn254::mul::ISTANBUL, + bn254::pair::BERNOULLI, blake2::SHANGHAI, ]); @@ -97,7 +97,7 @@ pub(crate) fn feynman() -> &'static Precompiles { static INSTANCE: OnceBox = OnceBox::new(); INSTANCE.get_or_init(|| { let mut precompiles = euclid().clone(); - precompiles.extend([bn128::pair::FEYNMAN]); + precompiles.extend([bn254::pair::FEYNMAN]); Box::new(precompiles) }) } @@ -149,7 +149,7 @@ impl Default for ScrollPrecompileProvider { #[cfg(test)] mod tests { use super::*; - use crate::precompile::bn128::pair; + use crate::precompile::bn254::pair; use revm::primitives::hex; #[test] @@ -162,13 +162,13 @@ mod tests { .unwrap(); // Euclid version should reject this input - let f = euclid().get(&pair::ADDRESS).expect("precompile exists"); - let outcome = f(&input, u64::MAX); + let precompile = euclid().get(&pair::ADDRESS).expect("precompile exists"); + let outcome = precompile.execute(&input, u64::MAX); assert!(outcome.is_err()); // Feynman version should accept this input - let f = feynman().get(&pair::ADDRESS).expect("precompile exists"); - let outcome = f(&input, u64::MAX).expect("call succeeds"); + let precompile = feynman().get(&pair::ADDRESS).expect("precompile exists"); + let outcome = precompile.execute(&input, u64::MAX).expect("call succeeds"); assert_eq!(outcome.bytes, expected); } } diff --git a/src/precompile/modexp.rs b/src/precompile/modexp.rs index 1b4fbcc..4954343 100644 --- a/src/precompile/modexp.rs +++ b/src/precompile/modexp.rs @@ -1,20 +1,21 @@ use revm::{ precompile::{ - modexp::{self, berlin_gas_calc, run_inner}, + modexp::{berlin_gas_calc, run_inner}, + u64_to_address, utilities::right_pad_with_offset, - PrecompileError, PrecompileResult, PrecompileWithAddress, + Precompile, PrecompileError, PrecompileId, PrecompileResult, }, primitives::{Address, U256}, }; /// The MODEXP precompile address. -pub const ADDRESS: Address = modexp::BYZANTIUM.0; +pub const ADDRESS: Address = u64_to_address(5); /// The maximum length of the input for the MODEXP precompile in BERNOULLI hardfork. pub const BERNOULLI_LEN_LIMIT: U256 = U256::from_limbs([32, 0, 0, 0]); /// The MODEXP precompile with BERNOULLI length limit rule. -pub const BERNOULLI: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, bernoulli_run); +pub const BERNOULLI: Precompile = Precompile::new(PrecompileId::ModExp, ADDRESS, bernoulli_run); /// The bernoulli MODEXP precompile implementation. /// diff --git a/src/system_call.rs b/src/system_call.rs index cb599d2..fa9d41a 100644 --- a/src/system_call.rs +++ b/src/system_call.rs @@ -16,6 +16,21 @@ where CTX: ScrollContextTr + ContextSetters, PRECOMPILE: PrecompileProvider, { + fn system_call_one_with_caller( + &mut self, + caller: Address, + system_contract_address: Address, + data: Bytes, + ) -> Result { + self.0.ctx.set_tx(CTX::Tx::new_system_tx_with_caller( + caller, + system_contract_address, + data, + )); + let mut h = ScrollHandler::<_, _, EthFrame>::new(); + h.run_system_call(self) + } + fn transact_system_call_with_caller( &mut self, caller: Address,