Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(op): Ecotone hardfork #1009

Merged
merged 5 commits into from
Jan 29, 2024
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
5 changes: 5 additions & 0 deletions crates/interpreter/src/instructions/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,11 @@ pub const fn spec_opcode_gas(spec_id: SpecId) -> &'static [OpInfo; 256] {
const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::CANYON);
TABLE
}
#[cfg(feature = "optimism")]
SpecId::ECOTONE => {
const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::ECOTONE);
TABLE
}
}
};
}
Expand Down
2 changes: 2 additions & 0 deletions crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ impl PrecompileSpecId {
LATEST => Self::LATEST,
#[cfg(feature = "optimism")]
BEDROCK | REGOLITH | CANYON => Self::BERLIN,
#[cfg(feature = "optimism")]
ECOTONE => Self::CANCUN,
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions crates/primitives/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub enum SpecId {
SHANGHAI = 18,
CANYON = 19,
CANCUN = 20,
ECOTONE = 21,
LATEST = u8::MAX,
}

Expand Down Expand Up @@ -102,6 +103,8 @@ impl From<&str> for SpecId {
"Regolith" => SpecId::REGOLITH,
#[cfg(feature = "optimism")]
"Canyon" => SpecId::CANYON,
#[cfg(feature = "optimism")]
"Ecotone" => SpecId::ECOTONE,
_ => Self::LATEST,
}
}
Expand Down Expand Up @@ -157,6 +160,8 @@ spec!(BEDROCK, BedrockSpec);
spec!(REGOLITH, RegolithSpec);
#[cfg(feature = "optimism")]
spec!(CANYON, CanyonSpec);
#[cfg(feature = "optimism")]
spec!(ECOTONE, EcotoneSpec);

#[macro_export]
macro_rules! spec_to_generic {
Expand Down Expand Up @@ -232,6 +237,11 @@ macro_rules! spec_to_generic {
use $crate::CanyonSpec as SPEC;
$e
}
#[cfg(feature = "optimism")]
$crate::SpecId::ECOTONE => {
use $crate::EcotoneSpec as SPEC;
$e
}
}
}};
}
Expand Down Expand Up @@ -338,4 +348,28 @@ mod optimism_tests {
assert!(SpecId::enabled(SpecId::CANYON, SpecId::REGOLITH));
assert!(SpecId::enabled(SpecId::CANYON, SpecId::CANYON));
}

#[test]
fn test_ecotone_post_merge_hardforks() {
assert!(EcotoneSpec::enabled(SpecId::MERGE));
assert!(EcotoneSpec::enabled(SpecId::SHANGHAI));
assert!(EcotoneSpec::enabled(SpecId::CANCUN));
assert!(!EcotoneSpec::enabled(SpecId::LATEST));
assert!(EcotoneSpec::enabled(SpecId::BEDROCK));
assert!(EcotoneSpec::enabled(SpecId::REGOLITH));
assert!(EcotoneSpec::enabled(SpecId::CANYON));
assert!(EcotoneSpec::enabled(SpecId::ECOTONE));
}

#[test]
fn test_ecotone_post_merge_hardforks_spec_id() {
assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::MERGE));
assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::SHANGHAI));
assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::CANCUN));
assert!(!SpecId::enabled(SpecId::ECOTONE, SpecId::LATEST));
assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::BEDROCK));
assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::REGOLITH));
assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::CANYON));
assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::ECOTONE));
}
}
5 changes: 3 additions & 2 deletions crates/revm/src/handler/mainnet/pre_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ pub fn load<SPEC: Spec, EXT, DB: Database>(
// the L1-cost fee is only computed for Optimism non-deposit transactions.
#[cfg(feature = "optimism")]
if context.evm.env.cfg.optimism && context.evm.env.tx.optimism.source_hash.is_none() {
let l1_block_info = crate::optimism::L1BlockInfo::try_fetch(&mut context.evm.db)
.map_err(EVMError::Database)?;
let l1_block_info =
crate::optimism::L1BlockInfo::try_fetch(&mut context.evm.db, SPEC::SPEC_ID)
.map_err(EVMError::Database)?;

// storage l1 block info for later use.
context.evm.l1_block_info = Some(l1_block_info);
Expand Down
20 changes: 12 additions & 8 deletions crates/revm/src/optimism/handler_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,9 @@ mod tests {
let mut context: Context<(), InMemoryDB> = Context::new_with_db(db);
context.evm.l1_block_info = Some(L1BlockInfo {
l1_base_fee: U256::from(1_000),
l1_fee_overhead: U256::from(1_000),
l1_fee_scalar: U256::from(1_000),
l1_fee_overhead: Some(U256::from(1_000)),
l1_base_fee_scalar: U256::from(1_000),
..Default::default()
});
// Enveloped needs to be some but it will deduce zero fee.
context.evm.env.tx.optimism.enveloped_tx = Some(bytes!(""));
Expand Down Expand Up @@ -442,8 +443,9 @@ mod tests {
let mut context: Context<(), InMemoryDB> = Context::new_with_db(db);
context.evm.l1_block_info = Some(L1BlockInfo {
l1_base_fee: U256::from(1_000),
l1_fee_overhead: U256::from(1_000),
l1_fee_scalar: U256::from(1_000),
l1_fee_overhead: Some(U256::from(1_000)),
l1_base_fee_scalar: U256::from(1_000),
..Default::default()
});
// l1block cost is 1048 fee.
context.evm.env.tx.optimism.enveloped_tx = Some(bytes!("FACADE"));
Expand Down Expand Up @@ -478,8 +480,9 @@ mod tests {
let mut context: Context<(), InMemoryDB> = Context::new_with_db(db);
context.evm.l1_block_info = Some(L1BlockInfo {
l1_base_fee: U256::from(1_000),
l1_fee_overhead: U256::from(1_000),
l1_fee_scalar: U256::from(1_000),
l1_fee_overhead: Some(U256::from(1_000)),
l1_base_fee_scalar: U256::from(1_000),
..Default::default()
});
// l1block cost is 1048 fee.
context.evm.env.tx.optimism.enveloped_tx = Some(bytes!("FACADE"));
Expand Down Expand Up @@ -508,8 +511,9 @@ mod tests {
let mut context: Context<(), InMemoryDB> = Context::new_with_db(db);
context.evm.l1_block_info = Some(L1BlockInfo {
l1_base_fee: U256::from(1_000),
l1_fee_overhead: U256::from(1_000),
l1_fee_scalar: U256::from(1_000),
l1_fee_overhead: Some(U256::from(1_000)),
l1_base_fee_scalar: U256::from(1_000),
..Default::default()
});
// l1block cost is 1048 fee.
context.evm.env.tx.optimism.enveloped_tx = Some(bytes!("FACADE"));
Expand Down
Loading
Loading