Skip to content

Commit dc7cc17

Browse files
committed
Fix asBoolUnchecked function
1 parent 462a9a1 commit dc7cc17

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/libraries/BytesParsing.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ library BytesParsing {
77

88
error OutOfBounds(uint256 offset, uint256 length);
99
error LengthMismatch(uint256 encodedLength, uint256 expectedLength);
10+
error InvalidBoolVal(uint8 val);
1011

1112
function checkBound(uint offset, uint length) internal pure {
1213
if (offset > length)
@@ -95,8 +96,15 @@ library BytesParsing {
9596
bytes memory encoded,
9697
uint offset
9798
) internal pure returns (bool, uint) {
98-
(uint8 ret, uint nextOffset) = asUint8(encoded, offset);
99-
return (ret != 0, nextOffset);
99+
(uint8 val, uint nextOffset) = asUint8(encoded, offset);
100+
if (val & 0xfe != 0)
101+
revert InvalidBoolVal(val);
102+
103+
bool ret;
104+
assembly ("memory-safe") {
105+
ret := val
106+
}
107+
return (ret, nextOffset);
100108
}
101109

102110
function asBool(

0 commit comments

Comments
 (0)