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
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 23 additions & 17 deletions crates/revm/src/optimism/handler_register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,13 @@ pub fn reimburse_caller<SPEC: Spec, EXT, DB: Database>(
context: &mut Context<EXT, DB>,
gas: &Gas,
) -> Result<(), EVMError<DB::Error>> {
mainnet::reimburse_caller::<SPEC, EXT, DB>(context, gas)?;
let is_deposit = context.evm.inner.env.tx.optimism.source_hash.is_some();

if context.evm.inner.env.tx.optimism.source_hash.is_none() {
let caller_account = context
.evm
.inner
.journaled_state
.load_account(context.evm.inner.env.tx.caller, &mut context.evm.inner.db)?;
if !is_deposit {
mainnet::reimburse_caller::<SPEC, EXT, DB>(context, gas)?;
}

if !is_deposit && SPEC::SPEC_ID.is_enabled_in(SpecId::ISTHMUS) {
let operator_fee_refund = context
.evm
.inner
Expand All @@ -295,6 +294,12 @@ pub fn reimburse_caller<SPEC: Spec, EXT, DB: Database>(
.expect("L1BlockInfo should be loaded")
.operator_fee_refund(gas, SPEC::SPEC_ID);

let caller_account = context
.evm
.inner
.journaled_state
.load_account(context.evm.inner.env.tx.caller, &mut context.evm.inner.db)?;

// In additional to the normal transaction fee, additionally refund the caller
// for the operator fee.
caller_account.data.info.balance = caller_account
Expand Down Expand Up @@ -367,10 +372,8 @@ pub fn deduct_caller<SPEC: Spec, EXT, DB: Database>(

// Deduct the operator fee from the caller's account.
let gas_limit = U256::from(context.evm.inner.env.tx.gas_limit);

let operator_fee_charge =
l1_block.operator_fee_charge(enveloped_tx, gas_limit, SPEC::SPEC_ID);

caller_account.info.balance = caller_account
.info
.balance
Expand Down Expand Up @@ -438,15 +441,18 @@ pub fn reward_beneficiary<SPEC: Spec, EXT, DB: Database>(
.basefee
.mul(U256::from(gas.spent() - gas.refunded() as u64));

// Send the operator fee of the transaction to the coinbase.
let mut operator_fee_vault_account = context
.evm
.inner
.journaled_state
.load_account(OPERATOR_FEE_RECIPIENT, &mut context.evm.inner.db)?;
// We can only touch the operator fee vault if the Isthmus spec is enabled.
if SPEC::SPEC_ID.is_enabled_in(SpecId::ISTHMUS) {
// Send the operator fee of the transaction to the coinbase.
let mut operator_fee_vault_account = context
.evm
.inner
.journaled_state
.load_account(OPERATOR_FEE_RECIPIENT, &mut context.evm.inner.db)?;

operator_fee_vault_account.mark_touch();
operator_fee_vault_account.data.info.balance += operator_fee_cost;
operator_fee_vault_account.mark_touch();
operator_fee_vault_account.data.info.balance += operator_fee_cost;
}
}
Ok(())
}
Expand Down
41 changes: 22 additions & 19 deletions crates/revm/src/optimism/l1block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,28 @@ impl L1BlockInfo {
///
/// Introduced in isthmus. Prior to isthmus, the operator fee is always zero.
pub fn operator_fee_charge(&self, input: &[u8], gas_limit: U256, spec_id: SpecId) -> U256 {
// If the input is a deposit transaction or empty, the default value is zero.
if input.is_empty() || input.first() == Some(&0x7F) {
// If the input is a deposit transaction, the default value is zero.
if input.first() == Some(&0x7E) {
return U256::ZERO;
}
if !spec_id.is_enabled_in(SpecId::ISTHMUS) {
return U256::ZERO;
}

self.operator_fee_charge_inner(gas_limit)
}

/// Calculate the operator fee for the given `gas`.
fn operator_fee_charge_inner(&self, gas: U256) -> U256 {
let operator_fee_scalar = self
.operator_fee_scalar
.expect("Missing operator fee scalar for isthmus L1 Block");
let operator_fee_constant = self
.operator_fee_constant
.expect("Missing operator fee constant for isthmus L1 Block");

let product = gas_limit.saturating_mul(operator_fee_scalar)
/ (U256::from(OPERATOR_FEE_SCALAR_DECIMAL));
let product =
gas.saturating_mul(operator_fee_scalar) / (U256::from(OPERATOR_FEE_SCALAR_DECIMAL));

product.saturating_add(operator_fee_constant)
}
Expand All @@ -219,15 +225,12 @@ impl L1BlockInfo {
return U256::ZERO;
}

let operator_fee_scalar = self
.operator_fee_scalar
.expect("Missing operator fee scalar for isthmus L1 Block");

// We're computing the difference between two operator fees, so no need to include the
// constant.
let operator_cost_gas_limit = self.operator_fee_charge_inner(U256::from(gas.limit()));
let operator_cost_gas_used = self.operator_fee_charge_inner(U256::from(
gas.limit() - (gas.remaining() + gas.refunded() as u64),
));

operator_fee_scalar.saturating_mul(U256::from(gas.remaining() + gas.refunded() as u64))
/ (U256::from(OPERATOR_FEE_SCALAR_DECIMAL))
operator_cost_gas_limit.saturating_sub(operator_cost_gas_used)
}

/// Calculate the data gas for posting the transaction on L1. Calldata costs 16 gas per byte
Expand Down Expand Up @@ -288,7 +291,7 @@ impl L1BlockInfo {
return tx_l1_cost;
}
// If the input is a deposit transaction or empty, the default value is zero.
let tx_l1_cost = if input.is_empty() || input.first() == Some(&0x7F) {
let tx_l1_cost = if input.is_empty() || input.first() == Some(&0x7E) {
return U256::ZERO;
} else if spec_id.is_enabled_in(SpecId::FJORD) {
self.calculate_tx_l1_cost_fjord(input)
Expand Down Expand Up @@ -451,8 +454,8 @@ mod tests {
assert_eq!(gas_cost, U256::ZERO);
l1_block_info.clear_tx_l1_cost();

// Deposit transactions with the EIP-2718 type of 0x7F should result in zero
let input = bytes!("7FFACADE");
// Deposit transactions with the EIP-2718 type of 0x7E should result in zero
let input = bytes!("7EFACADE");
let gas_cost = l1_block_info.calculate_tx_l1_cost(&input, SpecId::REGOLITH);
assert_eq!(gas_cost, U256::ZERO);
l1_block_info.clear_tx_l1_cost();
Expand Down Expand Up @@ -483,8 +486,8 @@ mod tests {
assert_eq!(gas_cost, U256::ZERO);
l1_block_info.clear_tx_l1_cost();

// Deposit transactions with the EIP-2718 type of 0x7F should result in zero
let input = bytes!("7FFACADE");
// Deposit transactions with the EIP-2718 type of 0x7E should result in zero
let input = bytes!("7EFACADE");
let gas_cost = l1_block_info.calculate_tx_l1_cost(&input, SpecId::ECOTONE);
assert_eq!(gas_cost, U256::ZERO);
l1_block_info.clear_tx_l1_cost();
Expand Down Expand Up @@ -539,8 +542,8 @@ mod tests {
assert_eq!(gas_cost, U256::ZERO);
l1_block_info.clear_tx_l1_cost();

// Deposit transactions with the EIP-2718 type of 0x7F should result in zero
let input = bytes!("7FFACADE");
// Deposit transactions with the EIP-2718 type of 0x7E should result in zero
let input = bytes!("7EFACADE");
let gas_cost = l1_block_info.calculate_tx_l1_cost(&input, SpecId::FJORD);
assert_eq!(gas_cost, U256::ZERO);
}
Expand Down