Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yellow-clowns-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': patch
---

`RLP`: Fix RLP encoding validity check when decoding long lists or strings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe include in a ### Bug fixes section of the changelog?

11 changes: 6 additions & 5 deletions contracts/utils/RLP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,10 @@ library RLP {
// Case: Long string (>55 bytes)
uint256 lengthLength = prefix - SHORT_OFFSET - SHORT_THRESHOLD;

require(itemLength > lengthLength && bytes1(item.load(0)) != 0x00, RLPInvalidEncoding());
bytes32 lenChunk = item.load(1);
require(itemLength > lengthLength && bytes1(lenChunk) != 0x00, RLPInvalidEncoding());

uint256 len = uint256(item.load(1)) >> (256 - 8 * lengthLength);
uint256 len = uint256(lenChunk) >> (256 - 8 * lengthLength);
require(len > SHORT_THRESHOLD && itemLength > lengthLength + len, RLPInvalidEncoding());

return (lengthLength + 1, len, ItemType.Data);
Expand All @@ -369,10 +370,10 @@ library RLP {
// Case: Long list
uint256 lengthLength = prefix - LONG_OFFSET - SHORT_THRESHOLD;

require(itemLength > lengthLength, RLPInvalidEncoding());
require(bytes1(item.load(0)) != 0x00);
bytes32 lenChunk = item.load(1);
require(itemLength > lengthLength && bytes1(lenChunk) != 0x00, RLPInvalidEncoding());

uint256 len = uint256(item.load(1)) >> (256 - 8 * lengthLength);
uint256 len = uint256(lenChunk) >> (256 - 8 * lengthLength);
require(len > SHORT_THRESHOLD && itemLength > lengthLength + len, RLPInvalidEncoding());

return (lengthLength + 1, len, ItemType.List);
Expand Down