Skip to content

Commit

Permalink
Add test showing bug in calculation of l1 gas used for ecotone tx
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Sep 4, 2024
1 parent fa5650e commit 8e76e01
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions crates/revm/src/optimism/l1block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,50 @@ mod tests {
assert_eq!(gas_cost, U256::from(1048));
}

#[test]
fn calculate_tx_l1_cost_ecotone() {
// rig

// l1 block info for OP mainnet ecotone block 118024092
// 1710374401 (ecotone timestamp)
// 1711603765 (block 118024092 timestamp)
// 1720627201 (fjord timestamp)
// <https://optimistic.etherscan.io/block/118024092>
// decoded from
let l1_block_info = L1BlockInfo {
l1_base_fee: U256::from_be_bytes(hex!(
"0000000000000000000000000000000000000000000000000000000af39ac327"
)), // 47036678951
l1_base_fee_scalar: U256::from(1368),
l1_blob_base_fee: Some(U256::from_be_bytes(hex!(
"0000000000000000000000000000000000000000000000000000000d5ea528d2"
))), // 57422457042
l1_blob_base_fee_scalar: Some(U256::from(810949)),
..Default::default()
};

// second tx in OP mainnet ecotone block 118024092
// <https://optimistic.etherscan.io/tx/0xa75ef696bf67439b4d5b61da85de9f3ceaa2e145abe982212101b244b63749c2>
const TX: &[u8] = &hex!("02f904940a8303fba78401d6d2798401db2b6d830493e0943e6f4f7866654c18f536170780344aa8772950b680b904246a761202000000000000000000000000087000a300de7200382b55d40045000000e5d60e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000022482ad56cb0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000120000000000000000000000000dc6ff44d5d932cbd77b52e5612ba0529dc6226f1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b300000000000000000000000021c4928109acb0659a88ae5329b5374a3024694c0000000000000000000000000000000000000000000000049b9ca9a6943400000000000000000000000000000000000000000000000000000000000000000000000000000000000021c4928109acb0659a88ae5329b5374a3024694c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000024b6b55f250000000000000000000000000000000000000000000000049b9ca9a694340000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000415ec214a3950bea839a7e6fbb0ba1540ac2076acd50820e2d5ef83d0902cdffb24a47aff7de5190290769c4f0a9c6fabf63012986a0d590b1b571547a8c7050ea1b00000000000000000000000000000000000000000000000000000000000000c080a06db770e6e25a617fe9652f0958bd9bd6e49281a53036906386ed39ec48eadf63a07f47cf51a4a40b4494cf26efc686709a9b03939e20ee27e59682f5faa536667e");

// l1 gas used for tx and l1 fee for tx, from OP mainnet block scanner
// <https://optimistic.etherscan.io/tx/0xa75ef696bf67439b4d5b61da85de9f3ceaa2e145abe982212101b244b63749c2>
let expected_l1_gas_used = U256::from(2456);
let expected_l1_fee = U256::from_be_bytes(hex!(
"000000000000000000000000000000000000000000000000000006a510bd7431" // 7306020222001 wei
));

// test

let gas_used = l1_block_info.data_gas(TX, SpecId::ECOTONE);

assert_eq!(gas_used, expected_l1_gas_used);

let l1_fee = l1_block_info.calculate_tx_l1_cost_ecotone(TX, SpecId::ECOTONE);

assert_eq!(l1_fee, expected_l1_fee)
}

#[test]
fn test_calculate_tx_l1_cost_fjord() {
// l1FeeScaled = baseFeeScalar*l1BaseFee*16 + blobFeeScalar*l1BlobBaseFee
Expand Down

0 comments on commit 8e76e01

Please sign in to comment.