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
50 changes: 50 additions & 0 deletions bin/morph-statetest/tests/celadon_alt_token_refund.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Golden roots from morph-geth 5a0d0d771 (go-ethereum#371), which reads them back
//! from this same fixture.
//!
//! The fee token is registered with `priceRatio = 3` against `scale = 1`, so
//! converting ETH to token units is inexact. Each fork runs three calldata
//! lengths against three consecutive gas limits:
//!
//! - one, two and three non-zero calldata bytes cost 21_016, 21_032 and 21_048
//! gas, which covers every remainder of the *net* fee modulo the price ratio;
//! - the gas limits 100_001..=100_003 cover every remainder of the *prepaid* fee.
//!
//! Tokens collected, per gas limit:
//!
//! | net gas | Emerald, Jade | Celadon | floor without the credit |
//! |---------|---------------------|---------------------|--------------------------|
//! | 21_016 | 7_005, 7_005, 7_006 | 7_006, 7_006, 7_006 | 7_006, 7_006, 7_006 |
//! | 21_032 | 7_011, 7_010, 7_011 | 7_011, 7_011, 7_011 | 7_011, 7_011, 7_012 |
//! | 21_048 | 7_016, 7_016, 7_016 | 7_016, 7_016, 7_016 | 7_017, 7_016, 7_017 |
//!
//! Celadon collects `ceil(net / 3)` on every gas limit, so it ends on one state
//! root per calldata length. Emerald and Jade round the prepaid fee and the refund
//! up independently and come out a token unit short on three of the nine, so the
//! first two rows end on two roots each.
//!
//! The last column is why one calldata length is not enough. With a net fee of
//! 21_016 the prepaid rounding credit never carries into the refund, so a client
//! that rounds the refund down but drops the credit still lands on every root of
//! that row. The other two rows are the ones that pin the credit itself.
//!
//! The gas figures also pin the transaction's gas: morph does not apply the
//! EIP-7623 calldata floor, which would bill 21_040 for the first row and miss
//! every root here.
use morph_statetest::runner::run_suite_str;

#[test]
fn celadon_alt_token_refund_matches_geth() {
let outcomes = run_suite_str(include_str!("fixtures/celadon_alt_token_refund.json")).unwrap();
assert_eq!(
outcomes.len(),
27,
"3 forks × 3 calldata lengths × 3 gas limits"
);
for outcome in outcomes {
assert!(
outcome.pass,
"{} / {}: {}",
outcome.test, outcome.fork, outcome.error_msg
);
}
}
321 changes: 321 additions & 0 deletions bin/morph-statetest/tests/fixtures/celadon_alt_token_refund.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,321 @@
{
"celadon_alt_token_refund_rounding": {
"env": {
"currentCoinbase": "0x530000000000000000000000000000000000000a",
"currentDifficulty": "0x0",
"currentGasLimit": "0x1c9c380",
"currentNumber": "0x1",
"currentTimestamp": "0x1",
"currentBaseFee": "0x1",
"currentChainID": "0x1"
},
"pre": {
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0x0",
"nonce": "0x0",
"code": "0x",
"storage": {}
},
"0x3000000000000000000000000000000000000003": {
"balance": "0x0",
"nonce": "0x0",
"code": "0x366044146013576004355460005260206000f35b60243580335403335560043580548201905550600160005260206000f3",
"storage": {
"0x9734b052146069605dcf2a05300c1dd5cd5852a2844e5491b2eb25d6daa909bc": "0x00000000000000000000000000000000000000000000000000000000000f4240"
}
},
"0x4200000000000000000000000000000000000042": {
"balance": "0x0",
"nonce": "0x0",
"code": "0x",
"storage": {}
},
"0x5300000000000000000000000000000000000021": {
"balance": "0x0",
"nonce": "0x0",
"code": "0x",
"storage": {
"0x53bdca72fa8d2e145a1b3bd11cde5bd75428acd18eac3d6adf4e06e7e637706d": "0x0000000000000000000000003000000000000000000000000000000000000003",
"0x53bdca72fa8d2e145a1b3bd11cde5bd75428acd18eac3d6adf4e06e7e637706e": "0x0000000000000000000000000000000000000000000000000000000000000002",
"0x53bdca72fa8d2e145a1b3bd11cde5bd75428acd18eac3d6adf4e06e7e637706f": "0x0000000000000000000000000000000000000000000000000000000000001201",
"0x53bdca72fa8d2e145a1b3bd11cde5bd75428acd18eac3d6adf4e06e7e6377070": "0x0000000000000000000000000000000000000000000000000000000000000001",
"0xbb86fbc034f4e382929974bcd8419ed626b0ea647f962d89ba2fb6bd28785ab9": "0x0000000000000000000000000000000000000000000000000000000000000003"
}
}
},
"transaction": {
"type": "0x7f",
"version": "0x0",
"feeTokenID": "0x1",
"feeLimit": "0x0",
"nonce": "0x0",
"gasPrice": "0x1",
"gasLimit": [
"0x186a1",
"0x186a2",
"0x186a3"
],
"to": "0x4200000000000000000000000000000000000042",
"value": [
"0x0"
],
"data": [
"0x01",
"0x0101",
"0x010101"
],
"secretKey": "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
},
"post": {
"Emerald": [
{
"indexes": {
"data": 0,
"gas": 0,
"value": 0
},
"hash": "0xdfaedbf51f7737495c2597c811b6127d75727bc8e359c7b6261dd5ff6519a14d",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 0,
"gas": 1,
"value": 0
},
"hash": "0xdfaedbf51f7737495c2597c811b6127d75727bc8e359c7b6261dd5ff6519a14d",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 0,
"gas": 2,
"value": 0
},
"hash": "0x29e5e2daaf49bd925026bc3834581a8062ef52ba8faf28bae579ca9b0bc5b43f",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 1,
"gas": 0,
"value": 0
},
"hash": "0x1643801e0afc66f0ba3a58f2b40b3251dce6286128b32e3dea600e0a94dc5150",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 1,
"gas": 1,
"value": 0
},
"hash": "0x8b7ea1313b3109e09cae63d493df2f9a405cad607147f72abcde55d84dee1b5b",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 1,
"gas": 2,
"value": 0
},
"hash": "0x1643801e0afc66f0ba3a58f2b40b3251dce6286128b32e3dea600e0a94dc5150",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 2,
"gas": 0,
"value": 0
},
"hash": "0xd0320d67596f1f8a013ab8ed47c1e87a66e707ad72accc3957f33438c4ee8bd6",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 2,
"gas": 1,
"value": 0
},
"hash": "0xd0320d67596f1f8a013ab8ed47c1e87a66e707ad72accc3957f33438c4ee8bd6",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 2,
"gas": 2,
"value": 0
},
"hash": "0xd0320d67596f1f8a013ab8ed47c1e87a66e707ad72accc3957f33438c4ee8bd6",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
}
],
"Jade": [
{
"indexes": {
"data": 0,
"gas": 0,
"value": 0
},
"hash": "0xdfaedbf51f7737495c2597c811b6127d75727bc8e359c7b6261dd5ff6519a14d",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 0,
"gas": 1,
"value": 0
},
"hash": "0xdfaedbf51f7737495c2597c811b6127d75727bc8e359c7b6261dd5ff6519a14d",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 0,
"gas": 2,
"value": 0
},
"hash": "0x29e5e2daaf49bd925026bc3834581a8062ef52ba8faf28bae579ca9b0bc5b43f",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 1,
"gas": 0,
"value": 0
},
"hash": "0x1643801e0afc66f0ba3a58f2b40b3251dce6286128b32e3dea600e0a94dc5150",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 1,
"gas": 1,
"value": 0
},
"hash": "0x8b7ea1313b3109e09cae63d493df2f9a405cad607147f72abcde55d84dee1b5b",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 1,
"gas": 2,
"value": 0
},
"hash": "0x1643801e0afc66f0ba3a58f2b40b3251dce6286128b32e3dea600e0a94dc5150",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 2,
"gas": 0,
"value": 0
},
"hash": "0xd0320d67596f1f8a013ab8ed47c1e87a66e707ad72accc3957f33438c4ee8bd6",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 2,
"gas": 1,
"value": 0
},
"hash": "0xd0320d67596f1f8a013ab8ed47c1e87a66e707ad72accc3957f33438c4ee8bd6",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 2,
"gas": 2,
"value": 0
},
"hash": "0xd0320d67596f1f8a013ab8ed47c1e87a66e707ad72accc3957f33438c4ee8bd6",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
}
],
"Celadon": [
{
"indexes": {
"data": 0,
"gas": 0,
"value": 0
},
"hash": "0x29e5e2daaf49bd925026bc3834581a8062ef52ba8faf28bae579ca9b0bc5b43f",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 0,
"gas": 1,
"value": 0
},
"hash": "0x29e5e2daaf49bd925026bc3834581a8062ef52ba8faf28bae579ca9b0bc5b43f",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 0,
"gas": 2,
"value": 0
},
"hash": "0x29e5e2daaf49bd925026bc3834581a8062ef52ba8faf28bae579ca9b0bc5b43f",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 1,
"gas": 0,
"value": 0
},
"hash": "0x1643801e0afc66f0ba3a58f2b40b3251dce6286128b32e3dea600e0a94dc5150",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 1,
"gas": 1,
"value": 0
},
"hash": "0x1643801e0afc66f0ba3a58f2b40b3251dce6286128b32e3dea600e0a94dc5150",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 1,
"gas": 2,
"value": 0
},
"hash": "0x1643801e0afc66f0ba3a58f2b40b3251dce6286128b32e3dea600e0a94dc5150",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 2,
"gas": 0,
"value": 0
},
"hash": "0xd0320d67596f1f8a013ab8ed47c1e87a66e707ad72accc3957f33438c4ee8bd6",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 2,
"gas": 1,
"value": 0
},
"hash": "0xd0320d67596f1f8a013ab8ed47c1e87a66e707ad72accc3957f33438c4ee8bd6",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
"indexes": {
"data": 2,
"gas": 2,
"value": 0
},
"hash": "0xd0320d67596f1f8a013ab8ed47c1e87a66e707ad72accc3957f33438c4ee8bd6",
"logs": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
}
]
}
}
}
8 changes: 8 additions & 0 deletions crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ pub struct MorphEvm<DB: Database, I> {
/// Ensures consistent price_ratio/scale between deduct and reimburse,
/// matching go-ethereum's `st.feeRate`/`st.tokenScale` caching pattern.
pub(crate) cached_token_fee_info: Option<TokenFeeInfo>,
/// Token-unit numerator the fee deduction overcharged by rounding up.
///
/// From Celadon on, the unused-gas refund adds this back before rounding
/// down, so the caller pays `ceil` of the net fee instead of
/// `ceil(prepaid) - ceil(refund)`, which under-collects. Mirrors
/// go-ethereum's `st.altFeeRoundingCredit`.
pub(crate) cached_alt_fee_rounding_credit: U256,
/// Cached L1 data fee calculated during handler validation.
/// Avoids re-encoding the full transaction RLP in the block executor's
/// receipt-building path (the handler already has the encoded bytes via
Expand Down Expand Up @@ -183,6 +190,7 @@ impl<DB: Database, I> MorphEvm<DB, I> {
Self {
inner,
cached_token_fee_info: None,
cached_alt_fee_rounding_credit: U256::ZERO,
cached_l1_data_fee: U256::ZERO,
pre_fee_refund: 0,
pre_fee_logs: Vec::new(),
Expand Down
Loading
Loading