Skip to content

Commit

Permalink
feat: support Wright upgrade for opbnb
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu committed Aug 2, 2024
1 parent 8a18176 commit 520525a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ impl PrecompileSpecId {
#[cfg(feature = "opbnb")]
FERMAT => Self::FERMAT,
#[cfg(any(feature = "bsc", feature = "opbnb"))]
HABER => Self::HABER,
HABER | WRIGHT => Self::HABER,
#[cfg(feature = "bsc")]
HABER_FIX => Self::HABER,
#[cfg(feature = "bsc")]
Expand Down
19 changes: 15 additions & 4 deletions crates/primitives/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ pub enum SpecId {
CANCUN = 21,
ECOTONE = 22,
HABER = 23,
FJORD = 24,
PRAGUE = 25,
PRAGUE_EOF = 26,
WRIGHT = 24,
FJORD = 25,
PRAGUE = 26,
PRAGUE_EOF = 27,
#[default]
LATEST = u8::MAX,
}
Expand Down Expand Up @@ -216,6 +217,8 @@ impl From<&str> for SpecId {
"HaberFix" => SpecId::HABER_FIX,
#[cfg(feature = "bsc")]
"Bohr" => SpecId::BOHR,
#[cfg(feature = "opbnb")]
"Wright" => SpecId::WRIGHT,
_ => Self::LATEST,
}
}
Expand Down Expand Up @@ -290,6 +293,8 @@ impl From<SpecId> for &'static str {
SpecId::FEYNMAN_FIX => "FeynmanFix",
#[cfg(any(feature = "opbnb", feature = "bsc"))]
SpecId::HABER => "Haber",
#[cfg(feature = "opbnb")]
SpecId::WRIGHT => "Wright",
#[cfg(feature = "bsc")]
SpecId::HABER_FIX => "HaberFix",
#[cfg(feature = "bsc")]
Expand Down Expand Up @@ -377,7 +382,8 @@ spec!(ECOTONE, EcotoneSpec);
spec!(FJORD, FjordSpec);
#[cfg(feature = "opbnb")]
spec!(FERMAT, FermatSpec);

#[cfg(feature = "opbnb")]
spec!(WRIGHT, WrightSpec);
#[cfg(all(not(feature = "optimism"), not(feature = "bsc")))]
#[macro_export]
macro_rules! spec_to_generic {
Expand Down Expand Up @@ -542,6 +548,11 @@ macro_rules! spec_to_generic {
use $crate::HaberSpec as SPEC;
$e
}
#[cfg(feature = "opbnb")]
$crate::SpecId::WRIGHT => {
use $crate::WrightSpec as SPEC;
$e
}
$crate::SpecId::FJORD => {
use $crate::FjordSpec as SPEC;
$e
Expand Down
26 changes: 18 additions & 8 deletions crates/revm/src/optimism/handler_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use core::ops::Mul;
use revm_precompile::{secp256r1, PrecompileSpecId};
use std::string::ToString;
use std::sync::Arc;
use crate::primitives::WRIGHT;

pub fn optimism_handle_register<DB: Database, EXT>(handler: &mut EvmHandler<'_, EXT, DB>) {
spec_to_generic!(handler.cfg.spec_id, {
Expand Down Expand Up @@ -207,13 +208,18 @@ pub fn deduct_caller<SPEC: Spec, EXT, DB: Database>(
));
};

let tx_l1_cost = context
.evm
.inner
.l1_block_info
.as_ref()
.expect("L1BlockInfo should be loaded")
.calculate_tx_l1_cost(enveloped_tx, SPEC::SPEC_ID);
let tx_l1_cost = if context.evm.inner.env.tx.gas_price.is_zero() && SPEC::enabled(WRIGHT) {
U256::ZERO
} else {
context
.evm
.inner
.l1_block_info
.as_ref()
.expect("L1BlockInfo should be loaded")
.calculate_tx_l1_cost(enveloped_tx, SPEC::SPEC_ID)
};

if tx_l1_cost.gt(&caller_account.info.balance) {
return Err(EVMError::Transaction(
InvalidTransaction::LackOfFundForMaxFee {
Expand Down Expand Up @@ -255,7 +261,11 @@ pub fn reward_beneficiary<SPEC: Spec, EXT, DB: Database>(
));
};

let l1_cost = l1_block_info.calculate_tx_l1_cost(enveloped_tx, SPEC::SPEC_ID);
let l1_cost = if context.evm.inner.env.tx.gas_price.is_zero() && SPEC::enabled(WRIGHT) {
U256::ZERO
} else {
l1_block_info.calculate_tx_l1_cost(enveloped_tx, SPEC::SPEC_ID)
};

// Send the L1 cost of the transaction to the L1 Fee Vault.
let (l1_fee_vault_account, _) = context
Expand Down

0 comments on commit 520525a

Please sign in to comment.