Skip to content

Commit 6b0f2ee

Browse files
committed
Fix PreimageOracle off-by-one
1 parent ad94f2d commit 6b0f2ee

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

rvsol/src/PreimageOracle.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ contract PreimageOracle is IPreimageOracle {
9090
// len(sig) + len(partOffset) + len(preimage offset) = 4 + 32 + 32 = 0x44
9191
size := calldataload(0x44)
9292

93-
// revert if part offset > size+8 (i.e. parts must be within bounds)
94-
if gt(_partOffset, add(size, 8)) {
93+
// revert if part offset >= size+8 (i.e. parts must be within bounds)
94+
if iszero(lt(_partOffset, add(size, 8))) {
9595
// Store "PartOffsetOOB()"
9696
mstore(0, 0xfe254987)
9797
// Revert with "PartOffsetOOB()"

rvsol/test/PreimageOracle.t.sol

Lines changed: 10 additions & 0 deletions
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)