Skip to content

Trace Storage Proof#254

Merged
anylots merged 5 commits intomainfrom
trace_code
Nov 27, 2025
Merged

Trace Storage Proof#254
anylots merged 5 commits intomainfrom
trace_code

Conversation

@Kukoomomo
Copy link
Copy Markdown
Contributor

@Kukoomomo Kukoomomo commented Nov 24, 2025

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Resolved storage trace logging to ensure all state changes are properly captured
    • Improved fee rate token scale validation and retrieval process
  • Improvements

    • Enhanced storage proof collection to accumulate and track token registry state information
    • Refined block trace generation to include additional token registry slots and price ratio data for comprehensive proof coverage

✏️ Tip: You can customize this high-level summary in your review settings.

@Kukoomomo Kukoomomo requested a review from a team as a code owner November 24, 2025 07:29
@Kukoomomo Kukoomomo requested review from panos-xyz and removed request for a team November 24, 2025 07:29
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 24, 2025

Walkthrough

These changes modify storage change recording, token registry proof accumulation, and fee conversion logic. The tracer now unconditionally records storage updates instead of skipping during system calls. Storage proofs for the token registry are collected from logged storage updates and aggregated into a proof map. Fee rate calculation is simplified to use direct scale values.

Changes

Cohort / File(s) Summary
Storage Change Recording
eth/tracers/logger/logger.go
Removed early-return skip check in OnStorageChange; now unconditionally records storage changes regardless of system-call context
Token Registry Storage Proof Collection
rollup/tracing/tracing.go
Added mechanism to accumulate storage proofs for token registry by capturing UpdatedStorages from struct logger; collects TokenInfo slot values (address, balance, isActive/decimals, scale) and price ratio; removes intrinsic slot requirements for L2TokenRegistryAddress in fillBlockTrace; eliminates redundant proofStorages initialization
Fee Rate Validation
rollup/fees/rate.go
Added validation log for token scale when nil or zero; removed GetTokenScaleByIDWithState retrieval; changed return to use info.Scale directly; introduced naming inconsistency with variable tokenSacle

Sequence Diagrams

sequenceDiagram
    participant TxTrace as Transaction<br/>Tracer
    participant Logger as Storage<br/>Logger
    participant Tracing as Tracing<br/>Collection
    participant Registry as Token<br/>Registry Proofs

    TxTrace->>Logger: OnStorageChange (now always records)
    Logger->>Logger: Record UpdatedStorages<br/>(no skip check)
    TxTrace->>Tracing: Finalize transaction trace
    Tracing->>Logger: Read UpdatedStorages
    Logger-->>Tracing: Storage updates
    Tracing->>Registry: Accumulate token registry<br/>slot values into proofStorages
    Registry-->>Tracing: Proof map populated
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • eth/tracers/logger/logger.go: Simple removal of skip logic, but verify all downstream code handles unconditional storage recording
  • rollup/tracing/tracing.go: Complex storage proof collection logic; requires careful review of slot mapping, proof aggregation, and interaction with struct logger—changes to intrinsic slot requirements may affect proof completeness
  • rollup/fees/rate.go: Simple change but introduces a naming inconsistency (tokenSacle typo); verify that removing GetTokenScaleByIDWithState doesn't break dependencies expecting fetched scales

Possibly related PRs

Suggested reviewers

  • FletcherMan
  • twcctop

Poem

🐰 A rabbit hops through storage slots,
Recording changes, forgetting naught,
Token proofs now bloom so bright,
Fees flow smoothly, logic tight,
The registry's secrets, captured just right! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Trace Storage Proof' directly relates to the main change: adding storage proof tracing mechanisms for token registry in rollup/tracing/tracing.go, which is the central focus of this changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch trace_code

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rollup/fees/rate.go (1)

23-37: Add early returns after validation failures.

The validation logic logs errors but continues execution, allowing invalid values (nil or zero scale, zero address, nil or zero rate) to be returned. This will cause incorrect fee calculations or runtime panics in downstream functions like EthToAlt and AltToETH.

Apply this diff to fix the validation logic:

 	if info.Scale == nil || info.Scale.Sign() == 0 {
 		log.Error("Invalid token scale", "tokenID", tokenID, "tokenAddr", info.TokenAddress.Hex())
+		return nil, nil, errors.New("invalid token scale")
 	}
 
 	// If token address is zero, this is not a valid token
 	if info.TokenAddress == (common.Address{}) {
 		log.Error("Invalid token address", "tokenID", tokenID)
-		return nil, nil, err
+		return nil, nil, errors.New("invalid token address")
 	}
 
 	// If price is nil or zero, this token doesn't have a valid price
 	if rate == nil || rate.Sign() == 0 {
 		log.Error("Invalid token price", "tokenID", tokenID, "tokenAddr", info.TokenAddress.Hex())
-		return nil, nil, err
+		return nil, nil, errors.New("invalid token price")
 	}
🧹 Nitpick comments (2)
rollup/fees/rate.go (1)

43-43: Fix variable name typo.

The variable name tokenSacle should be tokenScale for consistency and readability.

Apply this diff:

-	rate, tokenSacle, err := TokenRate(state, tokenID)
+	rate, tokenScale, err := TokenRate(state, tokenID)
 	if err != nil {
 		return nil, err
 	}
-	return types.EthToAlt(amount, rate, tokenSacle), nil
+	return types.EthToAlt(amount, rate, tokenScale), nil
-	rate, tokenSacle, err := TokenRate(state, tokenID)
+	rate, tokenScale, err := TokenRate(state, tokenID)
 	if err != nil {
 		return nil, err
 	}
-	return types.AltToEth(amount, rate, tokenSacle), nil
+	return types.AltToEth(amount, rate, tokenScale), nil

Also applies to: 51-51

rollup/tracing/tracing.go (1)

411-411: Consider reducing log level for production.

These Info-level logs are in the transaction execution hot path and will be emitted for every AltFeeTx transaction. Consider using Debug level or removing them to avoid performance impact and log spam.

Apply this diff:

-			log.Info("base slot", "base slot", baseSlot.String(), "token id", tx.FeeTokenID(), "token address", tokenInfo.TokenAddress.String())
+			log.Debug("collecting token registry proofs", "baseSlot", baseSlot.String(), "tokenID", tx.FeeTokenID(), "tokenAddress", tokenInfo.TokenAddress.String())
-				log.Info("offset slot", "offset", offset, "slot", slot.String())
+				log.Debug("collecting registry slot proof", "offset", offset, "slot", slot.String())

Also applies to: 420-420

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42d3973 and a99f2d5.

📒 Files selected for processing (3)
  • eth/tracers/logger/logger.go (0 hunks)
  • rollup/fees/rate.go (2 hunks)
  • rollup/tracing/tracing.go (3 hunks)
💤 Files with no reviewable changes (1)
  • eth/tracers/logger/logger.go
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-10T06:56:24.937Z
Learnt from: Kukoomomo
Repo: morph-l2/go-ethereum PR: 205
File: core/token_gas.go:140-155
Timestamp: 2025-11-10T06:56:24.937Z
Learning: In the ERC20 fee implementation (core/token_gas.go), ERC20 transfer and balance check calls use math.MaxUint64 gas limit. This is intentional given that fee tokens are restricted to an allowlist (via IsTokenActive checks and AllowListSlot/AllowListEnabledSlot in rollup/rcfg/config.go), so only vetted contracts can be invoked. The team has chosen this approach understanding the tradeoffs versus adding fixed gas stipends.

Applied to files:

  • rollup/tracing/tracing.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (5)
rollup/tracing/tracing.go (4)

371-371: LGTM!

Capturing updated storages from the struct logger is the correct approach for building storage proofs.


405-407: LGTM!

Defensive initialization of the nested map is correct and prevents potential nil map assignment panics.


468-469: LGTM!

Removing the redundant reinitialization of proofStorages is correct. The variable is already populated from structLogger.UpdatedStorages() at line 371 and augmented with token registry slots, so no redeclaration is needed.


410-428: Slot calculation functions are correctly implemented and configured.

All three helper functions (GetTokenInfoStructBaseSlot, CalculateStructFieldSlot, CalculateUint16MappingSlot) exist and correctly calculate Solidity storage slots:

  • CalculateUint16MappingSlot properly implements standard Solidity mapping storage with keccak256 hashing
  • CalculateStructFieldSlot correctly adds field offsets to base slots for struct field access
  • Configuration values are properly set: TokenRegistrySlot=151, PriceRatioSlot=153
  • The registrySlots offsets [0, 1, 2, 3] correctly correspond to TokenInfo struct fields (tokenAddress, balanceSlot, isActive+decimals, scale)
rollup/fees/rate.go (1)

39-39: No issues found—the change is correct.

The verification confirms that info.Scale from GetTokenInfoFromStorage matches the value that GetTokenScaleByIDWithState would return. Both functions derive from the same GetTokenInfo call, guaranteeing the scale values are identical. The change correctly consolidates multiple state lookups into a single function call without altering functionality or return values.

@anylots anylots merged commit 7618ae1 into main Nov 27, 2025
8 checks passed
@anylots anylots deleted the trace_code branch November 27, 2025 17:38
This was referenced Dec 16, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Jan 4, 2026
13 tasks
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.

2 participants