Skip to content

Conversation

@ranchalp
Copy link

@ranchalp ranchalp commented Jun 7, 2025

1. Purpose or design rationale of this PR

This PR updates the L1 data fee (aka rollup fee) to use a new formula starting at the Feynman upgrade.

Original formula (post-Curie):

feePerByte = blobScalar * l1BlobBaseFee
l1DataFee(tx) = (commitScalar * l1BaseFee + feePerByte * size(tx)) / 1e9

New formula (post-Feynman):

feePerByte = execScalar * l1BaseFee + blobScalar * l1BlobBaseFee
l1DataFee(tx) = (feePerByte * size(tx) * penalty(tx)) / 1e18

where

compressionRatio(tx) = size(tx) * 1e9 / size(zstd(tx))
penalty(tx) = compressionRatio(tx) >= penaltyThreshold ? 1e9 : penaltyFactor

Note:

  • commitScalar, blobScalar, execScalar, compressionRatio, penaltyThreshold, penaltyFactor, penalty are all scaled by PRECISION (1e9) to avoid losing precision.
  • This implementation includes the compression ratio calculation using zstd compression and the penalty mechanism based on compression efficiency.
  • penalty_threshold and penalty_factor are new parameters stored in L2 state that control the penalty mechanism for poorly compressible transactions.
  • We should also update the commitScalar and blobScalar on the contract during the application of the Feynman upgrade.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • build: Changes that affect the build system or external dependencies (example scopes: yarn, eslint, typescript)
  • ci: Changes to our CI configuration files and scripts (example scopes: vercel, github, cypress)
  • docs: Documentation-only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

Summary by CodeRabbit

  • New Features
    • Enhanced L1 data fee calculation to support the new "Feynman" phase, incorporating transaction data compression and penalty factors.
  • Bug Fixes
    • Improved error handling for compression failures during fee estimation.
  • Refactor
    • Updated fee calculation logic across transaction processing, tracing, simulation, and transaction pool components to include block timestamp for more accurate fee computation.
  • Tests
    • Added comprehensive tests for the new Feynman fee logic, compression ratio estimation, and penalty calculation.
  • Chores
    • Upgraded the data compression library dependency for improved performance and compatibility.

@coderabbitai
Copy link

coderabbitai bot commented Jun 7, 2025

Walkthrough

This change updates the L1 data fee calculation logic to support a new "Feynman" phase, introducing compression ratio and penalty factor considerations. It adds a blockTime parameter to fee-related functions and propagates this change across the codebase. New tests validate the updated fee logic, and the da-codec dependency is bumped to a newer version.

Changes

File(s) Change Summary
rollup/fees/rollup_fee.go Extended L1 data fee calculation for "Feynman" phase, added blockTime parameter, compression ratio logic, penalty factor, and updated function signatures.
rollup/fees/rollup_fee_test.go Added tests for Feynman fee calculation, compression ratio estimation, and penalty calculation.
accounts/abi/bind/backends/simulated.go
internal/ethapi/api.go
les/odr_test.go
light/odr_test.go
Updated calls to EstimateL1DataFeeForMessage to pass blockTime.
eth/tracers/api.go
core/state_prefetcher.go
eth/state_accessor.go
eth/tracers/api_test.go
eth/tracers/internal/tracetest/calltrace_test.go
eth/tracers/tracers_test.go
les/state_accessor.go
rollup/tracing/tracing.go
tests/state_test_util.go
Updated calls to CalculateL1DataFee to include blockTime.
core/state_processor.go Added blockTime parameter to transaction processing pipeline and related function signatures.
core/tx_list.go Added blockTime parameter to txList.Add method and its calls.
core/tx_list_test.go Updated test and benchmark calls to txList.Add with new parameter.
core/tx_pool.go
light/txpool.go
Added currentTime field to TxPool structs, updated logic to track and use current block time in fee calculations and transaction validation.
cmd/evm/internal/t8ntool/execution.go Updated call to CalculateL1DataFee to include blockTime.
go.mod Bumped da-codec dependency version.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant FeeModule
    participant CompressionLib

    Caller->>FeeModule: CalculateL1DataFee(tx, state, config, blockNum, blockTime)
    alt Feynman phase
        FeeModule->>CompressionLib: estimateTxCompressionRatio(tx.data, blockNum, blockTime, config)
        CompressionLib-->>FeeModule: compressionRatio
        FeeModule->>FeeModule: calculatePenalty(compressionRatio, penaltyThreshold, penaltyFactor)
        FeeModule->>FeeModule: calculateEncodedL1DataFeeFeynman(...)
    else Curie/Pre-Curie
        FeeModule->>FeeModule: calculate fee using legacy method
    end
    FeeModule-->>Caller: fee or error
Loading

Possibly related PRs

  • feat(feynman): upgrade gas oracle predeploy #1213: Implements the Feynman hard fork state changes by upgrading the gas oracle predeploy contract and applying the fork at the transition block; related through the Feynman upgrade but focuses on state and contract upgrades rather than fee calculation.

Suggested labels

bump-version

Suggested reviewers

  • Thegaram
  • georgehao

Poem

A hop, a skip, a fee anew,
With Feynman’s phase, we now review—
Compression checked, penalties weighed,
Block time in every call relayed.
The code hops forward, crisp and neat,
With tests and bumps, this change’s complete!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee255a4 and bad7cac.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (1)
  • go.mod (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • go.mod
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Analyze (go)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ranchalp
Copy link
Author

ranchalp commented Jun 7, 2025

We need to decide how and when we will update both blobScalar and commitScalar (now execScalar) and to which values (i.e. the values of verification_scalar and compression_scalar). I would say we start with compression_scalar=1.

For verification_scalar we probably have heuristics that we can reuse from the current analogous component in the scalar and overhead of the l2 base fee. In general though it should be: verification_scalar = verification_l1_gas_cost / avg_bytes_verified where avg_bytes_verified = avg_blobs_verified * 128000

@ranchalp ranchalp requested review from Thegaram and jonastheis June 9, 2025 08:35
@ranchalp ranchalp marked this pull request as ready for review June 9, 2025 08:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (3)
core/blockchain_test.go (1)

3760-3760: Consider updating variable name for consistency.

The variable commitScalar is now retrieved from rcfg.ExecScalarSlot, but the variable name still reflects the old naming convention. For better code readability and consistency with the Feynman upgrade changes, consider renaming the variable to execScalar.

-		commitScalar := statedb.GetState(rcfg.L1GasPriceOracleAddress, rcfg.ExecScalarSlot)
+		execScalar := statedb.GetState(rcfg.L1GasPriceOracleAddress, rcfg.ExecScalarSlot)

This would also require updating the variable references in the subsequent assertions (lines 3775, 3788) to maintain consistency.

consensus/misc/curie.go (1)

21-21: Consider renaming InitialCommitScalar to InitialExecScalar for consistency.

The storage slot has been renamed from CommitScalarSlot to ExecScalarSlot, but the value InitialCommitScalar still uses the old naming convention. For better code clarity and consistency, consider renaming it to InitialExecScalar.

rollup/fees/rollup_fee.go (1)

209-210: Implement the compression ratio calculation.

The compression ratio is currently hardcoded to 1 as a placeholder. According to the PR objectives, this should be replaced with the actual est_compression_ratio(tx) implementation.

Do you want me to help implement the compression ratio estimation function or open a new issue to track this task?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7fbc35d and 90bd9f4.

📒 Files selected for processing (8)
  • consensus/misc/curie.go (1 hunks)
  • core/blockchain_test.go (1 hunks)
  • ethclient/ethclient_test.go (1 hunks)
  • ethclient/gethclient/gethclient_test.go (1 hunks)
  • params/config.go (1 hunks)
  • rollup/fees/rollup_fee.go (5 hunks)
  • rollup/rcfg/config.go (1 hunks)
  • rollup/tracing/tracing.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (7)
ethclient/ethclient_test.go (2)
rollup/rcfg/config.go (1)
  • ExecScalarSlot (35-35)
common/types.go (1)
  • BigToHash (62-62)
consensus/misc/curie.go (2)
rollup/rcfg/config.go (3)
  • L1GasPriceOracleAddress (27-27)
  • ExecScalarSlot (35-35)
  • InitialCommitScalar (39-39)
common/types.go (1)
  • BigToHash (62-62)
rollup/tracing/tracing.go (1)
rollup/rcfg/config.go (1)
  • ExecScalarSlot (35-35)
ethclient/gethclient/gethclient_test.go (2)
rollup/rcfg/config.go (1)
  • ExecScalarSlot (35-35)
common/types.go (1)
  • BigToHash (62-62)
rollup/rcfg/config.go (1)
common/types.go (1)
  • BigToHash (62-62)
core/blockchain_test.go (1)
rollup/rcfg/config.go (2)
  • L1GasPriceOracleAddress (27-27)
  • ExecScalarSlot (35-35)
rollup/fees/rollup_fee.go (1)
rollup/rcfg/config.go (2)
  • ExecScalarSlot (35-35)
  • Precision (28-28)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: check
🔇 Additional comments (8)
ethclient/ethclient_test.go (1)

204-204: LGTM: Consistent storage slot key rename

The change from CommitScalarSlot to ExecScalarSlot aligns with the broader Feynman upgrade refactor while maintaining the same storage value.

rollup/tracing/tracing.go (1)

546-546: LGTM: Storage proof slot updated correctly

The change ensures tracing captures the renamed storage slot while maintaining the same underlying functionality.

params/config.go (1)

991-994: Placeholder implementation needs completion before activation

The IsFeynman method currently returns false unconditionally. Ensure this is properly implemented with actual fork block logic before the Feynman upgrade is activated.

ethclient/gethclient/gethclient_test.go (1)

88-88: LGTM: Consistent storage slot key rename in test

The change from CommitScalarSlot to ExecScalarSlot maintains test consistency with the broader Feynman upgrade refactor.

rollup/fees/rollup_fee.go (4)

54-54: Field rename looks good.

The rename from commitScalar to execScalar is consistent with the broader refactoring across the codebase.


77-88: Fee calculation logic properly handles all fork phases.

The implementation correctly differentiates between pre-Curie, Curie, and Feynman fee calculations, with appropriate parameter updates.


169-169: Storage slot reading updated correctly.

The function now reads from the renamed ExecScalarSlot, maintaining consistency with the contract storage layout changes.


283-287: Good addition of overflow protection.

The check to ensure rollupFee fits into uint64 is important for circuit compatibility and prevents potential issues with large fee values.

Copy link

@Thegaram Thegaram left a comment

Choose a reason for hiding this comment

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

LGTM, let's add some unit tests.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
rollup/fees/rollup_fee.go (2)

81-81: Verify the IsFeynman function implementation.

The code uses config.IsFeynman(blockNumber), but according to the PR objectives, this function needs to be implemented. Please ensure this function is properly defined in the params.ChainConfig type.


279-279: Verify the IsFeynman function implementation.

The code uses config.IsFeynman(blockNumber), but according to the PR objectives, this function needs to be implemented. Please ensure this function is properly defined in the params.ChainConfig type.

🧹 Nitpick comments (3)
rollup/fees/rollup_fee.go (3)

209-210: Implement the compression ratio estimation function.

The compression ratio is currently hardcoded to 1 (scaled by precision) as a placeholder. According to the PR objectives, the est_compression_ratio(tx) function needs to be implemented to properly estimate the compression ratio (≥ 1) for each transaction.

Would you like me to help implement the compression ratio estimation function or open an issue to track this task?


275-275: Consider renaming l1DataFee to rollupFee for consistency.

In EstimateL1DataFeeForMessage, the variable was renamed from l1DataFee to rollupFee to reflect the Feynman terminology. For consistency, consider applying the same rename in CalculateL1DataFee.

Apply this diff to maintain consistency:

-	var l1DataFee *big.Int
+	var rollupFee *big.Int

 	if !config.IsCurie(blockNumber) {
-		l1DataFee = calculateEncodedL1DataFee(raw, gpoState.overhead, gpoState.l1BaseFee, gpoState.scalar)
+		rollupFee = calculateEncodedL1DataFee(raw, gpoState.overhead, gpoState.l1BaseFee, gpoState.scalar)
 	} else if !config.IsFeynman(blockNumber) {
-		l1DataFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar)
+		rollupFee = calculateEncodedL1DataFeeCurie(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar)
 	} else {
-		l1DataFee = calculateEncodedL1DataFeeFeynman(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar)
+		rollupFee = calculateEncodedL1DataFeeFeynman(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar)
 	}

Also update the subsequent uses of this variable in the function.

Also applies to: 277-283


163-172: Track the scalar update requirement for Feynman activation.

According to the PR objectives, the commitScalar and blobScalar values need to be updated on the contract when applying the Feynman upgrade. Currently, the code reads these values from storage slots but doesn't include the update mechanism.

Ensure that:

  1. The scalar update transaction is prepared and tested before Feynman activation
  2. The initial values are set according to the PR discussion (e.g., compression_scalar = 1)
  3. The verification scalar computation follows the proposed heuristics
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49574cb and b221a0c.

📒 Files selected for processing (1)
  • rollup/fees/rollup_fee.go (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
rollup/fees/rollup_fee.go (1)
rollup/rcfg/config.go (1)
  • Precision (28-28)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Analyze (go)
🔇 Additional comments (1)
rollup/fees/rollup_fee.go (1)

198-228: Fee calculation implementation aligns with the Feynman formula.

The implementation correctly follows the formula from the PR objectives:

rollup_fee(tx) = est_compression_ratio(tx) * tx_size * (exec_scalar * l1_base_fee + blob_scalar * l1_blob_base_fee)

The double division by precision (lines 224-225) is correct since both the compression ratio and scalars are scaled by precision.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
rollup/fees/rollup_fee.go (1)

90-92: Still passing commitScalar where Feynman needs execScalar

This was flagged in a previous review and is still unresolved – the Feynman formula requires

execScalar = compression_scalar + commit_scalar + verification_scalar

but the call is made with gpoState.commitScalar only.

Either compute execScalar beforehand or extend gpoState to hold it, then pass the correct value:

- rollupFee = calculateEncodedL1DataFeeFeynman(raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee, gpoState.commitScalar, gpoState.blobScalar)
+ execScalar := new(big.Int).Add(gpoState.commitScalar, gpoState.compressionScalar)
+ execScalar.Add(execScalar, gpoState.verificationScalar)
+ rollupFee = calculateEncodedL1DataFeeFeynman(
+     raw,
+     gpoState.l1BaseFee,
+     gpoState.l1BlobBaseFee,
+     execScalar,
+     gpoState.blobScalar,
+ )
🧹 Nitpick comments (1)
rollup/fees/rollup_fee.go (1)

216-218: Avoid Int64() on big.Int

rcfg.Precision.Int64() is safe today (1 000 000 000 < 2^31), but tight coupling to int64 leaks an implementation detail and would break if Precision grows.

-compressionRatio := big.NewInt(rcfg.Precision.Int64())
+compressionRatio := new(big.Int).Set(rcfg.Precision)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b221a0c and a39317a.

📒 Files selected for processing (1)
  • rollup/fees/rollup_fee.go (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
rollup/fees/rollup_fee.go (1)
rollup/rcfg/config.go (1)
  • Precision (28-28)
🪛 GitHub Check: check
rollup/fees/rollup_fee.go

[failure] 88-88:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman


[failure] 88-88:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman


[failure] 286-286:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman) (typecheck)


[failure] 286-286:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman) (typecheck)

🪛 GitHub Check: build-mock-ccc-geth
rollup/fees/rollup_fee.go

[failure] 88-88:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman


[failure] 286-286:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman

🪛 GitHub Check: test
rollup/fees/rollup_fee.go

[failure] 88-88:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman


[failure] 286-286:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman

🪛 GitHub Actions: CI
rollup/fees/rollup_fee.go

[error] 88-88: Type mismatch error: cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
rollup/fees/rollup_fee.go (1)

3-8: ⚠️ Potential issue

Remove unused import ‒ the file currently fails to compile

"time" is imported but never referenced, triggering the CI error:

"time" imported and not used
-import (
-	"bytes"
-	"math"
-	"math/big"
-	"time"
+import (
+	"bytes"
+	"math"
+	"math/big"
 )
🧰 Tools
🪛 GitHub Check: test

[failure] 7-7:
"time" imported and not used

🪛 GitHub Check: build-mock-ccc-geth

[failure] 7-7:
"time" imported and not used

🪛 GitHub Check: check

[failure] 7-7:
"time" imported and not used


[failure] 7-7:
"time" imported and not used

🪛 GitHub Actions: CI

[error] 7-7: "time" imported and not used

♻️ Duplicate comments (3)
rollup/fees/rollup_fee.go (3)

285-290: ⚠️ Potential issue

Second IsFeynman call still causes a type-mismatch build error

CI reports:

cannot use blockNumber (*big.Int) as uint64 in argument to config.IsFeynman

Either convert or change the helper’s signature, e.g.:

-} else if !config.IsFeynman(blockNumber) {
+} else if !config.IsFeynman(blockNumber.Uint64()) {

Make sure both call-sites use the same parameter type.
Otherwise the package will not build.

🧰 Tools
🪛 GitHub Check: test

[failure] 287-287:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman

🪛 GitHub Check: build-mock-ccc-geth

[failure] 287-287:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman

🪛 GitHub Check: check

[failure] 287-287:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman) (typecheck)


[failure] 287-287:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman) (typecheck)


85-94: ⚠️ Potential issue

execScalar is never passed – Feynman branch still receives commitScalar

Per the PR spec:
exec_scalar = compression_scalar + commit_scalar + verification_scalar

Yet the call forwards gpoState.commitScalar as the execScalar argument, so the
fee is underestimated.

-} else {
-	rollupFee = calculateEncodedL1DataFeeFeynman(
-		raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee,
-		gpoState.commitScalar,               // <- wrong
-		gpoState.blobScalar,
-	)
+} else {
+	// TODO(feat-feynman): add compressionScalar & verificationScalar to GPO storage
+	execScalar := new(big.Int).Set(gpoState.commitScalar) // placeholder until the extra scalars are wired in
+	rollupFee = calculateEncodedL1DataFeeFeynman(
+		raw, gpoState.l1BaseFee, gpoState.l1BlobBaseFee,
+		execScalar,
+		gpoState.blobScalar,
+	)
 }

206-236: 🛠️ Refactor suggestion

Reduce rounding error in the Feynman fee by dividing once

Two successive Div(..., rcfg.Precision) introduce two rounding steps.
Combine them into a single division by precision² to keep precision
identical but with one rounding:

-// Divide by rcfg.Precision (once for ratio, once for scalar)
-l1DataFee.Div(l1DataFee, rcfg.Precision)
-l1DataFee.Div(l1DataFee, rcfg.Precision)
+precisionSq := new(big.Int).Mul(rcfg.Precision, rcfg.Precision)
+l1DataFee.Div(l1DataFee, precisionSq)
🧹 Nitpick comments (1)
rollup/fees/rollup_fee.go (1)

217-220: Explicit TODO for placeholder compression ratio

compressionRatio is hard-coded to 1. Add a clear TODO so it isn’t
forgotten during the rollout.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a39317a and f1348bbfcabdf23a81e0076e79171438bbc6a949.

📒 Files selected for processing (6)
  • accounts/abi/bind/backends/simulated.go (1 hunks)
  • eth/tracers/api.go (1 hunks)
  • internal/ethapi/api.go (2 hunks)
  • les/odr_test.go (2 hunks)
  • light/odr_test.go (1 hunks)
  • rollup/fees/rollup_fee.go (5 hunks)
✅ Files skipped from review due to trivial changes (3)
  • eth/tracers/api.go
  • les/odr_test.go
  • internal/ethapi/api.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
light/odr_test.go (1)
rollup/fees/rollup_fee.go (1)
  • EstimateL1DataFeeForMessage (66-96)
🪛 GitHub Check: test
rollup/fees/rollup_fee.go

[failure] 7-7:
"time" imported and not used


[failure] 287-287:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman

🪛 GitHub Check: build-mock-ccc-geth
rollup/fees/rollup_fee.go

[failure] 7-7:
"time" imported and not used


[failure] 287-287:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman

🪛 GitHub Check: check
rollup/fees/rollup_fee.go

[failure] 7-7:
"time" imported and not used


[failure] 7-7:
"time" imported and not used


[failure] 287-287:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman) (typecheck)


[failure] 287-287:
cannot use blockNumber (variable of type *big.Int) as uint64 value in argument to config.IsFeynman) (typecheck)

🪛 GitHub Actions: CI
rollup/fees/rollup_fee.go

[error] 7-7: "time" imported and not used

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
accounts/abi/bind/backends/simulated.go (1)

640-646: Call update looks good

The additional head.Time argument matches the new
EstimateL1DataFeeForMessage signature. No issues spotted.

light/odr_test.go (1)

200-206: Test updated correctly

The extra header.Time parameter keeps the test compiling with the new
fee-estimation API.

@ranchalp ranchalp force-pushed the l1data-to-rollupfee branch from 8278b6e to d0e730b Compare June 11, 2025 15:59
@ranchalp ranchalp force-pushed the l1data-to-rollupfee branch from d0e730b to ce2498e Compare June 11, 2025 16:00
@ranchalp ranchalp requested a review from Thegaram June 12, 2025 12:49
@colinlyguo colinlyguo changed the base branch from develop to feat-feynman-gas-oracle June 24, 2025 20:16
@colinlyguo colinlyguo force-pushed the l1data-to-rollupfee branch from 65181f4 to 1fbe3ea Compare June 25, 2025 11:04
Base automatically changed from feat-feynman-gas-oracle to develop June 25, 2025 11:22
@Thegaram Thegaram dismissed their stale review June 25, 2025 11:22

The base branch was changed.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 080cbf3 and 8df47a2.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • cmd/evm/internal/t8ntool/execution.go (1 hunks)
  • core/state_processor.go (5 hunks)
  • go.mod (1 hunks)
  • miner/scroll_worker.go (1 hunks)
  • rollup/fees/rollup_fee.go (7 hunks)
  • rollup/fees/rollup_fee_test.go (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • go.mod
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/evm/internal/t8ntool/execution.go
  • core/state_processor.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test
  • GitHub Check: Analyze (go)
🔇 Additional comments (11)
rollup/fees/rollup_fee.go (7)

9-9: LGTM - Required imports for new functionality.

The new imports support the compression functionality (da-codec/encoding) and error logging (log) needed for the Feynman fee calculation.

Also applies to: 14-14


65-66: LGTM - New penalty parameters properly added.

The penaltyThreshold and penaltyFactor fields are correctly added to support the compression-based penalty mechanism in Feynman.


69-69: Function signature updated correctly for time-aware fee calculation.

The addition of blockTime parameter enables the Feynman phase detection and is properly propagated through the call chain.

Also applies to: 81-81


170-204: Well-implemented compression ratio estimation with robust error handling.

The function correctly:

  • Handles edge cases (empty data, compression failures)
  • Uses appropriate logging for error conditions
  • Ensures compression ratio ≥ 1.0 for consistency with DA batch compression
  • Implements the formula: compression_ratio = size(tx) * PRECISION / size(zstd(tx))

206-215: Clean and correct penalty calculation implementation.

The logic correctly implements: penalty = 1.0 if compression ratio ≥ threshold, otherwise apply penalty factor.


241-284: Feynman fee formula implementation is mathematically correct.

The function properly implements the formula:

rollup_fee(tx) = (execScalar * l1BaseFee + blobScalar * l1BlobBaseFee) * size(tx) * penalty(tx) / PRECISION²

The two divisions by rcfg.Precision correctly account for the scalar precision and penalty precision.


319-319: Phase selection logic correctly implemented.

The conditional logic properly selects:

  • Pre-Curie: !config.IsCurie(blockNumber)
  • Curie: !config.IsFeynman(blockTime) (between Curie and Feynman)
  • Feynman: default case

The use of blockNumber for Curie and blockTime for Feynman is consistent with their respective fork activation mechanisms.

Also applies to: 335-352

rollup/fees/rollup_fee_test.go (4)

9-9: LGTM - Import added for chain configuration support.

The params import is correctly added to support chain configuration in compression ratio tests.


37-96: Excellent test coverage for Feynman fee calculation.

The test comprehensively covers:

  • No penalty scenario (compression ratio ≥ threshold)
  • Penalty scenario (compression ratio < threshold)
  • Clear mathematical verification with expected values
  • Both test cases properly validate the fee formula implementation

98-121: Good compression ratio testing with realistic scenarios.

Tests cover:

  • Empty data edge case
  • Compressible data with patterns
  • Proper use of test chain configuration

123-139: Complete penalty calculation test coverage.

Tests validate both penalty conditions:

  • No penalty when ratio ≥ threshold
  • Penalty applied when ratio < threshold

Thegaram
Thegaram previously approved these changes Jun 25, 2025
@Thegaram Thegaram changed the title Change l1DataFee to rollupFee for Feynman feat(feynman): add new compression-aware rollup fee formula Jun 25, 2025
Thegaram
Thegaram previously approved these changes Jun 25, 2025
Copy link

@colinlyguo colinlyguo left a comment

Choose a reason for hiding this comment

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

Let's merge this da-codec PR and update the commit first.

colinlyguo
colinlyguo previously approved these changes Jun 25, 2025
Thegaram
Thegaram previously approved these changes Jun 25, 2025
georgehao
georgehao previously approved these changes Jun 26, 2025
@colinlyguo colinlyguo dismissed stale reviews from georgehao, Thegaram, and themself via bad7cac June 26, 2025 09:25
Copy link

@colinlyguo colinlyguo left a comment

Choose a reason for hiding this comment

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

lgtm.

@colinlyguo colinlyguo merged commit c0d8941 into develop Jun 26, 2025
14 checks passed
@colinlyguo colinlyguo deleted the l1data-to-rollupfee branch June 26, 2025 10:08
@coderabbitai coderabbitai bot mentioned this pull request Nov 4, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants