-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Audit Fixes for RLP library on Broadcaster Audit #6106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: fe917b7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThe RLP library in Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
contracts/utils/RLP.sol(4 hunks)
⏰ 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). (9)
- GitHub Check: Redirect rules - solidity-contracts
- GitHub Check: Header rules - solidity-contracts
- GitHub Check: coverage
- GitHub Check: tests-foundry
- GitHub Check: slither
- GitHub Check: tests-upgradeable
- GitHub Check: tests
- GitHub Check: halmos
- GitHub Check: Pages changed - solidity-contracts
| assembly ("memory-safe") { | ||
| result := mload(0x40) | ||
| mstore(result, 0x15) // length of the encoded data: 1 (prefix) + 0x14 (address) | ||
| mstore(add(result, 0x20), or(shl(248, 0x94), shl(88, input))) // prefix (0x94 = SHORT_OFFSET + 0x14) + input | ||
| mstore(0x40, add(result, 0x35)) // reserve memory | ||
| } |
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.
This encoding is not consistent with how the ethereum ecosystem does things.
If you try to use ethers.js to do encode an address that had zeros, you'll get them encoded
> ethers.encodeRlp(ethers.ZeroAddress);
'0x940000000000000000000000000000000000000000'Note that this difference is important in the context of operations like getCreateAddress. If the address prefix zeros are removed, you'd get an invalid address prediction.
I'll add unit tests to show these issues.
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.
I mentioned to the auditors that it makes sense to include leading zeroes in addresses because there's no definition of an address in RLP. My thinking about this is that leading zeroes in an address are not necessarily "leading" because they constitute relevant information for the address.
|
Added tests that demonstrate the breaking effect of these changes. You can see on #6107 that these tests pass on master. If someone wants to encode an Address without the leading zeros, they can manually do the casting to uint256 and then call the corresponding encode function. However I believe this should not be the default encoding. In particular, predicting the addresses of contracts created using the CREATE mechanism requires the addresses to have the prefix zeros. IMO the library must offer a function that behaves that way, and I think the encode(address) is the one. |
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…mxx/openzeppelin-contracts into testing/rlp-encoding-addresses
| assembly ("memory-safe") { | ||
| result := mload(0x40) | ||
| mstore(result, 0x15) // length of the encoded data: 1 (prefix) + 0x14 (address) | ||
| mstore(result, 21) // length of the encoded data: 1 (prefix) + 0x14 (address) |
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.
Isn't this against our guidelines?
Numeric literals should use appropriate formats based on their purpose to improve code readability:
Memory-related operations (use hexadecimal):
- Memory locations:
mload(64)→mload(0x40)- Memory offsets:
mstore(add(ptr, 32), value)→mstore(add(ptr, 0x20), value)- Memory lengths:
keccak256(ptr, 85)→keccak256(ptr, 0x55)
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.
I don't think we need a changeset since we're not changing functionality
PR Checklist
npx changeset add)