Skip to content

Add ChainId to legacy transactions in RPC responses derived from signature#9453

Merged
LukaszRozmej merged 3 commits intomasterfrom
copilot/add-chainid-support-legacy-transactions
Oct 14, 2025
Merged

Add ChainId to legacy transactions in RPC responses derived from signature#9453
LukaszRozmej merged 3 commits intomasterfrom
copilot/add-chainid-support-legacy-transactions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 13, 2025

Description

Fixes legacy transaction RPC responses to include the chainId field when it can be derived from the transaction signature, even when transaction.ChainId is null.

According to the Ethereum JSON-RPC specification and Hive test expectations, legacy transactions (type 0x0) should include the chainId field in RPC responses when the transaction is signed with EIP-155 (where chainId is encoded in the V value of the signature).

Changes

Core Implementation

Modified LegacyTransactionForRpc constructor to populate ChainId from the signature when transaction.ChainId is null:

// Before: ChainId was only set from transaction.ChainId
ChainId = transaction.ChainId;

// After: Falls back to signature.ChainId if transaction.ChainId is null
ChainId = transaction.ChainId ?? signature.ChainId;

The Signature class already has logic to extract chainId from the V value for EIP-155 transactions:

  • For pre-EIP-155 transactions (V < 35): chainId is null
  • For EIP-155 transactions (V >= 35): chainId = (V + (V % 2) - 36) / 2

Testing

  • Added tests to verify chainId is correctly populated from signature when transaction.ChainId is null
  • Added test to verify transaction.ChainId takes precedence when explicitly set
  • Updated existing test expectations to include chainId in legacy transaction RPC responses

Example

For a legacy transaction with V = 0x18e5bb3abd109f (from the Hive test):

{
  "type": "0x0",
  "nonce": "0x9a",
  "chainId": "0xc72dd9d5e883e",  // Now correctly included
  "v": "0x18e5bb3abd109f",
  "r": "0x551fe45ccebb0318196e31dbc60da87c43dc60b8fb01afb3286693fa09878730",
  "s": "0x40d33e9afecfe1516b045d61a3272bddbc83f482a7f2c749311248b50fe62e81"
}

Impact

This change ensures Nethermind's RPC responses are compliant with Ethereum JSON-RPC specifications and pass Hive conformance tests for legacy transactions.

Resolves issue where Hive expected chainId to be returned for legacy transactions.

Original prompt

This section details on the original issue you should resolve

<issue_title>ChainID for legacy transactions in RPC</issue_title>
<issue_description>```

{"jsonrpc":"2.0","id":1,"method":"eth_getBlockByNumber","params":["safe",true]}
<< {"jsonrpc":"2.0","result":{"difficulty":"0x0","extraData":"0x","gasLimit":"0x47e7c40","gasUsed":"0x54a92","hash":"0xaf51811799f22260e5b4e1f95504dae760505f102dcb2e9ca7d897d8a40124a1","logsBloom":"0x00000000008000000000000000000040000000000000000000000000800000000000000008000000000000000000000000000000000000000000000000000000000000000000000000004000000000020200000000000000000000000000002000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000009000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x2d","parentHash":"0xab97b6b403066d2f4b270171bd532cc489510c1e07df609718dfc875cace60f1","receiptsRoot":"0x2c86b2791cdd088d3c3e9d6225f71724d3e8c67bdd13cd6208831058cee1043f","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x633","stateRoot":"0x67b58d6bd3c58396b464d3ae8f8a7e2e8ebf912b203ece9bf8a89063a79265bd","timestamp":"0x1c2","baseFeePerGas":"0x5763d64","transactions":[{"type":"0x0","nonce":"0x9a","to":null,"from":"0x7435ed30a8b4aeb0877cef0c6e8cffe834eb865f","value":"0x0","input":"0x600d380380600d6000396000f336156009575f355f555b305f525f5460205260405ff3","gasPrice":"0x5763d65","v":"0x18e5bb3abd109f","r":"0x551fe45ccebb0318196e31dbc60da87c43dc60b8fb01afb3286693fa09878730","s":"0x40d33e9afecfe1516b045d61a3272bddbc83f482a7f2c749311248b50fe62e81","hash":"0x2fbbd036996c7487316c92b9e5798edb98fd57f32a6c1075e904a734821e1cd2","transactionIndex":"0x0","blockHash":"0xaf51811799f22260e5b4e1f95504dae760505f102dcb2e9ca7d897d8a40124a1","blockNumber":"0x2d","gas":"0x11c32"},{"type":"0x4","authorizationList":[{"chainId":"0xc72dd9d5e883e","nonce":"0x0","address":"0x58f8fe237b593c19546e1e758a2544561d04bfe0","yParity":"0x1","s":"0x1d1225f76d6faac3d904c0635193e83d3867c101b2e6f6c9bb7b1fdeeed923ab","r":"0xec6caeb1b7071f1b3ae36aeaa7bf0eaecb8e006e83b3e50d792870ea95af4c59"}],"maxPriorityFeePerGas":"0x1","maxFeePerGas":"0x5763d65","accessList":[],"yParity":"0x1","chainId":"0xc72dd9d5e883e","nonce":"0x9b","to":"0x0000000000000000000000000000000000000000","from":"0x7435ed30a8b4aeb0877cef0c6e8cffe834eb865f","value":"0x0","input":"0x","gasPrice":"0x5763d65","v":"0x1","r":"0x8ae3402e4f63751c895532b94aee0f7b6b8ff5d0b0a689f6d63b3dbd19d69059","s":"0x2e63e4d140b0d282d56289b34f3df82cbcb2f3aa385f5438a423584fe0c2b467","hash":"0x16f6724ad864e7664c367893cae3e176d362bea3a47495cec3b246555a7228da","transactionIndex":"0x1","blockHash":"0xaf51811799f22260e5b4e1f95504dae760505f102dcb2e9ca7d897d8a40124a1","blockNumber":"0x2d","gas":"0xb3b0"},{"type":"0x0","nonce":"0x9c","to":"0xeda8645ba6948855e3b3cd596bbb07596d59c603","from":"0x7435ed30a8b4aeb0877cef0c6e8cffe834eb865f","value":"0x0","input":"0x696e766f6b6564","gasPrice":"0x5763d65","v":"0x18e5bb3abd10a0","r":"0xfea7e18c82a1270f142572533bc2e6e33d6d41a3f1303403dd0a90dd7a4f35d","s":"0x4a4ab6c5bb4c31c3a5f8991ae45bad2303c45923404571f7b4c66adbd03b7936","hash":"0xddf234c5f149d2d1a4d01276d42e38a6234bfa7b987c49ba889b028b429aac8f","transactionIndex":"0x2","blockHash":"0xaf51811799f22260e5b4e1f95504dae760505f102dcb2e9ca7d897d8a40124a1","blockNumber":"0x2d","gas":"0x11170"},{"type":"0x2","maxPriorityFeePerGas":"0x2","maxFeePerGas":"0x5763d65","accessList":[],"yParity":"0x1","chainId":"0xc72dd9d5e883e","nonce":"0x9d","to":"0x00000961ef480eb55e80d19ad83579a64c007002","from":"0x7435ed30a8b4aeb0877cef0c6e8cffe834eb865f","value":"0x3b9aca00","input":"0xb917cfdc0d25b72d55cf94db328e1629b7f4fde2c30cdacf873b664416f76a0c7f7cc50c9f72a3cb84be88144cde91250000000000000d80","gasPrice":"0x5763d65","v":"0x1","r":"0x5f8b300cf80f7fb7e511460fa1a803278b47223f2c0a82857c5c0e5f7c900d23","s":"0x290bf2495235a106352786403ed937df8385a2356472569020fd952913690ec9","hash":"0x3d3d02e1bdc39a6eab20f7b44ed299ca61eb1d642806bfa07e3a7ee8edd700e5","transactionIndex":"0x3","blockHash":"0xaf51811799f22260e5b4e1f95504dae760505f102dcb2e9ca7d897d8a40124a1","blockNumber":"0x2d","gas":"0x249f0"},{"type":"0x1","accessList":[{"address":"0x7dcd17433742f4c0ca53122ab541d0ba67fc27df","storageKeys":["0x0000000000000000000000000000000000000000000000000000000000000000","0xe8481f0a1ea7b2528784efff1d1b33cbd66ac97ebe2ae35c7997cacb2863430b"]}],"yParity":"0x0","chainId":"0xc72dd9d5e883e","nonce":"0x9e","to":"0x7dcd17433742f4c0ca53122ab541d0ba67fc27df","from":"0x7435ed30a8b4aeb0877cef0c6e8cffe834eb865f","value":"0x2","input":"0x6b3b937565afc29f656d6974","gasPrice":"0x5763d65","v":"0x0","r":"0x84f8b48ac6fbf39054c7794e6ff4e1...

Fixes #9372


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 13, 2025 21:02
Co-authored-by: MarekM25 <9356351+MarekM25@users.noreply.github.com>
Co-authored-by: MarekM25 <9356351+MarekM25@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ChainID support for legacy transactions in RPC Add ChainId to legacy transactions in RPC responses derived from signature Oct 13, 2025
Copilot AI requested a review from MarekM25 October 13, 2025 21:21
@MarekM25 MarekM25 marked this pull request as ready for review October 14, 2025 11:53
@LukaszRozmej LukaszRozmej merged commit c7cf8a2 into master Oct 14, 2025
157 of 223 checks passed
@LukaszRozmej LukaszRozmej deleted the copilot/add-chainid-support-legacy-transactions branch October 14, 2025 12:23
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.

ChainID for legacy transactions in RPC

4 participants