fix: reject EIP-1559 transactions missing chain_id#428
Closed
BitHighlander wants to merge 0 commit into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
This PR prevents malformed EIP-1559 Ethereum transactions (type 0x02) from being signed when chain_id is omitted, avoiding a mismatch between the computed RLP length and the bytes actually hashed (which can corrupt the keccak preimage and lead to signatures recovering to the wrong address).
Changes:
- Add an explicit input-validation check to reject EIP-1559 transactions when
msg->has_chain_id == false. - Return a
Failure_SyntaxErrorwith a specific message and abort signing early.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
73bd71b to
bc8bd3c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
hash_rlp_number(0)returns immediately without hashing any bytes:But
rlp_calculate_number_length(0)returns 1 (for the0x80byte that should represent integer 0 in RLP).For an EIP-1559 transaction sent without
chain_id(has_chain_id = false),chain_iddefaults to 0. The length calculation adds 1 byte torlp_lengthfor it, buthash_rlp_number(0)hashes nothing. The RLP list header claims N bytes but only N−1 are hashed — corrupting the keccak pre-image. The resulting signature recovers to a wrong address.The legacy EIP-155 path is safe because
send_signature()guards withif (chain_id) { hash_rlp_number(chain_id); }. The EIP-1559 path inethereum_signing_init()had no such guard:Fix
Fail fast at the input validation stage. EIP-1559 requires
chain_idby spec (EIP-1559 §4.2: "chainId is the chain ID of the signing chain").Notes