Skip to content

Commit ea01b62

Browse files
authored
fix: base fee (#288)
* feat: set dev genesis header base fee Signed-off-by: Gregory Edison <[email protected]> * feat: return early for Curie Signed-off-by: Gregory Edison <[email protected]> * feat: answer comments Signed-off-by: Gregory Edison <[email protected]> --------- Signed-off-by: Gregory Edison <[email protected]>
1 parent 090d795 commit ea01b62

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

crates/scroll/chainspec/res/genesis/dev.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"timestamp": "0x6490fdd2",
44
"extraData": "0x",
55
"gasLimit": "0x1c9c380",
6+
"baseFeePerGas": "0x0",
67
"difficulty": "0x0",
78
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
89
"coinbase": "0x0000000000000000000000000000000000000000",
@@ -83,4 +84,4 @@
8384
"number": "0x0",
8485
"gasUsed": "0x0",
8586
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
86-
}
87+
}

crates/scroll/chainspec/src/dev.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ use scroll_alloy_hardforks::ScrollHardfork;
1818
/// Includes 20 prefunded accounts with `10_000` ETH each derived from mnemonic "test test test test
1919
/// test test test test test test test junk".
2020
pub static SCROLL_DEV: LazyLock<Arc<ScrollChainSpec>> = LazyLock::new(|| {
21+
// In order to have Feynman activated at block 0, we set the `baseFeePerGas` field of the devnet
22+
// genesis to 0.
2123
let genesis = serde_json::from_str(include_str!("../res/genesis/dev.json"))
2224
.expect("Can't deserialize Dev testnet genesis json");
25+
2326
ScrollChainSpec {
2427
inner: ChainSpec {
2528
chain: Chain::dev(),

crates/scroll/chainspec/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ fn make_genesis_header(genesis: &Genesis) -> Header {
281281
timestamp: genesis.timestamp,
282282
mix_hash: genesis.mix_hash,
283283
beneficiary: genesis.coinbase,
284-
base_fee_per_gas: None,
284+
base_fee_per_gas: genesis
285+
.base_fee_per_gas
286+
.map(|b| b.try_into().expect("base fee should fit in u64")),
285287
withdrawals_root: None,
286288
parent_beacon_block_root: None,
287289
blob_gas_used: None,

crates/scroll/evm/src/base_fee.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ where
5757
) -> Result<u64, P::Error> {
5858
let chain_spec = &self.0;
5959

60+
// Return early if Curie isn't active. This branch will be taken by the
61+
// `ScrollPayloadBuilder` when executing `PayloadAttributes` that were derived from the L1
62+
// (during the L1 consolidation phase of the Rollup Node).
63+
if !chain_spec.is_curie_active_at_block(parent_header.number() + 1) {
64+
return Ok(0);
65+
}
66+
6067
// load l2 system config contract into cache.
6168
let system_config_contract_address =
6269
chain_spec.chain_config().l1_config.l2_system_config_address;
@@ -162,6 +169,7 @@ mod tests {
162169
];
163170

164171
const CURIE_TIMESTAMP: u64 = 1719994280;
172+
const CURIE_BLOCK: u64 = 7096836;
165173

166174
#[test]
167175
fn test_should_return_correct_base_fee() -> Result<(), Box<dyn core::error::Error>> {
@@ -172,8 +180,11 @@ mod tests {
172180

173181
// init the provider and parent header.
174182
let base_fee_provider = ScrollBaseFeeProvider::new(SCROLL_MAINNET.clone());
175-
let parent_header =
176-
alloy_consensus::Header { timestamp: CURIE_TIMESTAMP, ..Default::default() };
183+
let parent_header = alloy_consensus::Header {
184+
timestamp: CURIE_TIMESTAMP,
185+
number: CURIE_BLOCK,
186+
..Default::default()
187+
};
177188
let parent_header_ts = parent_header.timestamp();
178189

179190
// helper closure to insert the l1 base fee in state.
@@ -231,8 +242,11 @@ mod tests {
231242
.unwrap()
232243
.as_timestamp()
233244
.expect("Feynman is timestamp based forked.");
234-
let mut parent_header =
235-
alloy_consensus::Header { timestamp: feynman_fork_ts + 1, ..Default::default() };
245+
let mut parent_header = alloy_consensus::Header {
246+
timestamp: feynman_fork_ts + 1,
247+
number: CURIE_BLOCK + 1,
248+
..Default::default()
249+
};
236250
let parent_header_ts = parent_header.timestamp();
237251

238252
// for each test case, update the parent header fields and check the expected value matches.

0 commit comments

Comments
 (0)