-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Draft
ernestognw
wants to merge
75
commits into
OpenZeppelin:master
Choose a base branch
from
ernestognw:feature/rlp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+516
−0
Draft
Add RLP library #5680
Changes from 68 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
9eb5f1c
Add memory utils
ernestognw 2d397f4
Fix tests upgradeable
ernestognw 2a0fb7e
Add docs
ernestognw a7e61c3
Make use of the library
ernestognw 1aae8bb
Update docs/modules/ROOT/pages/utilities.adoc
ernestognw 1b2679a
Merge branch 'master' into utils/memory
Amxx d514606
fix tests
Amxx 14fa04e
Update contracts/utils/Memory.sol
ernestognw d0d55fc
Update contracts/utils/Memory.sol
arr00 7b3cb66
Add RLP library
ernestognw 95149f8
Add TrieProof library
ernestognw ad5d4ac
up
ernestognw 18540ef
Add docs
ernestognw 163f27c
Workaround stack too deep
ernestognw c484289
Add Changesets
ernestognw e0d4790
Add more changesets
ernestognw a6f9053
Add FV and fuzz tests
ernestognw e2b5e4c
Merge branch 'master' into feature/rlp
ernestognw 203d1a2
up
ernestognw 48eabc1
docs
ernestognw 63ced95
up pragma
ernestognw f342756
Add missing Bytes test
ernestognw 23dba37
Add unit tests
ernestognw 0cacca2
up pragma
ernestognw 831e8ab
Move TrieProof
ernestognw 5da111f
Fix countLeadingZeroes
ernestognw ba2293e
nits
ernestognw 9409bc6
Improve
ernestognw e740dac
Fix
ernestognw 0332ffe
Add Memory.sol library
ernestognw 608e3cd
Merge branch 'master' into utils/memory
ernestognw ac92bb4
up
ernestognw 6094bb7
Merge branch 'master' into utils/memory
ernestognw 6bb96d5
WIP: Add more Memory functions
ernestognw 860e5a8
up
ernestognw ecdb768
revert
ernestognw 95907aa
Update docs
ernestognw 124ccee
Nit
ernestognw c3237df
Finish fuzz tests and FV
ernestognw 27f0a9b
up
ernestognw 282ce39
up
ernestognw bdd2cf1
Add operations to Math.sol
ernestognw 42c79f1
Add new equal, nibbles and countLeadingZeroes functions
ernestognw 5754ab8
Rename countLeadingZeroes to clz
ernestognw 44f0e14
up
ernestognw 05c73bd
Pragma changes
ernestognw 3a6fbf6
up
ernestognw e67e8b4
up
ernestognw 3385718
Rename to in Math library and update corresponding tests for consis…
ernestognw 40d7922
Update return types of reverseBits functions to match their respectiv…
ernestognw 89860bc
Refactor reverseBits functions in to use fixed-size byte types
ernestognw 9b58730
Test nits
ernestognw 77ffa8c
Simplify
ernestognw ce91c80
up
ernestognw b3e3add
Move reverse functions to Bytes.sol
ernestognw 2f3107c
Move Bytes.t.sol
ernestognw 4383e01
Merge branch 'master' into feat/bytes-rlp
ernestognw 5a44b11
up
ernestognw d6db2d7
Document
ernestognw 3847050
Remove extra functions
ernestognw 4fd1947
Update docs
ernestognw c4e0375
up
ernestognw acb14cb
Merge branch 'utils/memory' into feature/rlp
ernestognw 2208006
Merge branch 'feat/math-reverse-bits' into feature/rlp
ernestognw 13f4d8f
Merge branch 'feat/bytes-rlp' into feature/rlp
ernestognw 502a520
Merge branch 'master' into feature/rlp
ernestognw aab9274
Merge branch 'master' into feature/rlp
Amxx aa26e48
up
Amxx 948f0a1
Merge branch 'master' into feature/rlp
ernestognw d4bfb8b
Fix compilation
ernestognw 138de7f
Remove dangling clz
ernestognw 5efeb37
Make nibbles function private
ernestognw 00ff228
Remove nibbles test
ernestognw c58c7fd
Remove TrieProof library
ernestognw d1aa944
Add some tests
ernestognw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`Bytes`: Add a `nibbles` function to split each byte into two nibbles. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`RLP`: Add library for Ethereum's Recursive Length Prefix encoding/decoding. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`TrieProof`: Add library for verifying Ethereum Merkle-Patricia trie inclusion proofs. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`Bytes`: Add an `equal` function to compare byte buffers. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': minor | ||
--- | ||
|
||
`Bytes`: Add a `clz` function to count the leading zero bytes in a `uint256` value. |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
The
toNibbles
function converts a bytes array like 0xABCD into a nibble-expanded format like 0xA00BC00D. The existing implementation does this by iterating linearly over the input, which works correctly but is extremely inefficient.My approach processes the input in parallel, reducing time complexity from O(n) to O(n / 32). This is inspired by bit-hacking techniques for interleaving bits, as described in the following resources:
https://stackoverflow.com/questions/38881877/bit-hack-expanding-bits
https://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN
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.
Bringing it all together:
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.
Can probably be simplified further by adjusting the first 4 masks, working on that now.