Skip to content

Commit 5b151dd

Browse files
authored
add l1_fee field to Receipt (#42)
Signed-off-by: Gregory Edison <[email protected]>
1 parent 1c9ebaf commit 5b151dd

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

crates/evm/execution-types/src/chain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,8 @@ mod tests {
817817
cumulative_gas_used: 46913,
818818
logs: vec![],
819819
success: true,
820+
#[cfg(feature = "scroll")]
821+
l1_fee: alloy_primitives::U256::ZERO,
820822
};
821823

822824
// Create another random receipt object, receipt2
@@ -825,6 +827,8 @@ mod tests {
825827
cumulative_gas_used: 1325345,
826828
logs: vec![],
827829
success: true,
830+
#[cfg(feature = "scroll")]
831+
l1_fee: alloy_primitives::U256::ZERO,
828832
};
829833

830834
// Create a Receipts object with a vector of receipt vectors

crates/evm/execution-types/src/execution_outcome.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ mod tests {
398398
cumulative_gas_used: 46913,
399399
logs: vec![],
400400
success: true,
401+
#[cfg(feature = "scroll")]
402+
l1_fee: U256::ZERO,
401403
})]],
402404
};
403405

@@ -460,6 +462,8 @@ mod tests {
460462
cumulative_gas_used: 46913,
461463
logs: vec![],
462464
success: true,
465+
#[cfg(feature = "scroll")]
466+
l1_fee: U256::ZERO,
463467
})]],
464468
};
465469

@@ -495,6 +499,8 @@ mod tests {
495499
cumulative_gas_used: 46913,
496500
logs: vec![Log::<LogData>::default()],
497501
success: true,
502+
#[cfg(feature = "scroll")]
503+
l1_fee: U256::ZERO,
498504
})]],
499505
};
500506

@@ -527,6 +533,8 @@ mod tests {
527533
cumulative_gas_used: 46913,
528534
logs: vec![Log::<LogData>::default()],
529535
success: true,
536+
#[cfg(feature = "scroll")]
537+
l1_fee: U256::ZERO,
530538
})]],
531539
};
532540

@@ -553,6 +561,8 @@ mod tests {
553561
cumulative_gas_used: 46913,
554562
logs: vec![Log::<LogData>::default()],
555563
success: true,
564+
#[cfg(feature = "scroll")]
565+
l1_fee: U256::ZERO,
556566
})]
557567
);
558568
}
@@ -567,6 +577,8 @@ mod tests {
567577
cumulative_gas_used: 46913,
568578
logs: vec![Log::<LogData>::default()],
569579
success: true,
580+
#[cfg(feature = "scroll")]
581+
l1_fee: U256::ZERO,
570582
})]],
571583
};
572584

@@ -615,6 +627,8 @@ mod tests {
615627
cumulative_gas_used: 46913,
616628
logs: vec![],
617629
success: true,
630+
#[cfg(feature = "scroll")]
631+
l1_fee: U256::ZERO,
618632
};
619633

620634
// Create a Receipts object with a vector of receipt vectors
@@ -664,6 +678,8 @@ mod tests {
664678
cumulative_gas_used: 46913,
665679
logs: vec![],
666680
success: true,
681+
#[cfg(feature = "scroll")]
682+
l1_fee: U256::ZERO,
667683
};
668684

669685
// Create a Receipts object containing the receipt.
@@ -708,6 +724,8 @@ mod tests {
708724
cumulative_gas_used: 46913,
709725
logs: vec![],
710726
success: true,
727+
#[cfg(feature = "scroll")]
728+
l1_fee: U256::ZERO,
711729
};
712730

713731
// Create a Receipts object with a vector of receipt vectors

crates/primitives/src/proofs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ mod tests {
9494
success: true,
9595
cumulative_gas_used: 102068,
9696
logs,
97+
#[cfg(feature = "scroll")]
98+
l1_fee: U256::from(0xffffff),
9799
},
98100
bloom,
99101
};

crates/primitives/src/receipt.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use alloy_consensus::{
77
Eip658Value, TxReceipt,
88
};
99
use alloy_eips::eip2718::Encodable2718;
10+
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
11+
use alloy_primitives::U256;
1012
use alloy_primitives::{Bloom, Log, B256};
1113
use alloy_rlp::{length_of_length, Decodable, Encodable, RlpDecodable, RlpEncodable};
1214
use bytes::{Buf, BufMut};
@@ -50,6 +52,12 @@ pub struct Receipt {
5052
/// ensures this is only set for post-Canyon deposit transactions.
5153
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
5254
pub deposit_receipt_version: Option<u64>,
55+
/// Additional fee to cover l1 data availability costs.
56+
/// L1 fee is not part of the consensus encoding of a receipt.
57+
/// <https://github.com/scroll-tech/go-ethereum/blob/9fff27e4f34fb5097100ed76ee725ce056267f4b/core/types/receipt.go#L96-L102>
58+
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
59+
#[rlp(skip)]
60+
pub l1_fee: U256,
5361
}
5462

5563
impl Receipt {
@@ -247,6 +255,8 @@ impl<'a> arbitrary::Arbitrary<'a> for Receipt {
247255
deposit_nonce,
248256
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
249257
deposit_receipt_version,
258+
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
259+
l1_fee: U256::arbitrary(u)?,
250260
})
251261
}
252262
}
@@ -334,6 +344,8 @@ impl ReceiptWithBloom {
334344
deposit_nonce: None,
335345
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
336346
deposit_receipt_version: None,
347+
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
348+
l1_fee: U256::ZERO,
337349
},
338350
};
339351

@@ -571,10 +583,14 @@ mod tests {
571583

572584
#[test]
573585
fn test_decode_receipt() {
574-
#[cfg(not(feature = "optimism"))]
586+
#[cfg(all(not(feature = "optimism"), not(feature = "scroll")))]
575587
reth_codecs::test_utils::test_decode::<Receipt>(&hex!(
576588
"c428b52ffd23fc42696156b10200f034792b6a94c3850215c2fef7aea361a0c31b79d9a32652eefc0d4e2e730036061cff7344b6fc6132b50cda0ed810a991ae58ef013150c12b2522533cb3b3a8b19b7786a8b5ff1d3cdc84225e22b02def168c8858df"
577589
));
590+
#[cfg(feature = "scroll")]
591+
reth_codecs::test_utils::test_decode::<Receipt>(&hex!(
592+
"c42128b52ffd23fc42696159c90200f034792b6a94c3850215c2fef7aea361a0c31b79d9a32652eefc0d4e2e730036061cff7344b6fc6132b50cda0ed810a991ae58ef013150c12b2522533cb3b3a8b19b7786a8b5ff1d3cdc84225e22b02def168c8858dfffffff"
593+
));
578594
#[cfg(feature = "optimism")]
579595
reth_codecs::test_utils::test_decode::<Receipt>(&hex!(
580596
"c30328b52ffd23fc426961a00105007eb0042307705a97e503562eacf2b95060cce9de6de68386b6c155b73a9650021a49e2f8baad17f30faff5899d785c4c0873e45bc268bcf07560106424570d11f9a59e8f3db1efa4ceec680123712275f10d92c3411e1caaa11c7c5d591bc11487168e09934a9986848136da1b583babf3a7188e3aed007a1520f1cf4c1ca7d3482c6c28d37c298613c70a76940008816c4c95644579fd08471dc34732fd0f24"
@@ -604,6 +620,8 @@ mod tests {
604620
deposit_nonce: None,
605621
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
606622
deposit_receipt_version: None,
623+
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
624+
l1_fee: U256::ZERO,
607625
},
608626
bloom: [0; 256].into(),
609627
};
@@ -638,6 +656,8 @@ mod tests {
638656
deposit_nonce: None,
639657
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
640658
deposit_receipt_version: None,
659+
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
660+
l1_fee: U256::ZERO,
641661
},
642662
bloom: [0; 256].into(),
643663
};
@@ -720,6 +740,8 @@ mod tests {
720740
deposit_nonce: None,
721741
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
722742
deposit_receipt_version: None,
743+
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
744+
l1_fee: U256::from(0xffffff),
723745
};
724746

725747
let mut data = vec![];
@@ -740,6 +762,8 @@ mod tests {
740762
deposit_nonce: None,
741763
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
742764
deposit_receipt_version: None,
765+
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
766+
l1_fee: U256::from(0xffffff),
743767
},
744768
bloom: Bloom::default(),
745769
};
@@ -762,6 +786,8 @@ mod tests {
762786
deposit_nonce: None,
763787
#[cfg(all(feature = "optimism", not(feature = "scroll")))]
764788
deposit_receipt_version: None,
789+
#[cfg(all(feature = "scroll", not(feature = "optimism")))]
790+
l1_fee: U256::from(0xffffff),
765791
},
766792
bloom: Bloom::default(),
767793
};

crates/storage/db-api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ arbitrary = [
8282
"alloy-consensus/arbitrary",
8383
]
8484
optimism = ["reth-primitives/optimism", "reth-codecs/optimism"]
85+
scroll = ["reth-primitives/scroll"]

crates/storage/db-api/src/models/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,10 @@ mod tests {
335335
assert_eq!(PruneCheckpoint::bitflag_encoded_bytes(), 1);
336336
assert_eq!(PruneMode::bitflag_encoded_bytes(), 1);
337337
assert_eq!(PruneSegment::bitflag_encoded_bytes(), 1);
338+
#[cfg(not(feature = "scroll"))]
338339
assert_eq!(Receipt::bitflag_encoded_bytes(), 1);
340+
#[cfg(feature = "scroll")]
341+
assert_eq!(Receipt::bitflag_encoded_bytes(), 2);
339342
assert_eq!(StageCheckpoint::bitflag_encoded_bytes(), 1);
340343
assert_eq!(StageUnitCheckpoint::bitflag_encoded_bytes(), 1);
341344
assert_eq!(StoredBlockBodyIndices::bitflag_encoded_bytes(), 1);
@@ -356,7 +359,10 @@ mod tests {
356359
validate_bitflag_backwards_compat!(PruneCheckpoint, UnusedBits::NotZero);
357360
validate_bitflag_backwards_compat!(PruneMode, UnusedBits::Zero);
358361
validate_bitflag_backwards_compat!(PruneSegment, UnusedBits::Zero);
362+
#[cfg(not(feature = "scroll"))]
359363
validate_bitflag_backwards_compat!(Receipt, UnusedBits::Zero);
364+
#[cfg(feature = "scroll")]
365+
validate_bitflag_backwards_compat!(Receipt, UnusedBits::NotZero);
360366
validate_bitflag_backwards_compat!(StageCheckpoint, UnusedBits::NotZero);
361367
validate_bitflag_backwards_compat!(StageUnitCheckpoint, UnusedBits::Zero);
362368
validate_bitflag_backwards_compat!(StoredBlockBodyIndices, UnusedBits::Zero);

0 commit comments

Comments
 (0)