Skip to content

Commit aa110ab

Browse files
Amxxernestognw
andcommitted
Fix typos and documentation for the 5.6 audit. (#6330)
Co-authored-by: ernestognw <ernestognw@gmail.com> Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
1 parent 27dddf8 commit aa110ab

File tree

15 files changed

+87
-60
lines changed

15 files changed

+87
-60
lines changed

contracts/crosschain/ERC7786Recipient.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ abstract contract ERC7786Recipient is IERC7786Recipient {
5151
*/
5252
function _isAuthorizedGateway(address gateway, bytes calldata sender) internal view virtual returns (bool);
5353

54-
/// @dev Virtual function that should contain the logic to execute when a cross-chain message is received.
54+
/**
55+
* @dev Virtual function that should contain the logic to execute when a cross-chain message is received.
56+
*
57+
* NOTE: This function should revert on failure. Any silent failure from this function will result in the message
58+
* being marked as received and not being retryable.
59+
*/
5560
function _processMessage(
5661
address gateway,
5762
bytes32 receiveId,

contracts/metatx/ERC2771Forwarder.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ contract ERC2771Forwarder is EIP712, Nonces {
214214
* @dev Returns a tuple with the recovered the signer of an EIP712 forward request message hash
215215
* and a boolean indicating if the signature is valid.
216216
*
217-
* NOTE: The signature is considered valid if {ECDSA-tryRecover} indicates no recover error for it.
217+
* NOTE: The signature is considered valid if {ECDSA-tryRecoverCalldata} indicates no recover error for it.
218218
*/
219219
function _recoverForwardRequestSigner(
220220
ForwardRequestData calldata request

contracts/token/ERC1155/ERC1155.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IER
376376
*
377377
* Requirements:
378378
*
379+
* - `owner` cannot be the zero address.
379380
* - `operator` cannot be the zero address.
380381
*/
381382
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {

contracts/utils/Arrays.sol

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -466,21 +466,21 @@ library Arrays {
466466
}
467467

468468
/**
469-
* @dev Moves the content of `array`, from `start` (included) to the end of `array` to the start of that array.
469+
* @dev Moves the content of `array`, from `start` (included) to the end of `array` to the start of that array,
470+
* and shrinks the array length accordingly, effectively overwriting the array with array[start:].
470471
*
471472
* NOTE: This function modifies the provided array in place. If you need to preserve the original array, use {slice} instead.
472-
* NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice[Javascript's `Array.splice`]
473473
*/
474474
function splice(address[] memory array, uint256 start) internal pure returns (address[] memory) {
475475
return splice(array, start, array.length);
476476
}
477477

478478
/**
479-
* @dev Moves the content of `array`, from `start` (included) to `end` (excluded) to the start of that array. The
479+
* @dev Moves the content of `array`, from `start` (included) to `end` (excluded) to the start of that array,
480+
* and shrinks the array length accordingly, effectively overwriting the array with array[start:end]. The
480481
* `end` argument is truncated to the length of the `array`.
481482
*
482483
* NOTE: This function modifies the provided array in place. If you need to preserve the original array, use {slice} instead.
483-
* NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice[Javascript's `Array.splice`]
484484
*/
485485
function splice(address[] memory array, uint256 start, uint256 end) internal pure returns (address[] memory) {
486486
// sanitize
@@ -499,7 +499,7 @@ library Arrays {
499499
/**
500500
* @dev Replaces elements in `array` starting at `pos` with all elements from `replacement`.
501501
*
502-
* Parameters are clamped to valid ranges (i.e. `pos` is clamped to `[0, array.length]`).
502+
* Parameters are clamped to valid ranges (e.g. `pos` is clamped to `[0, array.length]`).
503503
* If `pos >= array.length`, no replacement occurs and the array is returned unchanged.
504504
*
505505
* NOTE: This function modifies the provided array in place.
@@ -535,7 +535,7 @@ library Arrays {
535535
offset = Math.min(offset, replacement.length);
536536
length = Math.min(length, Math.min(replacement.length - offset, array.length - pos));
537537

538-
// allocate and copy
538+
// replace
539539
assembly ("memory-safe") {
540540
mcopy(
541541
add(add(array, 0x20), mul(pos, 0x20)),
@@ -548,21 +548,21 @@ library Arrays {
548548
}
549549

550550
/**
551-
* @dev Moves the content of `array`, from `start` (included) to the end of `array` to the start of that array.
551+
* @dev Moves the content of `array`, from `start` (included) to the end of `array` to the start of that array,
552+
* and shrinks the array length accordingly, effectively overwriting the array with array[start:].
552553
*
553554
* NOTE: This function modifies the provided array in place. If you need to preserve the original array, use {slice} instead.
554-
* NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice[Javascript's `Array.splice`]
555555
*/
556556
function splice(bytes32[] memory array, uint256 start) internal pure returns (bytes32[] memory) {
557557
return splice(array, start, array.length);
558558
}
559559

560560
/**
561-
* @dev Moves the content of `array`, from `start` (included) to `end` (excluded) to the start of that array. The
561+
* @dev Moves the content of `array`, from `start` (included) to `end` (excluded) to the start of that array,
562+
* and shrinks the array length accordingly, effectively overwriting the array with array[start:end]. The
562563
* `end` argument is truncated to the length of the `array`.
563564
*
564565
* NOTE: This function modifies the provided array in place. If you need to preserve the original array, use {slice} instead.
565-
* NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice[Javascript's `Array.splice`]
566566
*/
567567
function splice(bytes32[] memory array, uint256 start, uint256 end) internal pure returns (bytes32[] memory) {
568568
// sanitize
@@ -581,7 +581,7 @@ library Arrays {
581581
/**
582582
* @dev Replaces elements in `array` starting at `pos` with all elements from `replacement`.
583583
*
584-
* Parameters are clamped to valid ranges (i.e. `pos` is clamped to `[0, array.length]`).
584+
* Parameters are clamped to valid ranges (e.g. `pos` is clamped to `[0, array.length]`).
585585
* If `pos >= array.length`, no replacement occurs and the array is returned unchanged.
586586
*
587587
* NOTE: This function modifies the provided array in place.
@@ -617,7 +617,7 @@ library Arrays {
617617
offset = Math.min(offset, replacement.length);
618618
length = Math.min(length, Math.min(replacement.length - offset, array.length - pos));
619619

620-
// allocate and copy
620+
// replace
621621
assembly ("memory-safe") {
622622
mcopy(
623623
add(add(array, 0x20), mul(pos, 0x20)),
@@ -630,21 +630,21 @@ library Arrays {
630630
}
631631

632632
/**
633-
* @dev Moves the content of `array`, from `start` (included) to the end of `array` to the start of that array.
633+
* @dev Moves the content of `array`, from `start` (included) to the end of `array` to the start of that array,
634+
* and shrinks the array length accordingly, effectively overwriting the array with array[start:].
634635
*
635636
* NOTE: This function modifies the provided array in place. If you need to preserve the original array, use {slice} instead.
636-
* NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice[Javascript's `Array.splice`]
637637
*/
638638
function splice(uint256[] memory array, uint256 start) internal pure returns (uint256[] memory) {
639639
return splice(array, start, array.length);
640640
}
641641

642642
/**
643-
* @dev Moves the content of `array`, from `start` (included) to `end` (excluded) to the start of that array. The
643+
* @dev Moves the content of `array`, from `start` (included) to `end` (excluded) to the start of that array,
644+
* and shrinks the array length accordingly, effectively overwriting the array with array[start:end]. The
644645
* `end` argument is truncated to the length of the `array`.
645646
*
646647
* NOTE: This function modifies the provided array in place. If you need to preserve the original array, use {slice} instead.
647-
* NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice[Javascript's `Array.splice`]
648648
*/
649649
function splice(uint256[] memory array, uint256 start, uint256 end) internal pure returns (uint256[] memory) {
650650
// sanitize
@@ -663,7 +663,7 @@ library Arrays {
663663
/**
664664
* @dev Replaces elements in `array` starting at `pos` with all elements from `replacement`.
665665
*
666-
* Parameters are clamped to valid ranges (i.e. `pos` is clamped to `[0, array.length]`).
666+
* Parameters are clamped to valid ranges (e.g. `pos` is clamped to `[0, array.length]`).
667667
* If `pos >= array.length`, no replacement occurs and the array is returned unchanged.
668668
*
669669
* NOTE: This function modifies the provided array in place.
@@ -699,7 +699,7 @@ library Arrays {
699699
offset = Math.min(offset, replacement.length);
700700
length = Math.min(length, Math.min(replacement.length - offset, array.length - pos));
701701

702-
// allocate and copy
702+
// replace
703703
assembly ("memory-safe") {
704704
mcopy(
705705
add(add(array, 0x20), mul(pos, 0x20)),

contracts/utils/Bytes.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,28 @@ library Bytes {
9898
}
9999

100100
/**
101-
* @dev Moves the content of `buffer`, from `start` (included) to the end of `buffer` to the start of that buffer.
101+
* @dev Moves the content of `buffer`, from `start` (included) to the end of `buffer` to the start of that buffer,
102+
* and shrinks the buffer length accordingly, effectively overriding the content of buffer with buffer[start:].
102103
*
103104
* NOTE: This function modifies the provided buffer in place. If you need to preserve the original buffer, use {slice} instead
104-
* NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice[Javascript's `Array.splice`]
105105
*/
106106
function splice(bytes memory buffer, uint256 start) internal pure returns (bytes memory) {
107107
return splice(buffer, start, buffer.length);
108108
}
109109

110110
/**
111-
* @dev Moves the content of `buffer`, from `start` (included) to end (excluded) to the start of that buffer. The
112-
* `end` argument is truncated to the length of the `buffer`.
111+
* @dev Moves the content of `buffer`, from `start` (included) to `end` (excluded) to the start of that buffer,
112+
* and shrinks the buffer length accordingly, effectively overriding the content of buffer with buffer[start:end].
113+
* The `end` argument is truncated to the length of the `buffer`.
113114
*
114115
* NOTE: This function modifies the provided buffer in place. If you need to preserve the original buffer, use {slice} instead
115-
* NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice[Javascript's `Array.splice`]
116116
*/
117117
function splice(bytes memory buffer, uint256 start, uint256 end) internal pure returns (bytes memory) {
118118
// sanitize
119119
end = Math.min(end, buffer.length);
120120
start = Math.min(start, end);
121121

122-
// allocate and copy
122+
// move and resize
123123
assembly ("memory-safe") {
124124
mcopy(add(buffer, 0x20), add(add(buffer, 0x20), start), sub(end, start))
125125
mstore(buffer, sub(end, start))
@@ -163,7 +163,7 @@ library Bytes {
163163
offset = Math.min(offset, replacement.length);
164164
length = Math.min(length, Math.min(replacement.length - offset, buffer.length - pos));
165165

166-
// allocate and copy
166+
// replace
167167
assembly ("memory-safe") {
168168
mcopy(add(add(buffer, 0x20), pos), add(add(replacement, 0x20), offset), length)
169169
}

contracts/utils/LowLevelCall.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ library LowLevelCall {
2323
}
2424

2525
/// @dev Performs a Solidity function call using a low level `call` and returns the first 64 bytes of the result
26-
/// in the scratch space of memory. Useful for functions that return a tuple of single-word values.
26+
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
2727
///
2828
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
2929
/// and this function doesn't zero it out.
@@ -55,7 +55,7 @@ library LowLevelCall {
5555
}
5656

5757
/// @dev Performs a Solidity function call using a low level `staticcall` and returns the first 64 bytes of the result
58-
/// in the scratch space of memory. Useful for functions that return a tuple of single-word values.
58+
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
5959
///
6060
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
6161
/// and this function doesn't zero it out.
@@ -78,7 +78,7 @@ library LowLevelCall {
7878
}
7979

8080
/// @dev Performs a Solidity function call using a low level `delegatecall` and returns the first 64 bytes of the result
81-
/// in the scratch space of memory. Useful for functions that return a tuple of single-word values.
81+
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
8282
///
8383
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
8484
/// and this function doesn't zero it out.

contracts/utils/Memory.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ library Memory {
6868
}
6969
}
7070

71-
/// @dev Offset a memory slice (equivalent to self[start:] for calldata slices)
71+
/// @dev Offset a memory slice (equivalent to self[offset:] for calldata slices)
7272
function slice(Slice self, uint256 offset) internal pure returns (Slice) {
7373
if (offset > length(self)) Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS);
7474
return _asSlice(length(self) - offset, forward(_pointer(self), offset));
7575
}
7676

77-
/// @dev Offset and cut a Slice (equivalent to self[start:start+length] for calldata slices)
77+
/// @dev Offset and cut a Slice (equivalent to self[offset:offset+len] for calldata slices)
7878
function slice(Slice self, uint256 offset, uint256 len) internal pure returns (Slice) {
7979
if (offset + len > length(self)) Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS);
8080
return _asSlice(len, forward(_pointer(self), offset));

contracts/utils/RLP.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ library RLP {
5252
using Bytes for *;
5353
using Memory for *;
5454

55-
/// @dev The item is not properly formatted and cannot de decoded.
55+
/// @dev The item is not properly formatted and cannot be decoded.
5656
error RLPInvalidEncoding();
5757

5858
enum ItemType {
@@ -429,7 +429,7 @@ library RLP {
429429
}
430430

431431
/**
432-
* @dev Decodes an RLP `item`'s `length and type from its prefix.
432+
* @dev Decodes an RLP `item`'s length and type from its prefix.
433433
* Returns the offset, length, and type of the RLP item based on the encoding rules.
434434
*/
435435
function _decodeLength(Memory.Slice item) private pure returns (uint256, uint256, ItemType) {
@@ -468,7 +468,7 @@ library RLP {
468468
if (prefix <= LONG_OFFSET + SHORT_THRESHOLD) {
469469
// Case: Short list
470470
uint256 listLength = prefix - LONG_OFFSET;
471-
require(item.length() > listLength, RLPInvalidEncoding());
471+
require(itemLength > listLength, RLPInvalidEncoding());
472472
return (1, listLength, ItemType.List);
473473
} else {
474474
// Case: Long list

contracts/utils/RelayedCall.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pragma solidity ^0.8.20;
1515
*
1616
* For example, instead of `target.call(data)` where the target sees this contract as `msg.sender`, use
1717
* {relayCall} where the target sees a relay address as `msg.sender`.
18+
*
19+
* NOTE: This library uses the PUSH0 opcode that was introduced in the Shanghai hardfork. While this instruction is
20+
* now widely supported, developers using the library on exotic chains should verify that their target chain has
21+
* supports for EIP-3855.
1822
*/
1923
library RelayedCall {
2024
/// @dev Relays a call to the target contract through a dynamically deployed relay contract.

contracts/utils/cryptography/TrieProof.sol

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ library TrieProof {
123123
if (currentNodeIdLength != 32 || keccak256(encoded) != currentNodeId)
124124
return (_emptyBytesMemory(), ProofError.INVALID_LARGE_NODE);
125125
} else {
126-
// Small nodes must match directly
126+
// Short nodes must match directly
127127
if (currentNodeIdLength != encoded.length || bytes32(encoded) != currentNodeId)
128128
return (_emptyBytesMemory(), ProofError.INVALID_SHORT_NODE);
129129
}
@@ -146,12 +146,12 @@ library TrieProof {
146146
if (path.length == 0) {
147147
return (_emptyBytesMemory(), ProofError.EMPTY_PATH);
148148
}
149-
uint8 prefix = uint8(path[0]);
149+
uint8 prefix = uint8(path[0]); // path encoding nibble (node type + parity), see {Prefix}
150150
Memory.Slice keyRemainder = keyExpanded.asSlice().slice(keyIndex); // Remaining key to match
151151
Memory.Slice pathRemainder = path.asSlice().slice(2 - (prefix % 2)); // Path after the prefix
152152
uint256 pathRemainderLength = pathRemainder.length();
153153

154-
// pathRemainder must not be longer than keyRemainder, and it must be a prefix of it
154+
// pathRemainder must not be longer than keyRemainder and must match the start of keyRemainder
155155
if (
156156
pathRemainderLength > keyRemainder.length() ||
157157
!pathRemainder.equal(keyRemainder.slice(0, pathRemainderLength))
@@ -210,13 +210,21 @@ library TrieProof {
210210
/**
211211
* @dev Extracts the node ID (hash or raw data based on size)
212212
*
213-
* For small nodes (encoded length < 32 bytes) the node ID is the node content itself,
213+
* For short nodes (encoded length < 32 bytes) the node ID is the node content itself,
214214
* For larger nodes, the node ID is the hash of the encoded node data.
215215
*
216-
* NOTE: Under normal operation, the input should never be exactly 32-byte inputs. If such an input is provided,
217-
* it will be used directly, similarly to how small nodes are processed. The following traversal check whether
218-
* the next node is a large one, and whether its hash matches the raw 32 bytes we have here. If that is the case,
219-
* the value will be accepted. Otherwise, the next step will return an {INVALID_LARGE_NODE} error.
216+
* [NOTE]
217+
* ====
218+
* Under normal operation, the input should never be exactly 32 bytes nor empty.
219+
*
220+
* If a 32-byte input is provided, it is used directly (like short nodes). The next traversal step then checks
221+
* whether the next node is large and its hash matches those raw bytes. If that is not the case, it returns
222+
* {INVALID_LARGE_NODE}.
223+
*
224+
* If the input is empty (e.g. when traversing a branch node whose target child slot is empty, meaning the key
225+
* does not exist in the trie), this returns `nodeIdLength = 0` and the next iteration fails with {INVALID_LARGE_NODE} or
226+
* {INVALID_SHORT_NODE} depending on the next proof element, rather than a dedicated "key not in trie" error.
227+
* ====
220228
*/
221229
function _getNodeId(Memory.Slice node) private pure returns (bytes32 nodeId, uint256 nodeIdLength) {
222230
uint256 nodeLength = node.length();

0 commit comments

Comments
 (0)