Skip to content

Commit 520525a

Browse files
committed
feat: support Wright upgrade for opbnb
1 parent 8a18176 commit 520525a

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

crates/precompile/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ impl PrecompileSpecId {
487487
#[cfg(feature = "opbnb")]
488488
FERMAT => Self::FERMAT,
489489
#[cfg(any(feature = "bsc", feature = "opbnb"))]
490-
HABER => Self::HABER,
490+
HABER | WRIGHT => Self::HABER,
491491
#[cfg(feature = "bsc")]
492492
HABER_FIX => Self::HABER,
493493
#[cfg(feature = "bsc")]

crates/primitives/src/specification.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ pub enum SpecId {
6969
CANCUN = 21,
7070
ECOTONE = 22,
7171
HABER = 23,
72-
FJORD = 24,
73-
PRAGUE = 25,
74-
PRAGUE_EOF = 26,
72+
WRIGHT = 24,
73+
FJORD = 25,
74+
PRAGUE = 26,
75+
PRAGUE_EOF = 27,
7576
#[default]
7677
LATEST = u8::MAX,
7778
}
@@ -216,6 +217,8 @@ impl From<&str> for SpecId {
216217
"HaberFix" => SpecId::HABER_FIX,
217218
#[cfg(feature = "bsc")]
218219
"Bohr" => SpecId::BOHR,
220+
#[cfg(feature = "opbnb")]
221+
"Wright" => SpecId::WRIGHT,
219222
_ => Self::LATEST,
220223
}
221224
}
@@ -290,6 +293,8 @@ impl From<SpecId> for &'static str {
290293
SpecId::FEYNMAN_FIX => "FeynmanFix",
291294
#[cfg(any(feature = "opbnb", feature = "bsc"))]
292295
SpecId::HABER => "Haber",
296+
#[cfg(feature = "opbnb")]
297+
SpecId::WRIGHT => "Wright",
293298
#[cfg(feature = "bsc")]
294299
SpecId::HABER_FIX => "HaberFix",
295300
#[cfg(feature = "bsc")]
@@ -377,7 +382,8 @@ spec!(ECOTONE, EcotoneSpec);
377382
spec!(FJORD, FjordSpec);
378383
#[cfg(feature = "opbnb")]
379384
spec!(FERMAT, FermatSpec);
380-
385+
#[cfg(feature = "opbnb")]
386+
spec!(WRIGHT, WrightSpec);
381387
#[cfg(all(not(feature = "optimism"), not(feature = "bsc")))]
382388
#[macro_export]
383389
macro_rules! spec_to_generic {
@@ -542,6 +548,11 @@ macro_rules! spec_to_generic {
542548
use $crate::HaberSpec as SPEC;
543549
$e
544550
}
551+
#[cfg(feature = "opbnb")]
552+
$crate::SpecId::WRIGHT => {
553+
use $crate::WrightSpec as SPEC;
554+
$e
555+
}
545556
$crate::SpecId::FJORD => {
546557
use $crate::FjordSpec as SPEC;
547558
$e

crates/revm/src/optimism/handler_register.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use core::ops::Mul;
1717
use revm_precompile::{secp256r1, PrecompileSpecId};
1818
use std::string::ToString;
1919
use std::sync::Arc;
20+
use crate::primitives::WRIGHT;
2021

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

210-
let tx_l1_cost = context
211-
.evm
212-
.inner
213-
.l1_block_info
214-
.as_ref()
215-
.expect("L1BlockInfo should be loaded")
216-
.calculate_tx_l1_cost(enveloped_tx, SPEC::SPEC_ID);
211+
let tx_l1_cost = if context.evm.inner.env.tx.gas_price.is_zero() && SPEC::enabled(WRIGHT) {
212+
U256::ZERO
213+
} else {
214+
context
215+
.evm
216+
.inner
217+
.l1_block_info
218+
.as_ref()
219+
.expect("L1BlockInfo should be loaded")
220+
.calculate_tx_l1_cost(enveloped_tx, SPEC::SPEC_ID)
221+
};
222+
217223
if tx_l1_cost.gt(&caller_account.info.balance) {
218224
return Err(EVMError::Transaction(
219225
InvalidTransaction::LackOfFundForMaxFee {
@@ -255,7 +261,11 @@ pub fn reward_beneficiary<SPEC: Spec, EXT, DB: Database>(
255261
));
256262
};
257263

258-
let l1_cost = l1_block_info.calculate_tx_l1_cost(enveloped_tx, SPEC::SPEC_ID);
264+
let l1_cost = if context.evm.inner.env.tx.gas_price.is_zero() && SPEC::enabled(WRIGHT) {
265+
U256::ZERO
266+
} else {
267+
l1_block_info.calculate_tx_l1_cost(enveloped_tx, SPEC::SPEC_ID)
268+
};
259269

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

0 commit comments

Comments
 (0)