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
52 changes: 26 additions & 26 deletions Cargo.lock

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

19 changes: 10 additions & 9 deletions src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -74,13 +74,14 @@ pub fn make_scroll_instruction_table<WIRE: InterpreterTypes, HOST: ScrollContext
let mut table = instruction_table::<WIRE, HOST>();

// override the instructions
table[opcode::BLOCKHASH as usize] = blockhash::<WIRE, HOST>;
table[opcode::BASEFEE as usize] = basefee::<WIRE, HOST>;
table[opcode::TSTORE as usize] = tstore::<WIRE, HOST>;
table[opcode::TLOAD as usize] = tload::<WIRE, HOST>;
table[opcode::SELFDESTRUCT as usize] = selfdestruct::<WIRE, HOST>;
table[opcode::MCOPY as usize] = mcopy::<WIRE, HOST>;
table[opcode::DIFFICULTY as usize] = difficulty::<WIRE, HOST>;
// static gas values taken from <https://github.com/bluealloy/revm/blob/v86/crates/interpreter/src/instructions.rs#L84>
table[opcode::BLOCKHASH as usize] = Instruction::new(blockhash::<WIRE, HOST>, 20);
table[opcode::BASEFEE as usize] = Instruction::new(basefee::<WIRE, HOST>, 2);
table[opcode::TSTORE as usize] = Instruction::new(tstore::<WIRE, HOST>, 100);
table[opcode::TLOAD as usize] = Instruction::new(tload::<WIRE, HOST>, 100);
table[opcode::SELFDESTRUCT as usize] = Instruction::new(selfdestruct::<WIRE, HOST>, 0);
table[opcode::MCOPY as usize] = Instruction::new(mcopy::<WIRE, HOST>, 0);
table[opcode::DIFFICULTY as usize] = Instruction::new(difficulty::<WIRE, HOST>, 2);

table
}
Expand Down
6 changes: 3 additions & 3 deletions src/precompile/blake2.rs
Original file line number Diff line number Diff line change
@@ -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);
18 changes: 10 additions & 8 deletions src/precompile/bn128.rs → src/precompile/bn254.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
18 changes: 9 additions & 9 deletions src/precompile/hash.rs
Original file line number Diff line number Diff line change
@@ -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);
}
26 changes: 13 additions & 13 deletions src/precompile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()))
})
}
Expand All @@ -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,
]);

Expand Down Expand Up @@ -97,7 +97,7 @@ pub(crate) fn feynman() -> &'static Precompiles {
static INSTANCE: OnceBox<Precompiles> = OnceBox::new();
INSTANCE.get_or_init(|| {
let mut precompiles = euclid().clone();
precompiles.extend([bn128::pair::FEYNMAN]);
precompiles.extend([bn254::pair::FEYNMAN]);
Box::new(precompiles)
})
}
Expand Down Expand Up @@ -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]
Expand All @@ -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);
}
}
9 changes: 5 additions & 4 deletions src/precompile/modexp.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
Loading
Loading