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 NameTest NameMain GasPR GasDiff
LibRLPTesttestComputeAddressForLargeNonces()1750177222
testComputeAddressOriginalForLargeNonces()3495351722
testComputeAddressOriginalForSmallNonces()2088211123
testRLPEncodeBytes()25014725019851
testRLPEncodeBytes2()155904156672768
testRLPEncodeList()3426655718111-2708544
testRLPEncodeList2()808242793155-15087
testRLPEncodeListEdgeCases()1807977181940611429
testRLPEncodeStringEdgeCases()205382056022
testRLPEncodeUint()14616291317882-143747
testRLPPUint256()36383436386632
test__codesize()18246260507804
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-
LibRLPWithCLZTesttestComputeAddressForLargeNonces()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 freeto 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

@BhariGowda