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
2 changes: 1 addition & 1 deletion crates/database/src/states/bundle_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl BundleAccount {
}
}

/// Fetch account info if it exist.
/// Fetch account info if it exists.
pub fn account_info(&self) -> Option<AccountInfo> {
self.info.clone()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/database/src/states/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct State<DB> {
///
/// This allows us to have only one layer of cache where we can fetch data.
///
/// Additionally we can introduce some preloading of data from database.
/// Additionally, we can introduce some preloading of data from database.
pub cache: CacheState,
/// Optional database that we use to fetch data from
///
Expand Down Expand Up @@ -290,7 +290,7 @@ impl<DB: Database> Database for State<DB> {
btree_map::Entry::Vacant(entry) => {
let ret = *entry.insert(self.database.block_hash(number)?);

// Prune all hashes that are older then BLOCK_HASH_HISTORY
// Prune all hashes that are older than BLOCK_HASH_HISTORY
let last_block = number.saturating_sub(BLOCK_HASH_HISTORY);
while let Some(entry) = self.block_hashes.first_entry() {
if *entry.key() < last_block {
Expand Down
4 changes: 2 additions & 2 deletions crates/database/src/states/state_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct StateBuilder<DB> {
with_bundle_update: bool,
/// Do we want to merge transitions in background?
///
/// This will allows evm to continue executing.
/// This will allow evm to continue executing.
///
/// Default is false.
with_background_transition_merge: bool,
Expand Down Expand Up @@ -64,7 +64,7 @@ impl<DB: Database> StateBuilder<DB> {
/// Set the database.
pub fn with_database<ODB: Database>(self, database: ODB) -> StateBuilder<ODB> {
// Cast to the different database.
// Note that we return different type depending of the database NewDBError.
// Note that we return different type depending on the database NewDBError.
StateBuilder {
with_state_clear: self.with_state_clear,
database,
Expand Down
8 changes: 4 additions & 4 deletions crates/handler/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use interpreter::{
CreateScheme, EOFCreateInputs, EOFCreateKind, FrameInput, Gas, InputsImpl, InstructionResult,
Interpreter, InterpreterAction, InterpreterResult, InterpreterTypes, SharedMemory,
};
use precompile::PrecompileErrors;
use precompile::PrecompileError;
use primitives::{keccak256, Address, Bytes, B256, U256};
use specification::{
constants::CALL_STACK_LIMIT,
Expand Down Expand Up @@ -81,7 +81,7 @@ where
Output = InterpreterAction,
>,
>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileErrors>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileError>,
{
type Evm = EVM;
type FrameInit = FrameInput;
Expand Down Expand Up @@ -150,7 +150,7 @@ where
Precompiles: PrecompileProvider<Context = EVM::Context, Output = InterpreterResult>,
Instructions: InstructionProvider,
>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileErrors>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileError>,
{
/// Make call frame
#[inline]
Expand Down Expand Up @@ -522,7 +522,7 @@ where
Output = InterpreterAction,
>,
>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileErrors>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileError>,
{
pub fn init_first(
evm: &mut EVM,
Expand Down
6 changes: 3 additions & 3 deletions crates/handler/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use context_interface::{
};
use core::mem;
use interpreter::{FrameInput, Host, InitialAndFloorGas, Interpreter, InterpreterAction};
use precompile::PrecompileErrors;
use precompile::PrecompileError;
use primitives::Log;
use state::EvmState;
use std::{vec, vec::Vec};
Expand All @@ -20,7 +20,7 @@ pub trait EvmTrError<EVM: EvmTr>:
From<InvalidTransaction>
+ From<InvalidHeader>
+ From<<<EVM::Context as ContextTr>::Db as Database>::Error>
+ From<PrecompileErrors>
+ From<PrecompileError>
{
}

Expand All @@ -29,7 +29,7 @@ impl<
T: From<InvalidTransaction>
+ From<InvalidHeader>
+ From<<<EVM::Context as ContextTr>::Db as Database>::Error>
+ From<PrecompileErrors>,
+ From<PrecompileError>,
> EvmTrError<EVM> for T
{
}
Expand Down
Empty file.
12 changes: 7 additions & 5 deletions crates/handler/src/precompile_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use auto_impl::auto_impl;
use context::Cfg;
use context_interface::ContextTr;
use interpreter::{Gas, InstructionResult, InterpreterResult};
use precompile::PrecompileErrors;
use precompile::PrecompileError;
use precompile::{PrecompileSpecId, Precompiles};
use primitives::{Address, Bytes};
use specification::hardfork::SpecId;
Expand All @@ -22,7 +22,7 @@ pub trait PrecompileProvider {
address: &Address,
bytes: &Bytes,
gas_limit: u64,
) -> Result<Option<Self::Output>, PrecompileErrors>;
) -> Result<Option<Self::Output>, PrecompileError>;

/// Get the warm addresses.
fn warm_addresses(&self) -> Box<impl Iterator<Item = Address> + '_>;
Expand Down Expand Up @@ -70,7 +70,7 @@ where
address: &Address,
bytes: &Bytes,
gas_limit: u64,
) -> Result<Option<InterpreterResult>, PrecompileErrors> {
) -> Result<Option<InterpreterResult>, PrecompileError> {
let Some(precompile) = self.precompiles.get(address) else {
return Ok(None);
};
Expand All @@ -88,14 +88,16 @@ where
result.result = InstructionResult::Return;
result.output = output.bytes;
}
Err(PrecompileErrors::Error(e)) => {
Err(e) => {
if let PrecompileError::Fatal(_) = e {
return Err(e);
}
result.result = if e.is_oog() {
InstructionResult::PrecompileOOG
} else {
InstructionResult::PrecompileError
};
}
Err(err @ PrecompileErrors::Fatal { .. }) => return Err(err),
}
Ok(Some(result))
}
Expand Down
4 changes: 2 additions & 2 deletions crates/inspector/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use interpreter::{
interpreter::EthInterpreter, FrameInput, Interpreter, InterpreterAction, InterpreterResult,
InterpreterTypes,
};
use precompile::PrecompileErrors;
use precompile::PrecompileError;

/// Inspector EVM trait.
pub trait InspectorEvmTr: EvmTr {
Expand Down Expand Up @@ -83,7 +83,7 @@ where
Output = InterpreterAction,
>,
> + InspectorEvmTr,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileErrors>,
ERROR: From<ContextTrDbError<EVM::Context>> + From<PrecompileError>,
{
type IT = EthInterpreter;

Expand Down
19 changes: 5 additions & 14 deletions crates/optimism/src/bn128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub mod pair {

pub fn run_pair(input: &[u8], gas_limit: u64) -> PrecompileResult {
if input.len() > GRANITE_MAX_INPUT_SIZE {
return Err(PrecompileError::Bn128PairLength.into());
return Err(PrecompileError::Bn128PairLength);
}
bn128::run_pair(
input,
Expand All @@ -27,7 +27,7 @@ pub mod pair {
#[cfg(test)]
mod tests {
use super::*;
use revm::{precompile::PrecompileErrors, primitives::hex};
use revm::{precompile::PrecompileError, primitives::hex};
use std::vec;

#[test]
Expand Down Expand Up @@ -65,25 +65,16 @@ mod tests {
.unwrap();

let res = pair::run_pair(&input, 260_000);
assert!(matches!(
res,
Err(PrecompileErrors::Error(PrecompileError::Bn128PairLength))
));
assert!(matches!(res, Err(PrecompileError::Bn128PairLength)));

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

// Input length longer than 112687
let input = vec![1u8; 587 * bn128::PAIR_ELEMENT_LEN];
let res = pair::run_pair(&input, 260_000);
assert!(matches!(
res,
Err(PrecompileErrors::Error(PrecompileError::Bn128PairLength))
));
assert!(matches!(res, Err(PrecompileError::Bn128PairLength)));
}
}
4 changes: 2 additions & 2 deletions crates/optimism/src/handler/precompiles.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::OpSpecId;
use once_cell::race::OnceBox;
use precompile::{secp256r1, PrecompileErrors, Precompiles};
use precompile::{secp256r1, PrecompileError, Precompiles};
use revm::{
context::Cfg,
context_interface::ContextTr,
Expand Down Expand Up @@ -103,7 +103,7 @@ where
address: &precompile::Address,
bytes: &precompile::Bytes,
gas_limit: u64,
) -> Result<Option<Self::Output>, PrecompileErrors> {
) -> Result<Option<Self::Output>, PrecompileError> {
self.precompile_provider
.run(context, address, bytes, gas_limit)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/precompile/src/blake2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ pub fn run(input: &Bytes, gas_limit: u64) -> PrecompileResult {
let input = &input[..];

if input.len() != INPUT_LENGTH {
return Err(PrecompileError::Blake2WrongLength.into());
return Err(PrecompileError::Blake2WrongLength);
}

// Rounds 4 bytes
let rounds = u32::from_be_bytes(input[..4].try_into().unwrap()) as usize;
let gas_used = rounds as u64 * F_ROUND;
if gas_used > gas_limit {
return Err(PrecompileError::OutOfGas.into());
return Err(PrecompileError::OutOfGas);
}

let f = match input[212] {
1 => true,
0 => false,
_ => return Err(PrecompileError::Blake2WrongFinalIndicatorFlag.into()),
_ => return Err(PrecompileError::Blake2WrongFinalIndicatorFlag),
};

let mut h = [0u64; 8];
Expand Down
5 changes: 2 additions & 3 deletions crates/precompile/src/bls12_381/g1_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ pub const PRECOMPILE: PrecompileWithAddress =
/// See also: <https://eips.ethereum.org/EIPS/eip-2537#abi-for-g1-addition>
pub(super) fn g1_add(input: &Bytes, gas_limit: u64) -> PrecompileResult {
if G1_ADD_BASE_GAS_FEE > gas_limit {
return Err(PrecompileError::OutOfGas.into());
return Err(PrecompileError::OutOfGas);
}

if input.len() != G1_ADD_INPUT_LENGTH {
return Err(PrecompileError::Other(format!(
"G1ADD input should be {G1_ADD_INPUT_LENGTH} bytes, was {}",
input.len()
))
.into());
)));
}

// NB: There is no subgroup check for the G1 addition precompile.
Expand Down
5 changes: 2 additions & 3 deletions crates/precompile/src/bls12_381/g1_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ pub(super) fn g1_msm(input: &Bytes, gas_limit: u64) -> PrecompileResult {
return Err(PrecompileError::Other(format!(
"G1MSM input length should be multiple of {}, was {}",
G1_MSM_INPUT_LENGTH, input_len
))
.into());
)));
}

let k = input_len / G1_MSM_INPUT_LENGTH;
let required_gas = msm_required_gas(k, &DISCOUNT_TABLE_G1_MSM, G1_MSM_BASE_GAS_FEE);
if required_gas > gas_limit {
return Err(PrecompileError::OutOfGas.into());
return Err(PrecompileError::OutOfGas);
}

let mut g1_points: Vec<blst_p1> = Vec::with_capacity(k);
Expand Down
5 changes: 2 additions & 3 deletions crates/precompile/src/bls12_381/g2_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ pub const PRECOMPILE: PrecompileWithAddress =
/// See also <https://eips.ethereum.org/EIPS/eip-2537#abi-for-g2-addition>
pub(super) fn g2_add(input: &Bytes, gas_limit: u64) -> PrecompileResult {
if G2_ADD_BASE_GAS_FEE > gas_limit {
return Err(PrecompileError::OutOfGas.into());
return Err(PrecompileError::OutOfGas);
}

if input.len() != G2_ADD_INPUT_LENGTH {
return Err(PrecompileError::Other(format!(
"G2ADD input should be {G2_ADD_INPUT_LENGTH} bytes, was {}",
input.len()
))
.into());
)));
}

// NB: There is no subgroup check for the G2 addition precompile.
Expand Down
5 changes: 2 additions & 3 deletions crates/precompile/src/bls12_381/g2_msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ pub(super) fn g2_msm(input: &Bytes, gas_limit: u64) -> PrecompileResult {
return Err(PrecompileError::Other(format!(
"G2MSM input length should be multiple of {}, was {}",
G2_MSM_INPUT_LENGTH, input_len
))
.into());
)));
}

let k = input_len / G2_MSM_INPUT_LENGTH;
let required_gas = msm_required_gas(k, &DISCOUNT_TABLE_G2_MSM, G2_MSM_BASE_GAS_FEE);
if required_gas > gas_limit {
return Err(PrecompileError::OutOfGas.into());
return Err(PrecompileError::OutOfGas);
}

let mut g2_points: Vec<blst_p2> = Vec::with_capacity(k);
Expand Down
5 changes: 2 additions & 3 deletions crates/precompile/src/bls12_381/map_fp2_to_g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ pub const PRECOMPILE: PrecompileWithAddress =
/// See also: <https://eips.ethereum.org/EIPS/eip-2537#abi-for-mapping-fp2-element-to-g2-point>
pub(super) fn map_fp2_to_g2(input: &Bytes, gas_limit: u64) -> PrecompileResult {
if MAP_FP2_TO_G2_BASE_GAS_FEE > gas_limit {
return Err(PrecompileError::OutOfGas.into());
return Err(PrecompileError::OutOfGas);
}

if input.len() != PADDED_FP2_LENGTH {
return Err(PrecompileError::Other(format!(
"MAP_FP2_TO_G2 input should be {PADDED_FP2_LENGTH} bytes, was {}",
input.len()
))
.into());
)));
}

let input_p0_x = remove_padding(&input[..PADDED_FP_LENGTH])?;
Expand Down
7 changes: 3 additions & 4 deletions crates/precompile/src/bls12_381/map_fp_to_g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ pub const PRECOMPILE: PrecompileWithAddress =
/// See also: <https://eips.ethereum.org/EIPS/eip-2537#abi-for-mapping-fp-element-to-g1-point>
pub(super) fn map_fp_to_g1(input: &Bytes, gas_limit: u64) -> PrecompileResult {
if MAP_FP_TO_G1_BASE_GAS_FEE > gas_limit {
return Err(PrecompileError::OutOfGas.into());
return Err(PrecompileError::OutOfGas);
}

if input.len() != PADDED_FP_LENGTH {
return Err(PrecompileError::Other(format!(
"MAP_FP_TO_G1 input should be {PADDED_FP_LENGTH} bytes, was {}",
input.len()
))
.into());
)));
}

let input_p0 = remove_padding(input)?;
Expand Down Expand Up @@ -55,7 +54,7 @@ mod test {
let fail = map_fp_to_g1(&input, MAP_FP_TO_G1_BASE_GAS_FEE);
assert_eq!(
fail,
Err(PrecompileError::Other("non-canonical fp value".to_string()).into())
Err(PrecompileError::Other("non-canonical fp value".to_string()))
);
}
}
8 changes: 4 additions & 4 deletions crates/precompile/src/bls12_381/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ pub(super) fn pairing(input: &Bytes, gas_limit: u64) -> PrecompileResult {
if input_len == 0 || input_len % PAIRING_INPUT_LENGTH != 0 {
return Err(PrecompileError::Other(format!(
"Pairing input length should be multiple of {PAIRING_INPUT_LENGTH}, was {input_len}"
))
.into());
)));
}

let k = input_len / PAIRING_INPUT_LENGTH;
let required_gas: u64 = PAIRING_PAIRING_MULTIPLIER_BASE * k as u64 + PAIRING_PAIRING_OFFSET_BASE;
let required_gas: u64 =
PAIRING_PAIRING_MULTIPLIER_BASE * k as u64 + PAIRING_PAIRING_OFFSET_BASE;
if required_gas > gas_limit {
return Err(PrecompileError::OutOfGas.into());
return Err(PrecompileError::OutOfGas);
}

// Accumulator for the fp12 multiplications of the miller loops.
Expand Down
Loading
Loading