Skip to content

✨ Add RLP decoding to LibRLP (issue #1449)#1540

Open
BhariGowda wants to merge 3 commits into
Vectorized:mainfrom
BhariGowda:feat/rlp-decoding
Open

✨ Add RLP decoding to LibRLP (issue #1449)#1540
BhariGowda wants to merge 3 commits into
Vectorized:mainfrom
BhariGowda:feat/rlp-decoding

Conversation

@BhariGowda

Copy link
Copy Markdown
Contributor

Closes #1449

Adds the decode side to LibRLP:

New API

Structs

  • Item zero-copy view into encoded RLP input (offset + length + type)

Public decoders

  • decodeBytes(bytes memory)bytes memory
  • decodeUint256(bytes memory)uint256
  • decodeAddress(bytes memory)address
  • decodeBytes32(bytes memory)bytes32
  • decodeList(bytes memory)Item[] memory

Item overloads

  • decodeBytes(Item), decodeUint256(Item), decodeAddress(Item), decodeBytes32(Item)

Iteration

  • next(Item) next sibling, empty sentinel when exhausted
  • isList(Item)bool
  • isEmpty(Item)bool

Design

  • Pure assembly, zero-copy list views into input
  • _decodeLength: single shared prefix decoder with full validation
  • Permissive (accepts non-canonical leading-zero scalars, like OZ reference)
  • mcopy avoided (paris EVM); word-copy loop with tail zeroization

Tests

42 tests passing fuzz + edge cases + 9 revert cases + round-trips

@github-actions

Copy link
Copy Markdown

Gas Snapshot Comparison Report

Generated at commit : 5ea73fa, Compared to commit : ab96a83

Contract Name Test Name Main Gas PR Gas Diff
LibRLPTest testComputeAddressForLargeNonces() 1750 1772 22
testComputeAddressOriginalForLargeNonces() 3495 3517 22
testComputeAddressOriginalForSmallNonces() 2088 2111 23
testRLPEncodeBytes() 250147 250198 51
testRLPEncodeBytes2() 155904 156672 768
testRLPEncodeList() 3426655 718111 -2708544
testRLPEncodeList2() 808242 793155 -15087
testRLPEncodeListEdgeCases() 1807977 1819406 11429
testRLPEncodeStringEdgeCases() 20538 20560 22
testRLPEncodeUint() 1461629 1317882 -143747
testRLPPUint256() 363834 363866 32
test__codesize() 18246 26050 7804
testRLPDecodeAddressSingleByte() - 2624 -
testRLPDecodeBytes32() - 2728 -
testRLPDecodeBytesEdgeCases() - 25047 -
testRLPDecodeEmptyItemQueries() - 672 -
testRLPDecodeEmptyList() - 1126 -
testRLPDecodeInvalidReverts() - 41994 -
testRLPDecodeKnownVectors() - 9552 -
testRLPDecodeListIteratorEquivalence() - 8109 -
testRLPDecodeListKnownVector() - 4602 -
testRLPDecodeLongListRoundTrip() - 38483 -
testRLPDecodeNestedList() - 10084 -
testRLPDecodeNonCanonical() - 2514 -
testRLPDecodeUint() - 66339 -
LibRLPWithCLZTest testComputeAddressForLargeNonces() 1750 - -
testComputeAddressForSmallNonces() 997 - -
testComputeAddressOriginalForLargeNonces() 3495 - -
testComputeAddressOriginalForSmallNonces() 2088 - -
testRLPEncodeBytes() 250090 - -
testRLPEncodeBytes2() 155904 - -
testRLPEncodeList() 735942 - -
testRLPEncodeList2() 810708 - -
testRLPEncodeListEdgeCases() 1807743 - -
testRLPEncodeStringEdgeCases() 20424 - -
testRLPEncodeUint() 1175570 - -
testRLPPUint256() 363834 - -
test__codesize() 18292 - -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Rlp decoding + MPT proofs

1 participant