From 8d33585d6ab97abbc2db2370415751ea8d3f0245 Mon Sep 17 00:00:00 2001 From: Karl Bartel Date: Fri, 28 Nov 2025 15:01:57 +0100 Subject: [PATCH] CIP-64: actual GASPRICE opcode fix The previous fix was not correct and only accidentally made the tests pass. The GASPRICE opcodes fetches the effective gas price and passes in the base fee in native tokens. We work around this by calculating the correct effective gas price in advance and ignoring the passed in base fee. --- crates/alloy-celo-evm/src/lib.rs | 1 + crates/celo-revm/src/handler.rs | 3 +++ crates/celo-revm/src/transaction/abstraction.rs | 14 ++++++++++++++ crates/celo-revm/src/tx.rs | 1 + 4 files changed, 19 insertions(+) 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, } } }