-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Add RLP library #5680
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?
Add RLP library #5680
Conversation
Co-authored-by: Hadrien Croubois <[email protected]>
Co-authored-by: Arr00 <[email protected]>
🦋 Changeset detectedLatest commit: fdcb15f 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 |
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
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.
Left some comments in Memory, I will continue reviewing the RLP and Accumulators library later
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/ERC4626.sol) | ||
|
||
pragma solidity ^0.8.20; | ||
pragma solidity ^0.8.24; |
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.
Any reason for this?
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.
If we're keeping it we should add it to the changelog. I did in 698221f
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.
Since we haven't release this file, I just noticed it may be clever to follow the same pattern as in ERC7579Utils where we define the type at the file level and then we create free functions to overload operators:
// Operators
using {eqPointer as ==} for Memory.Pointer global;
/// @dev Compares two `Pointer` values for equality.
function eqPointer(Memory.Pointer a, Memory.Pointer b) pure returns (bool) {
return Memory.asBytes32(a) == Memory.asBytes32(b);
}
Maybe overengineered but just mentioning before it becomes a breaking change. Note it would populate the global namespace for Pointer
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.
It is not possible to do using {...} for <type> global;
when the Type is in a library
Can only use "global" with types defined in the same source unit at file level.
To do that, we would have to declare Pointer at the file level (so outside the Memory library), which means we would probably need to rename it.
contracts/utils/RLP.sol
Outdated
uint256 lengthLength = prefix - SHORT_OFFSET - SHORT_THRESHOLD; | ||
|
||
require(itemLength > lengthLength, RLPInvalidDataRemainder(lengthLength, itemLength)); | ||
require(bytes1(item.load(0)) != 0x00); // TODO: custom error for sanity checks |
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.
Maybe panic with RESOURCE_ERROR
code?
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.
Almost there!
The only thing left to discuss is the error to use in Once that's done I think the PR should be good. The main problem may be the coverage hit but we may be fine with that (?) |
Requires:
Memory
utility library #5189reverseBits
operations to Bytes.sol #5724clz(bytes)
andclz(uint256)
functions #5725PR Checklist
npx changeset add
)