Skip to content

Commit 535b54d

Browse files
authored
Rename arrayLengthPointer to arrayLengthOffset and add changeset (#5371)
1 parent a71f79f commit 535b54d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

.changeset/seven-insects-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openzeppelin-solidity': patch
3+
---
4+
5+
`ERC7579Utils`: Add ABI decoding checks on calldata bounds within `decodeBatch`

contracts/account/utils/draft-ERC7579Utils.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,28 @@ library ERC7579Utils {
182182
if (bufferLength < 32) revert ERC7579DecodingError();
183183

184184
// Get the offset of the array (pointer to the array length).
185-
uint256 arrayLengthPointer = uint256(bytes32(executionCalldata[0:32]));
185+
uint256 arrayLengthOffset = uint256(bytes32(executionCalldata[0:32]));
186186

187-
// The array length (at arrayLengthPointer) should be 32 bytes long. We check that this is within the
187+
// The array length (at arrayLengthOffset) should be 32 bytes long. We check that this is within the
188188
// buffer bounds. Since we know bufferLength is at least 32, we can subtract with no overflow risk.
189-
if (arrayLengthPointer > bufferLength - 32) revert ERC7579DecodingError();
189+
if (arrayLengthOffset > bufferLength - 32) revert ERC7579DecodingError();
190190

191-
// Get the array length. arrayLengthPointer + 32 is bounded by bufferLength so it does not overflow.
192-
uint256 arrayLength = uint256(bytes32(executionCalldata[arrayLengthPointer:arrayLengthPointer + 32]));
191+
// Get the array length. arrayLengthOffset + 32 is bounded by bufferLength so it does not overflow.
192+
uint256 arrayLength = uint256(bytes32(executionCalldata[arrayLengthOffset:arrayLengthOffset + 32]));
193193

194194
// Check that the buffer is long enough to store the array elements as "offset pointer":
195195
// - each element of the array is an "offset pointer" to the data.
196196
// - each "offset pointer" (to an array element) takes 32 bytes.
197197
// - validity of the calldata at that location is checked when the array element is accessed, so we only
198198
// need to check that the buffer is large enough to hold the pointers.
199199
//
200-
// Since we know bufferLength is at least arrayLengthPointer + 32, we can subtract with no overflow risk.
200+
// Since we know bufferLength is at least arrayLengthOffset + 32, we can subtract with no overflow risk.
201201
// Solidity limits length of such arrays to 2**64-1, this guarantees `arrayLength * 32` does not overflow.
202-
if (arrayLength > type(uint64).max || bufferLength - arrayLengthPointer - 32 < arrayLength * 32)
202+
if (arrayLength > type(uint64).max || bufferLength - arrayLengthOffset - 32 < arrayLength * 32)
203203
revert ERC7579DecodingError();
204204

205205
assembly ("memory-safe") {
206-
executionBatch.offset := add(add(executionCalldata.offset, arrayLengthPointer), 32)
206+
executionBatch.offset := add(add(executionCalldata.offset, arrayLengthOffset), 32)
207207
executionBatch.length := arrayLength
208208
}
209209
}

0 commit comments

Comments
 (0)