Skip to content

Commit

Permalink
apply seppi's recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Dec 12, 2024
1 parent cc6bdc6 commit 35c74ab
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions contracts/account/utils/draft-ERC7579Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,23 @@ library ERC7579Utils {
uint256 offset = uint256(bytes32(executionCalldata[0:32]));

// The array length should be found at offset and be 32 bytes long. We check that this is within the
// buffer bounds. Since we know executionCalldata is at least 32, we can subtract with no overflow risk.
// buffer bounds. Since we know bufferLength is at least 32, we can subtract with no overflow risk.
if (offset > bufferLength - 32) revert ERC7579DecodingError();

// Get the array length. offset + 32 is bounded by bufferLength so does not overflow.
uint256 arrayLength = uint256(bytes32(executionCalldata[offset:offset + 32]));
if (arrayLength > type(uint64).max) revert ERC7579DecodingError();

// Get the array as a bytes slice, and check it is long enough:
// - each element of the array is an "offset pointer" to the data
// - each offset pointer takes 32 bytes
// - validity of the calldata at that location is checked when the array element is accessed.
// - `arrayLength * 32` does not overflow because `arrayLength` is less than `2**64`.
bytes calldata executionArray = executionCalldata[offset + 32:];
if (executionArray.length < arrayLength * 32) revert ERC7579DecodingError();
// Since we know bufferLength is at least offset + 32, we can subtract with no overflow risk.
if (arrayLength > type(uint64).max || bufferLength - offset - 32 < arrayLength * 32)
revert ERC7579DecodingError();

assembly ("memory-safe") {
executionBatch.offset := executionArray.offset
executionBatch.offset := add(add(executionCalldata.offset, offset), 32)
executionBatch.length := arrayLength
}
}
Expand Down

0 comments on commit 35c74ab

Please sign in to comment.