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
6 changes: 3 additions & 3 deletions crates/optimism/src/api/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{evm::OpEvm, transaction::OpTxTrait, L1BlockInfo, OpSpec, OpTransaction};
use crate::{evm::OpEvm, transaction::OpTxTrait, L1BlockInfo, OpSpecId, OpTransaction};
use precompile::Log;
use revm::{
context::{BlockEnv, Cfg, CfgEnv, TxEnv},
Expand Down Expand Up @@ -27,7 +27,7 @@ impl<BLOCK, TX, CFG, DB, JOURNAL> OpBuilder for Context<BLOCK, TX, CFG, DB, JOUR
where
BLOCK: Block,
TX: OpTxTrait,
CFG: Cfg<Spec = OpSpec>,
CFG: Cfg<Spec = OpSpecId>,
DB: Database,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)>,
{
Expand All @@ -48,4 +48,4 @@ where
}

pub type OpContext<DB> =
Context<BlockEnv, OpTransaction<TxEnv>, CfgEnv<OpSpec>, DB, JournaledState<DB>, L1BlockInfo>;
Context<BlockEnv, OpTransaction<TxEnv>, CfgEnv<OpSpecId>, DB, JournaledState<DB>, L1BlockInfo>;
8 changes: 4 additions & 4 deletions crates/optimism/src/api/default_ctx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{L1BlockInfo, OpSpec, OpSpecId, OpTransaction};
use crate::{L1BlockInfo, OpSpecId, OpTransaction};
use revm::{
context::{BlockEnv, CfgEnv, TxEnv},
database_interface::EmptyDB,
Expand All @@ -9,7 +9,7 @@ pub trait DefaultOp {
fn op() -> Context<
BlockEnv,
OpTransaction<TxEnv>,
CfgEnv<OpSpec>,
CfgEnv<OpSpecId>,
EmptyDB,
JournaledState<EmptyDB>,
L1BlockInfo,
Expand All @@ -20,7 +20,7 @@ impl DefaultOp
for Context<
BlockEnv,
OpTransaction<TxEnv>,
CfgEnv<OpSpec>,
CfgEnv<OpSpecId>,
EmptyDB,
JournaledState<EmptyDB>,
L1BlockInfo,
Expand All @@ -29,7 +29,7 @@ impl DefaultOp
fn op() -> Self {
Context::mainnet()
.with_tx(OpTransaction::default())
.with_cfg(CfgEnv::new().with_spec(OpSpec::Op(OpSpecId::BEDROCK)))
.with_cfg(CfgEnv::new().with_spec(OpSpecId::BEDROCK))
.with_chain(L1BlockInfo::default())
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/optimism/src/api/exec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
evm::OpEvm, handler::OpHandler, transaction::OpTxTrait, L1BlockInfo, OpHaltReason, OpSpec,
evm::OpEvm, handler::OpHandler, transaction::OpTxTrait, L1BlockInfo, OpHaltReason, OpSpecId,
OpTransactionError,
};
use precompile::Log;
Expand Down Expand Up @@ -29,7 +29,7 @@ impl<BLOCK, TX, CFG, DB, JOURNAL, INSP> ExecuteEvm
where
BLOCK: Block,
TX: OpTxTrait,
CFG: Cfg<Spec = OpSpec>,
CFG: Cfg<Spec = OpSpecId>,
DB: Database,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)> + JournalExt,
INSP: Inspector<Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>, EthInterpreter>,
Expand All @@ -52,7 +52,7 @@ impl<BLOCK, TX, CFG, DB, JOURNAL, INSP> ExecuteCommitEvm
where
BLOCK: Block,
TX: OpTxTrait,
CFG: Cfg<Spec = OpSpec>,
CFG: Cfg<Spec = OpSpecId>,
DB: Database + DatabaseCommit,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)> + JournalExt,
INSP: Inspector<Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>, EthInterpreter>,
Expand All @@ -79,7 +79,7 @@ impl<BLOCK, TX, CFG, DB, JOURNAL, INSP> InspectEvm
where
BLOCK: Block,
TX: OpTxTrait,
CFG: Cfg<Spec = OpSpec>,
CFG: Cfg<Spec = OpSpecId>,
DB: Database,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)> + JournalExt,
INSP: Inspector<Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>, EthInterpreter>,
Expand All @@ -105,7 +105,7 @@ impl<BLOCK, TX, CFG, DB, JOURNAL, INSP> InspectCommitEvm
where
BLOCK: Block,
TX: OpTxTrait,
CFG: Cfg<Spec = OpSpec>,
CFG: Cfg<Spec = OpSpecId>,
DB: Database + DatabaseCommit,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)> + JournalExt,
INSP: Inspector<Context<BLOCK, TX, CFG, DB, JOURNAL, L1BlockInfo>, EthInterpreter>,
Expand Down
43 changes: 23 additions & 20 deletions crates/optimism/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
deposit::{DepositTransaction, DEPOSIT_TRANSACTION_TYPE},
OpTransactionError, OpTxTrait,
},
L1BlockInfo, OpHaltReason, OpSpec, OpSpecId,
L1BlockInfo, OpHaltReason, OpSpecId,
};
use precompile::Log;
use revm::{
Expand Down Expand Up @@ -66,7 +66,7 @@ where
Context: ContextTrait<
Journal: Journal<FinalOutput = (EvmState, Vec<Log>)>,
Tx: OpTxTrait,
Cfg: Cfg<Spec = OpSpec>,
Cfg: Cfg<Spec = OpSpecId>,
Chain = L1BlockInfo,
>,
>,
Expand Down Expand Up @@ -290,9 +290,13 @@ where
// Prior to Regolith, deposit transactions did not receive gas refunds.
let is_gas_refund_disabled = is_deposit && !is_regolith;
if !is_gas_refund_disabled {
exec_result
.gas_mut()
.set_final_refund(evm.ctx().cfg().spec().is_enabled_in(SpecId::LONDON));
exec_result.gas_mut().set_final_refund(
evm.ctx()
.cfg()
.spec()
.into_eth_spec()
.is_enabled_in(SpecId::LONDON),
);
}
}

Expand Down Expand Up @@ -444,7 +448,7 @@ where
Context: ContextTrait<
Journal: Journal<FinalOutput = (EvmState, Vec<Log>)>,
Tx: OpTxTrait,
Cfg: Cfg<Spec = OpSpec>,
Cfg: Cfg<Spec = OpSpecId>,
Chain = L1BlockInfo,
>,
Inspector: Inspector<<<Self as EthHandler>::Evm as EvmTrait>::Context, EthInterpreter>,
Expand Down Expand Up @@ -507,7 +511,7 @@ mod tests {
tx.base.gas_limit = 100;
tx.enveloped_tx = None;
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::BEDROCK.into());
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::BEDROCK);

let gas = call_last_frame_return(ctx, InstructionResult::Revert, Gas::new(90));
assert_eq!(gas.remaining(), 90);
Expand All @@ -523,7 +527,7 @@ mod tests {
tx.deposit.source_hash = B256::ZERO;
tx.base.tx_type = DEPOSIT_TRANSACTION_TYPE;
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH.into());
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH);

let gas = call_last_frame_return(ctx, InstructionResult::Stop, Gas::new(90));
assert_eq!(gas.remaining(), 90);
Expand All @@ -539,7 +543,7 @@ mod tests {
tx.base.tx_type = DEPOSIT_TRANSACTION_TYPE;
tx.deposit.source_hash = B256::ZERO;
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH.into());
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH);

let mut ret_gas = Gas::new(90);
ret_gas.record_refund(20);
Expand All @@ -563,7 +567,7 @@ mod tests {
tx.base.gas_limit = 100;
tx.deposit.source_hash = B256::ZERO;
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::BEDROCK.into());
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::BEDROCK);
let gas = call_last_frame_return(ctx, InstructionResult::Stop, Gas::new(90));
assert_eq!(gas.remaining(), 0);
assert_eq!(gas.spent(), 100);
Expand All @@ -590,7 +594,7 @@ mod tests {
l1_base_fee_scalar: U256::from(1_000),
..Default::default()
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH.into());
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH);
ctx.modify_tx(|tx| {
tx.base.tx_type = DEPOSIT_TRANSACTION_TYPE;
tx.deposit.source_hash = B256::ZERO;
Expand Down Expand Up @@ -626,7 +630,7 @@ mod tests {
l1_base_fee_scalar: U256::from(1_000),
..Default::default()
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH.into())
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH)
.modify_tx_chained(|tx| {
tx.base.gas_limit = 100;
tx.base.tx_type = DEPOSIT_TRANSACTION_TYPE;
Expand Down Expand Up @@ -664,7 +668,7 @@ mod tests {
l1_base_fee_scalar: U256::from(1_000),
..Default::default()
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH.into())
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH)
.modify_tx_chained(|tx| {
tx.base.gas_limit = 100;
tx.deposit.source_hash = B256::ZERO;
Expand Down Expand Up @@ -700,7 +704,7 @@ mod tests {
operator_fee_constant: Some(U256::from(50)),
..Default::default()
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::ISTHMUS.into())
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::ISTHMUS)
.modify_tx_chained(|tx| {
tx.base.gas_limit = 10;
tx.enveloped_tx = Some(bytes!("FACADE"));
Expand Down Expand Up @@ -737,7 +741,7 @@ mod tests {
l1_base_fee_scalar: U256::from(1_000),
..Default::default()
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH.into())
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH)
.modify_tx_chained(|tx| {
tx.enveloped_tx = Some(bytes!("FACADE"));
});
Expand Down Expand Up @@ -767,7 +771,7 @@ mod tests {
tx.base.tx_type = DEPOSIT_TRANSACTION_TYPE;
tx.deposit.is_system_transaction = true;
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH.into());
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH);

let mut evm = ctx.build_op();
let handler = OpHandler::<_, EVMError<_, OpTransactionError>, EthFrame<_, _, _>>::new();
Expand All @@ -779,8 +783,7 @@ mod tests {
))
);

evm.ctx()
.modify_cfg(|cfg| cfg.spec = OpSpecId::BEDROCK.into());
evm.ctx().modify_cfg(|cfg| cfg.spec = OpSpecId::BEDROCK);

// Pre-regolith system transactions should be allowed.
assert!(handler.validate_env(&mut evm).is_ok());
Expand All @@ -794,7 +797,7 @@ mod tests {
tx.base.tx_type = DEPOSIT_TRANSACTION_TYPE;
tx.deposit.source_hash = B256::ZERO;
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH.into());
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH);

let mut evm = ctx.build_op();
let handler = OpHandler::<_, EVMError<_, OpTransactionError>, EthFrame<_, _, _>>::new();
Expand All @@ -810,7 +813,7 @@ mod tests {
tx.base.tx_type = DEPOSIT_TRANSACTION_TYPE;
tx.deposit.source_hash = B256::ZERO;
})
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH.into());
.modify_cfg_chained(|cfg| cfg.spec = OpSpecId::REGOLITH);

let mut evm = ctx.build_op();
let handler = OpHandler::<_, EVMError<_, OpTransactionError>, EthFrame<_, _, _>>::new();
Expand Down
43 changes: 11 additions & 32 deletions crates/optimism/src/handler/precompiles.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::{OpSpec, OpSpecId};
use crate::OpSpecId;
use once_cell::race::OnceBox;
use precompile::{secp256r1, PrecompileErrors, Precompiles};
use revm::{
context::Cfg,
context_interface::ContextTrait,
handler::{EthPrecompiles, PrecompileProvider},
interpreter::InterpreterResult,
specification::hardfork::SpecId,
};
use std::boxed::Box;

Expand All @@ -33,35 +32,15 @@ impl<CTX> OpPrecompileProvider<CTX> {
}

#[inline]
pub fn new_with_spec(spec: OpSpec) -> Self {
pub fn new_with_spec(spec: OpSpecId) -> Self {
match spec {
spec @ (OpSpec::Eth(
SpecId::FRONTIER
| SpecId::FRONTIER_THAWING
| SpecId::HOMESTEAD
| SpecId::DAO_FORK
| SpecId::TANGERINE
| SpecId::SPURIOUS_DRAGON
| SpecId::BYZANTIUM
| SpecId::CONSTANTINOPLE
| SpecId::PETERSBURG
| SpecId::ISTANBUL
| SpecId::MUIR_GLACIER
| SpecId::BERLIN
| SpecId::LONDON
| SpecId::ARROW_GLACIER
| SpecId::GRAY_GLACIER
| SpecId::MERGE
| SpecId::SHANGHAI
| SpecId::CANCUN,
)
| OpSpec::Op(
OpSpecId::BEDROCK | OpSpecId::REGOLITH | OpSpecId::CANYON | OpSpecId::ECOTONE,
)) => Self::new(Precompiles::new(spec.into_eth_spec().into())),
OpSpec::Op(OpSpecId::FJORD) => Self::new(fjord()),
OpSpec::Op(OpSpecId::GRANITE | OpSpecId::HOLOCENE) => Self::new(granite()),
OpSpec::Op(OpSpecId::ISTHMUS)
| OpSpec::Eth(SpecId::PRAGUE | SpecId::OSAKA | SpecId::LATEST) => Self::new(isthumus()),
spec @ (OpSpecId::BEDROCK
| OpSpecId::REGOLITH
| OpSpecId::CANYON
| OpSpecId::ECOTONE) => Self::new(Precompiles::new(spec.into_eth_spec().into())),
OpSpecId::FJORD => Self::new(fjord()),
OpSpecId::GRANITE | OpSpecId::HOLOCENE => Self::new(granite()),
OpSpecId::ISTHMUS => Self::new(isthumus()),
}
}
}
Expand Down Expand Up @@ -107,7 +86,7 @@ pub fn isthumus() -> &'static Precompiles {

impl<CTX> PrecompileProvider for OpPrecompileProvider<CTX>
where
CTX: ContextTrait<Cfg: Cfg<Spec = OpSpec>>,
CTX: ContextTrait<Cfg: Cfg<Spec = OpSpecId>>,
{
type Context = CTX;
type Output = InterpreterResult;
Expand Down Expand Up @@ -142,6 +121,6 @@ where

impl<CTX> Default for OpPrecompileProvider<CTX> {
fn default() -> Self {
Self::new_with_spec(OpSpec::Op(OpSpecId::ISTHMUS))
Self::new_with_spec(OpSpecId::ISTHMUS)
}
}
Loading
Loading