Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/alloy-celo-evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions crates/celo-revm/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
14 changes: 14 additions & 0 deletions crates/celo-revm/src/transaction/abstraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub struct CeloTransaction<T: Transaction> {
pub op_tx: OpTransaction<T>,
pub fee_currency: Option<Address>,
pub cip64_tx_info: Option<Cip64Info>,
/// 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<u128>,
}

impl<T: Transaction> CeloTransaction<T> {
Expand All @@ -44,6 +49,7 @@ impl<T: Transaction> CeloTransaction<T> {
op_tx,
fee_currency: None,
cip64_tx_info: None,
effective_gas_price: None,
}
}
}
Expand All @@ -54,6 +60,7 @@ impl Default for CeloTransaction<TxEnv> {
op_tx: OpTransaction::default(),
fee_currency: None,
cip64_tx_info: None,
effective_gas_price: None,
}
}
}
Expand Down Expand Up @@ -141,6 +148,12 @@ impl<T: Transaction> Transaction for CeloTransaction<T> {
}

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)
}

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions crates/celo-revm/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl FromTxWithEncoded<CeloTxEnvelope> for CeloTransaction<TxEnv> {
},
fee_currency,
cip64_tx_info: None,
effective_gas_price: None,
}
}
}
Expand Down