Skip to content

Conversation

@m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jul 15, 2025

Closes: #845

Description

Due to the Geth changes for Pectra, a chain ID of 0 is no longer valid. And for such legacy transactions, the HomesteadSigner has to be used instead. See https://github.com/ethereum/go-ethereum/blob/v1.16.1/core/types/transaction_signing.go#L379-L382 for more info.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Enhanced transaction handling to consistently use the internal chain ID for all transaction types.
    • Added a method to retrieve the chain ID from transaction objects.
  • Bug Fixes

    • Improved sender address derivation for Ethereum transactions, ensuring correct signer selection based on chain ID.
  • Tests

    • Updated and expanded multicall3 contract tests for more comprehensive deployment and interaction validation.
    • Replaced multicall3 contract bytecode fixture with a new version.
    • Adjusted transaction filter tests to remove unnecessary chainId checks.

@m-Peter m-Peter self-assigned this Jul 15, 2025
@m-Peter m-Peter added the Bugfix label Jul 15, 2025
@m-Peter m-Peter requested a review from zhangchiqing as a code owner July 15, 2025 10:39
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

Walkthrough

The changes update how chain IDs are handled for Ethereum transactions, ensuring the correct signer is used for legacy (non-replay protected) transactions without a chain ID. The Transaction interface is extended, sender derivation is centralized, and tests are updated to reflect the new logic. Bytecode fixtures are also replaced.

Changes

File(s) Change Summary
eth/types/types.go Refactored NewTransaction to set ChainID from the transaction's own method, handling legacy/EIP-155 logic.
models/transaction.go Added ChainId() to Transaction interface and implementations; centralized sender derivation in DeriveTxSender.
services/requester/batch_tx_pool.go
services/requester/requester.go
Updated sender derivation to use models.DeriveTxSender; simplified error handling.
tests/fixtures/multicall3.byte Replaced entire bytecode fixture with new contract bytecode.
tests/web3js/eth_filter_endpoints_test.js Removed chainId field from expected transaction object in filter test.
tests/web3js/eth_multicall3_contract_test.js Expanded and renamed multicall3 contract test, added deployment via raw transaction, and updated assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant JSON-RPC Handler
    participant Transaction
    participant DeriveTxSender

    Client->>JSON-RPC Handler: Submit transaction (may lack chainId)
    JSON-RPC Handler->>Transaction: Parse transaction
    JSON-RPC Handler->>DeriveTxSender: Derive sender address
    alt chainId is non-zero
        DeriveTxSender->>Transaction: Use LatestSignerForChainID
    else chainId is zero (legacy)
        DeriveTxSender->>Transaction: Use HomesteadSigner
    end
    DeriveTxSender-->>JSON-RPC Handler: Return sender address
    JSON-RPC Handler-->>Client: Respond with result or error
Loading

Assessment against linked issues

Objective Addressed Explanation
Correctly handle legacy transactions without chainId using HomesteadSigner (#845)
Prevent JSON-RPC endpoint crashes on non-replay protected transactions (#845)
Ensure chainId is not incorrectly set for legacy transactions (#845)

Assessment against linked issues: Out-of-scope changes

Code Change (file_path) Explanation
Replaced entire bytecode fixture (tests/fixtures/multicall3.byte) The bytecode replacement is not directly related to chainId or signer logic; possibly test maintenance, but not specified in #845.
Expanded multicall3 contract test (tests/web3js/eth_multicall3_contract_test.js) The expanded test includes more deployment and interaction logic than strictly required for #845.

Suggested labels

EVM, Compatibility

Suggested reviewers

  • peterargue
  • zhangchiqing
  • janezpodhostnik

Poem

A rabbit hopped through EVM’s maze,
Fixing chain IDs in subtle ways.
Now legacy sends don’t cause a fright—
HomesteadSigner makes it right!
With fixtures new and tests anew,
The blockchain’s path is clear and true.
🐇✨


📜 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 a9fbe65 and 00aaa70.

📒 Files selected for processing (7)
  • eth/types/types.go (3 hunks)
  • models/transaction.go (4 hunks)
  • services/requester/batch_tx_pool.go (1 hunks)
  • services/requester/requester.go (1 hunks)
  • tests/fixtures/multicall3.byte (1 hunks)
  • tests/web3js/eth_filter_endpoints_test.js (0 hunks)
  • tests/web3js/eth_multicall3_contract_test.js (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/web3js/eth_filter_endpoints_test.js
🚧 Files skipped from review as they are similar to previous changes (5)
  • services/requester/requester.go
  • services/requester/batch_tx_pool.go
  • tests/fixtures/multicall3.byte
  • eth/types/types.go
  • models/transaction.go
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: peterargue
PR: onflow/flow-evm-gateway#772
File: services/requester/keystore/key_store.go:50-62
Timestamp: 2025-03-07T01:35:09.751Z
Learning: In the flow-evm-gateway codebase, panics are acceptable in scenarios where immediate detection of critical bugs is desired during development and testing, particularly for invariant violations that should never occur in a correctly functioning system (e.g., when a key is available but locked in the keystore implementation).
⏰ 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: Test
🔇 Additional comments (6)
tests/web3js/eth_multicall3_contract_test.js (6)

1-2: Well-structured imports and constant definition.

Good addition of the required imports and the MULTICALL3_DEPLOYER constant with clear documentation. This addresses the previous review comment about clarifying the hardcoded address.

Also applies to: 8-9


11-11: Typo fixed correctly.

The test name typo has been corrected from "mutlicall3" to "multicall3".


21-30: Proper funding setup for the deployer address.

The funding logic correctly transfers ETH to the deployer address that will be used for the multicall3 deployment. The transaction parameters and assertion are appropriate.


31-41: Well-documented raw transaction deployment.

The deployment section properly documents the fixture requirements and includes error handling with the transaction hash assertion. This addresses the previous review comment about documenting fixture requirements.


55-62: Correct validation of legacy transaction properties.

The assertions correctly validate that chainId is undefined for both the transaction and block transaction details. This aligns perfectly with the PR objectives about handling non-replay protected EVM transactions where legacy transactions don't have a chain ID.


63-107: Comprehensive multicall3 interaction test.

The multicall3 contract interaction test is well-structured with proper ABI loading, method encoding, and result validation. The test covers the full flow from deployment to interaction, providing good coverage for the multicall3 functionality.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

Copy link
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: 3

🧹 Nitpick comments (1)
eth/types/types.go (1)

398-420: Consider consolidating redundant ChainID assignments.

The ChainID is being set multiple times in different conditional blocks (lines 398, 407, 413, 420). Since all non-legacy transaction types require a chain ID, consider setting it once after the legacy transaction handling.

 	if tx.Type() > types.LegacyTxType {
 		al := tx.AccessList()
 		yparity := hexutil.Uint64(v.Sign())
 		result.Accesses = &al
 		result.YParity = &yparity
-		result.ChainID = (*hexutil.Big)(tx.ChainId())
 	}
 
 	if tx.Type() > types.AccessListTxType {
 		result.GasFeeCap = (*hexutil.Big)(tx.GasFeeCap())
 		result.GasTipCap = (*hexutil.Big)(tx.GasTipCap())
 		// Since BaseFee is `0`, this is the max gas price
 		// the sender is willing to pay.
 		result.GasPrice = (*hexutil.Big)(tx.GasFeeCap())
-		result.ChainID = (*hexutil.Big)(tx.ChainId())
 	}
 
 	if tx.Type() > types.DynamicFeeTxType {
 		result.MaxFeePerBlobGas = (*hexutil.Big)(tx.BlobGasFeeCap())
 		result.BlobVersionedHashes = tx.BlobHashes()
-		result.ChainID = (*hexutil.Big)(tx.ChainId())
 	}
 
 	// The `AuthorizationList` field became available with the introduction
 	// of https://eip7702.io/#specification, under the `SetCodeTxType`
 	if tx.Type() > types.BlobTxType {
 		result.AuthorizationList = tx.SetCodeAuthorizations()
-		result.ChainID = (*hexutil.Big)(tx.ChainId())
 	}
+
+	// Set ChainID for all non-legacy transaction types
+	if tx.Type() > types.LegacyTxType {
+		result.ChainID = (*hexutil.Big)(tx.ChainId())
+	}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fc9e0e6 and a9fbe65.

📒 Files selected for processing (7)
  • eth/types/types.go (3 hunks)
  • models/transaction.go (4 hunks)
  • services/requester/batch_tx_pool.go (1 hunks)
  • services/requester/requester.go (1 hunks)
  • tests/fixtures/multicall3.byte (1 hunks)
  • tests/web3js/eth_filter_endpoints_test.js (0 hunks)
  • tests/web3js/eth_multicall3_contract_test.js (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/web3js/eth_filter_endpoints_test.js
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: peterargue
PR: onflow/flow-evm-gateway#772
File: services/requester/keystore/key_store.go:50-62
Timestamp: 2025-03-07T01:35:09.751Z
Learning: In the flow-evm-gateway codebase, panics are acceptable in scenarios where immediate detection of critical bugs is desired during development and testing, particularly for invariant violations that should never occur in a correctly functioning system (e.g., when a key is available but locked in the keystore implementation).
services/requester/batch_tx_pool.go (1)
Learnt from: m-Peter
PR: onflow/flow-evm-gateway#831
File: services/requester/batch_tx_pool.go:0-0
Timestamp: 2025-06-19T11:36:25.478Z
Learning: In Go, when copying maps that contain slices (like `map[gethCommon.Address][]pooledEvmTx`), perform deep copies by iterating over the map and copying each slice individually using `make()` and `copy()` to avoid shared references that could lead to race conditions and data corruption.
🧬 Code Graph Analysis (3)
services/requester/requester.go (1)
models/transaction.go (1)
  • DeriveTxSender (314-328)
services/requester/batch_tx_pool.go (1)
models/transaction.go (1)
  • DeriveTxSender (314-328)
models/transaction.go (1)
eth/types/types.go (1)
  • Transaction (276-302)
⏰ 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: Test
🔇 Additional comments (9)
tests/fixtures/multicall3.byte (1)

1-1: Confirm multicall3.byte fixture is correct

The multicall3.byte fixture is only used by tests/web3js/eth_multicall3_contract_test.js. Please:

• Verify that tests/fixtures/multicall3.byte matches the official Multicall3 contract bytecode (e.g. compile the exact source version you expect or fetch from a trusted on-chain verifier like Etherscan).
• Ensure tests/web3js/eth_multicall3_contract_test.js correctly loads and compares against this fixture.
• Run the full test suite to confirm there are no mismatches or failures.

services/requester/requester.go (1)

211-214: LGTM! Centralized sender derivation fixes legacy transaction handling.

The change to use models.DeriveTxSender(tx) correctly addresses the issue with non-replay protected transactions by using the appropriate signer based on the transaction's chain ID.

services/requester/batch_tx_pool.go (1)

123-127: LGTM! Consistent implementation of centralized sender derivation.

The changes align with the updates in requester.go, ensuring uniform handling of transaction sender derivation across the codebase.

models/transaction.go (3)

47-47: LGTM! Essential interface addition for chain ID handling.

Adding ChainId() to the Transaction interface enables consistent chain ID access across all transaction types, which is crucial for the legacy transaction fix.


121-123: Appropriate implementation for DirectCall transactions.

Returning a zero chain ID for DirectCall is correct as these are special state transitions in Flow EVM that don't have a traditional chain ID.


314-328: Core fix correctly implements legacy transaction handling.

The DeriveTxSender function properly addresses the PR objective by:

  1. Using HomesteadSigner for transactions with zero chain ID (legacy, non-replay protected)
  2. Using LatestSignerForChainID for transactions with non-zero chain ID
  3. Centralizing sender derivation logic for consistency

This prevents the crashes mentioned in issue #845 by handling legacy transactions appropriately.

eth/types/types.go (1)

365-368: LGTM! Correctly handles legacy transactions with EIP-155 chain ID.

The check for non-zero chain ID before including it in the result is appropriate for legacy transactions that may or may not have replay protection.

tests/web3js/eth_multicall3_contract_test.js (2)

44-51: LGTM! Correctly verifies legacy transaction handling

The test properly verifies that chainId is undefined for both the transaction and block data, which aligns with the PR's objective of handling legacy (non-replay protected) transactions.


52-96: LGTM! Multicall3 contract interaction is properly implemented

The test correctly:

  • Instantiates the multicall3 contract with appropriate options
  • Uses aggregate3 to batch multiple calls
  • Properly decodes and verifies the results

@m-Peter m-Peter force-pushed the mpeter/guard-against-zero-chain-id-transactions branch from a9fbe65 to 00aaa70 Compare July 15, 2025 11:06
@m-Peter m-Peter merged commit a801ed2 into main Jul 16, 2025
2 checks passed
@m-Peter m-Peter deleted the mpeter/guard-against-zero-chain-id-transactions branch July 16, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-replay protected transactions cause JSON-RPC endpoints to crash

4 participants