Skip to content

Commit

Permalink
T
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Nov 25, 2024
1 parent 9832b77 commit dee2e87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
10 changes: 2 additions & 8 deletions src/accounts/LibERC7579.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ library LibERC7579 {
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

/// @dev Attempt to access an execution that is out of bounds.
error OutOfBoundsAccess();

/// @dev Cannot decode `executionData`.
error DecodingError();

Expand Down Expand Up @@ -255,18 +252,15 @@ library LibERC7579 {
}
}

/// @dev Returns the `i`th execution at `pointers`.
/// @dev Returns the `i`th execution at `pointers`, without bounds checks.
/// The bounds check is excluded as this function is intended to be called in a bounded loop.
function getExecution(bytes32[] calldata pointers, uint256 i)
internal
pure
returns (address target, uint256 value, bytes calldata data)
{
/// @solidity memory-safe-assembly
assembly {
if iszero(lt(i, pointers.length)) {
mstore(0x00, 0x3542fe03) // `OutOfBoundsAccess()`.
revert(0x1c, 0x04)
}
let c := add(pointers.offset, calldataload(add(pointers.offset, shl(5, i))))
target := calldataload(c)
value := calldataload(add(c, 0x20))
Expand Down
17 changes: 6 additions & 11 deletions test/LibERC7579.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,12 @@ contract LibERC7579Test is SoladyTest {
assertEq(t.opData, opData);
}

if (_randomChance(8)) {
uint256 i = _bound(_randomUniform(), 0, calls.length + 5);
if (i >= calls.length) {
vm.expectRevert(LibERC7579.OutOfBoundsAccess.selector);
this.decodeBatchAndGetExecution(abi.encode(calls), i);
} else {
(t.target, t.value, t.data) = this.decodeBatchAndGetExecution(abi.encode(calls), i);
assertEq(t.target, calls[i].target);
assertEq(t.value, calls[i].value);
assertEq(t.data, calls[i].data);
}
if (calls.length > 0 && _randomChance(8)) {
uint256 i = _bound(_randomUniform(), 0, calls.length - 1);
(t.target, t.value, t.data) = this.decodeBatchAndGetExecution(abi.encode(calls), i);
assertEq(t.target, calls[i].target);
assertEq(t.value, calls[i].value);
assertEq(t.data, calls[i].data);
}
}

Expand Down

0 comments on commit dee2e87

Please sign in to comment.