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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I getting this right? You want to find a
chunk
value that makes the minimum transmitted chunk size larger than3
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The ledger bug above triggers when a chunk boundary falls immediately between
data
andchainid
in unsigned, legacy transactions. By ensuring that the final chunk is always at least 4 bytes large, we prevent this triggering condition from occurringThe EIP-155 unsigned TX RLP format is:
(nonce, gasprice, startgas, to, value, data, chainid, 0, 0)
The root cause of the bug appears to be that ledger does not validate the length of the RLP list. The unsigned tx RLP list contains 9 items. However, the Ledger Ethereum app completes deser of the unsigned transaction when it has received at least 6 items, and the RLP input has been exactly consumed
(no extra bytes are left in the device's RLP buffer). When the chunk boundary falls between
data
andchainid
these conditions are met, and the ledger device prematurely starts its signing flow. The remaining 3 itemschainid, 0 ,0
are in an unsent chunk. During the signing flow, this causes thechainid
in the device to be 0, and the user to accidentally sign a transaction withchainid
0.The mitigation ensures that the chunk boundary doesn't fall on the item boundary between
data
andchainid
. Ifchainid
is a single byte, then 3 list items are 3 bytes long. Ifchainid
is 2 or more bytes, then ensuring the last packet is at least 4 bytes ensures that the packet boundary either includeschainid
or falls in the middle ofchainid
. This ensures that the triggering conditions are never met, as either thechainid
will be sent in its entirety, or a portion of thechainid
will be sent, and the device will wait for the final packet