Skip to content

Commit 0b86f77

Browse files
committed
Fix PreimageOracle off-by-one
1 parent d3ff8bd commit 0b86f77

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

rvsol/src/PreimageOracle.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ contract PreimageOracle is IPreimageOracle {
7474
// len(sig) + len(partOffset) + len(preimage offset) = 4 + 32 + 32 = 0x44
7575
size := calldataload(0x44)
7676

77-
// revert if part offset > size+8 (i.e. parts must be within bounds)
78-
if gt(_partOffset, add(size, 8)) {
77+
// revert if part offset >= size+8 (i.e. parts must be within bounds)
78+
if iszero(lt(_partOffset, add(size, 8))) {
7979
// Store "PartOffsetOOB()"
8080
mstore(0, 0xfe254987)
8181
// Revert with "PartOffsetOOB()"

rvsol/test/PreimageOracle.t.sol

+10
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ contract PreimageOracle_Test is Test {
133133
assertTrue(ok);
134134
}
135135

136+
/// @notice Tests that adding a global keccak256 pre-image at the part boundary reverts.
137+
function test_loadKeccak256PreimagePart_partBoundary_reverts() public {
138+
bytes memory preimage = hex"deadbeef";
139+
uint256 offset = preimage.length + 8;
140+
141+
// TODO: remove magic errors
142+
vm.expectRevert(0xfe254987);
143+
oracle.loadKeccak256PreimagePart(offset, preimage);
144+
}
145+
136146
/// @notice Tests that a pre-image cannot be set with an out-of-bounds offset.
137147
function test_loadLocalData_outOfBoundsOffset_reverts() public {
138148
bytes32 preimage = bytes32(uint256(0xdeadbeef));

0 commit comments

Comments
 (0)