diff --git a/crates/alloy-celo-evm/src/lib.rs b/crates/alloy-celo-evm/src/lib.rs index ce55202f..3031137c 100644 --- a/crates/alloy-celo-evm/src/lib.rs +++ b/crates/alloy-celo-evm/src/lib.rs @@ -184,6 +184,7 @@ where }, fee_currency: None, cip64_tx_info: None, + effective_gas_price: None, }; let mut gas_limit = tx.op_tx.base.gas_limit; diff --git a/crates/celo-revm/src/handler.rs b/crates/celo-revm/src/handler.rs index 585fc091..6fbe52e6 100644 --- a/crates/celo-revm/src/handler.rs +++ b/crates/celo-revm/src/handler.rs @@ -338,6 +338,9 @@ where logs_pre: logs, logs_post: Vec::new(), }); + // Store the effective gas price for the GASPRICE opcode. + // This is calculated using the base fee converted to the fee currency. + tx.effective_gas_price = Some(effective_gas_price); evm.ctx().set_tx(tx); Ok(()) diff --git a/crates/celo-revm/src/transaction/abstraction.rs b/crates/celo-revm/src/transaction/abstraction.rs index e849fbba..2c3f9916 100644 --- a/crates/celo-revm/src/transaction/abstraction.rs +++ b/crates/celo-revm/src/transaction/abstraction.rs @@ -36,6 +36,11 @@ pub struct CeloTransaction { pub op_tx: OpTransaction, pub fee_currency: Option
, pub cip64_tx_info: Option, + /// Pre-computed effective gas price for CIP-64 transactions. + /// This is calculated using the base fee converted to the fee currency. + /// When set, this value is returned by `effective_gas_price()` instead of + /// computing it from the native base fee. + pub effective_gas_price: Option, } impl CeloTransaction { @@ -44,6 +49,7 @@ impl CeloTransaction { op_tx, fee_currency: None, cip64_tx_info: None, + effective_gas_price: None, } } } @@ -54,6 +60,7 @@ impl Default for CeloTransaction { op_tx: OpTransaction::default(), fee_currency: None, cip64_tx_info: None, + effective_gas_price: None, } } } @@ -141,6 +148,12 @@ impl Transaction for CeloTransaction { } fn effective_gas_price(&self, base_fee: u128) -> u128 { + // For CIP-64 transactions, return the pre-computed effective gas price + // that was calculated using the base fee converted to the fee currency. + // This ensures the GASPRICE opcode returns the correct value. + if let Some(egp) = self.effective_gas_price { + return egp; + } self.op_tx.effective_gas_price(base_fee) } @@ -206,6 +219,7 @@ mod tests { }, fee_currency: Some(Address::with_last_byte(1)), cip64_tx_info: None, + effective_gas_price: None, }; // Verify transaction type assert_eq!(cip64_tx.tx_type(), CeloTxType::Cip64 as u8); diff --git a/crates/celo-revm/src/tx.rs b/crates/celo-revm/src/tx.rs index 67496c56..0e6456fb 100644 --- a/crates/celo-revm/src/tx.rs +++ b/crates/celo-revm/src/tx.rs @@ -98,6 +98,7 @@ impl FromTxWithEncoded for CeloTransaction { }, fee_currency, cip64_tx_info: None, + effective_gas_price: None, } } }