Skip to content

Commit

Permalink
feat: support Wright upgrade for opbnb (#52)
Browse files Browse the repository at this point in the history
* feat: support Wright upgrade for opbnb

* fix lint errors

* fix lint errors
  • Loading branch information
yutianwu authored Aug 6, 2024
1 parent 0161a27 commit 8675437
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
2 changes: 2 additions & 0 deletions crates/precompile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ impl PrecompileSpecId {
FERMAT => Self::FERMAT,
#[cfg(any(feature = "bsc", feature = "opbnb"))]
HABER => Self::HABER,
#[cfg(feature = "opbnb")]
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
27 changes: 18 additions & 9 deletions crates/revm/src/optimism/handler_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
primitives::{
db::Database, spec_to_generic, Account, EVMError, Env, ExecutionResult, HaltReason,
HashMap, InvalidTransaction, OptimismInvalidTransaction, ResultAndState, Spec, SpecId,
SpecId::REGOLITH, U256,
SpecId::REGOLITH, SpecId::WRIGHT, U256,
},
Context, ContextPrecompiles, FrameResult,
};
Expand Down Expand Up @@ -211,13 +211,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 @@ -259,7 +264,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 8675437

Please sign in to comment.