Skip to content

feat: feynman base fee #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: scroll
Choose a base branch
from
Open

feat: feynman base fee #273

wants to merge 11 commits into from

Conversation

greged93
Copy link
Collaborator

@greged93 greged93 commented Jul 4, 2025

Adds the Feynman L2 base fee computation to Reth and introduces it into the transaction pool.

Fixes #234.

Copy link

codspeed-hq bot commented Jul 4, 2025

CodSpeed Performance Report

Merging #273 will not alter performance

Comparing feat/feynman-base-fee (2e7b149) with scroll (aad1706)

Summary

✅ 77 untouched benchmarks

Comment on lines +38 to +39
// TODO: should we get the pool base fee in the case where the transaction is a pending
// transaction here?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the points that I'm not sure about: should the base fee from the transaction pool be fetched and used here?

For context, this type is used in the RpcConverter and builds a RPC transaction from a recovered tx and the scroll transaction info (which contains the L1 fee and the block context info). For now, afaiu, the RpcConverter uses empty block context for pending pool transaction (see here) but from what I understand in l2geth, the pending base fee is used to compute the effective_gas_price for pool transactions.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the original value (tx_info.inner.base_fee) taken from, the latest or pending block?

I don't think it's very important to consider overhead here, and this will just be a transient discrepancy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's taken from here and with thus be None.

@@ -37,7 +37,7 @@ impl ScrollHardfork {
(Self::Euclid, ForkCondition::Timestamp(1744815600)),
(Self::EuclidV2, ForkCondition::Timestamp(1745305200)),
// TODO: update
(Self::Feynman, ForkCondition::Timestamp(u64::MAX)),
(Self::Feynman, ForkCondition::Timestamp(6000000000)),
Copy link
Collaborator Author

@greged93 greged93 Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done in order to be able to add test cases with pre and post Feynman chainspec.

greged93 added 2 commits July 14, 2025 13:25
Signed-off-by: Gregory Edison <[email protected]>
Signed-off-by: Gregory Edison <[email protected]>
@greged93 greged93 requested a review from georgehao July 14, 2025 12:15
use alloy_primitives::{address, b256, Address, B256};

/// The transaction fee recipient on the L2.
pub const SCROLL_FEE_VAULT_ADDRESS: Address = address!("5300000000000000000000000000000000000005");

/// The system contract on L2 mainnet.
pub const SCROLL_MAINNET_SYSTEM_CONTRACT_ADDRESS: Address =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub const SCROLL_MAINNET_SYSTEM_CONTRACT_ADDRESS: Address =
pub const SCROLL_MAINNET_L2_SYSTEM_CONFIG_CONTRACT_ADDRESS: Address =

A bit verbose, but "system contract" made me think of Ethereum's system contracts.

Comment on lines 62 to 64
/// The system contract on devnet.
pub const SCROLL_DEV_SYSTEM_CONTRACT_ADDRESS: Address =
address!("0000000000000000000000000000000000000000");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add this as a predeploy in devnet genesis if needed.

Comment on lines 115 to 116
/// The address of the L2 system contract.
pub l2_system_contract_address: Address,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure that genesis format is consistent with l2geth: https://github.com/scroll-tech/sre-helm-charts/blob/main/config/genesis/genesis.mainnet.json

This should be l2SystemConfigAddress.

I just realized that I erroneously added this to l1Config. We should fix that, but for now it seems safer to maintain consistency with l2geth.

@@ -108,6 +112,8 @@ pub struct ScrollChainConfig {
/// This is an optional field that, when set, specifies where L2 transaction fees
/// will be sent or stored.
pub fee_vault_address: Option<Address>,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to this PR, but how come we only have one l1_message_queue_address? In EuclidV2 we added a new message queue, both should be indexed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We missed this update to the genesis, but we don't ever use the message queue address in Reth, which is way it was missed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rollup-node does not use the genesis config for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm no but indeed it would make sense to have the chain spec in the L1 watcher and read config from there.

@@ -24,6 +26,9 @@ pub static SCROLL_SEPOLIA: LazyLock<Arc<ScrollChainSpec>> = LazyLock::new(|| {
),
genesis,
hardforks: SCROLL_SEPOLIA_HARDFORKS.clone(),
base_fee_params: BaseFeeParamsKind::Variable(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does BaseFeeParamsKind::Variable behave before Feynman?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will return these values, which are also the default values we use (8 for max change denominator and 2 for elasticity multiplier).

);

if chain_spec.is_feynman_active_at_timestamp(ts) {
Ok(feynman_base_fee(chain_spec, parent_header, ts, overhead.saturating_to()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any risk about dropping back to u64 here? I guess no since the result of next_block_base_fee must fit into u64 anyway?

L2geth does not have this limitation, so if we set overhead incorrectly the behavior would diverge. But normally this value should be quite small.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the overhead > u64::MAX, then you would end up with base_fee = MAX_L2_BASE_FEE; at the end right? Since your comment below says we also need to bound the Feynman base fee.

Comment on lines 119 to 121
if base_fee > MAX_L2_BASE_FEE {
base_fee = MAX_L2_BASE_FEE;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Max fee cap also needs to be applied in feynman_base_fee.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -382,14 +394,10 @@ where
builder_config: &ScrollBuilderConfig,
) -> Result<impl BlockBuilder<Primitives = Evm::Primitives> + 'a, PayloadBuilderError> {
// get the base fee for the attributes.
let base_fee: u64 = if self.chain_spec.is_curie_active_at_block(self.parent().number + 1) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this means we don't support building pre-Curie blocks anymore? (Which is fine.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of came around on this yes and decided to just remove support for pre-Curie blocks

let eip_1559_base_fee = if chainspec.is_feynman_active_at_timestamp(parent_header.timestamp()) {
// extract the eip 1559 base fee from parent header by subtracting overhead from it.
let parent_eip_1559_base_fee =
parent_header.base_fee_per_gas().expect("Feynman active").saturating_sub(overhead);
Copy link
Member

@colinlyguo colinlyguo Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the result will be max(0, parent base fee - overhead). But it's OK iiuc since parent base fee will always >= overhead. Or maybe in some blocks right are transition, this will happen, l2geth should also add underflow protection.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a good point, I think there might be an edge case where we increase ovearhead and that leads to underflow or undefined behavior in l2geth.

Signed-off-by: Gregory Edison <[email protected]>
@greged93 greged93 requested a review from Thegaram July 16, 2025 13:46
Copy link
Collaborator

@frisitano frisitano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a couple of comments inline.

Comment on lines +137 to +163
const CURIE_PARAMS_TEST_CASES: [(u64, u64); 8] = [
(0u64, 15680000u64),
(1000000000, 15714000),
(2000000000, 15748000),
(100000000000, 19080000),
(111111111111, 19457777),
(2164000000000, 89256000),
(644149677419355, 10000000000),
(0x1c3c0f442u64, 15937691),
];

const OVERWRITTEN_PARAMS_TEST_CASES: [(u64, u64); 7] = [
(0, 1),
(1000000000, 1),
(2000000000, 1),
(100000000000, 2),
(111111111111, 2),
(2164000000000, 22),
(644149677419355, 6442),
];

const EIP_1559_TEST_CASES: [(u64, u64, u64, u64); 3] = [
(1000000000, 20000000, 10000000, 1000000000), // usage == target
(1000000001, 20000000, 9000000, 987500001), // usage below target
(1000000001, 20000000, 11000000, 1012500001), // usage above target
];

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do these test cases come from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +1211 to +1221
let backfill_height = if let ControlFlow::Unwind { bad_block, target } = &ctrl {
warn!(target: "engine::tree", invalid_block=?bad_block, "Bad block detected in unwind");
// update the `invalid_headers` cache with the new invalid header
self.state.invalid_headers.insert(**bad_block);

// if this was an unwind then the target is the new height
backfill_height = Some(*target);
}
Some(*target)
} else {
// backfill height is the block number that the backfill finished at
ctrl.block_number()
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we making changes to the core reth logic for this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clippy CI was failing, I just added the changes from this PR on Reth in order to have it pass.

Comment on lines 17 to 24
const L1_BASE_FEE_OVERHEAD_SLOT: U256 = U256::from_limbs([101, 0, 0, 0]);

/// The default base fee overhead, in case the L2 system contract isn't deployed or
/// initialized.
pub const DEFAULT_L1_BASE_FEE_OVERHEAD: U256 = U256::from_limbs([15_680_000, 0, 0, 0]);

/// The base fee scalar slot.
const L1_BASE_FEE_SCALAR_SLOT: U256 = U256::from_limbs([102, 0, 0, 0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	L2BaseFeeOverheadSlot = common.BigToHash(big.NewInt(101))
	L2BaseFeeScalarSlot   = common.BigToHash(big.NewInt(102))

The constant name is wrong or the slot number is wrong

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name is wrong

@@ -842,20 +842,20 @@ impl<N: NetworkPrimitives> NetworkManager<N> {
"Session disconnected"
);

let mut reason = None;
if let Some(ref err) = error {
let reason = if let Some(ref err) = error {
Copy link
Member

@georgehao georgehao Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the benefits of this change

Copy link
Collaborator Author

@greged93 greged93 Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none really, it's just to make clippy happy, see here. I think clippy flags this as it is more idiomatic in Rust to use the let var = if let Some(..) = error { ... } else { ... } pattern.

Signed-off-by: Gregory Edison <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Feynman L2 base fee formula
5 participants