Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PreimageOracle off-by-one #11

Merged
merged 1 commit into from
Feb 13, 2024
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
4 changes: 2 additions & 2 deletions rvsol/src/PreimageOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ contract PreimageOracle is IPreimageOracle {
// len(sig) + len(partOffset) + len(preimage offset) = 4 + 32 + 32 = 0x44
size := calldataload(0x44)

// revert if part offset > size+8 (i.e. parts must be within bounds)
if gt(_partOffset, add(size, 8)) {
// revert if part offset >= size+8 (i.e. parts must be within bounds)
if iszero(lt(_partOffset, add(size, 8))) {
// Store "PartOffsetOOB()"
mstore(0, 0xfe254987)
// Revert with "PartOffsetOOB()"
Expand Down
10 changes: 10 additions & 0 deletions rvsol/test/PreimageOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ contract PreimageOracle_Test is Test {
assertTrue(ok);
}

/// @notice Tests that adding a global keccak256 pre-image at the part boundary reverts.
function test_loadKeccak256PreimagePart_partBoundary_reverts() public {
bytes memory preimage = hex"deadbeef";
uint256 offset = preimage.length + 8;

// TODO: remove magic errors
vm.expectRevert(0xfe254987);
oracle.loadKeccak256PreimagePart(offset, preimage);
}

/// @notice Tests that a pre-image cannot be set with an out-of-bounds offset.
function test_loadLocalData_outOfBoundsOffset_reverts() public {
bytes32 preimage = bytes32(uint256(0xdeadbeef));
Expand Down
Loading