Skip to content

Commit 633a1c8

Browse files
authored
Rewrite assembly slot offset for consistency (#5325)
1 parent bdf8aff commit 633a1c8

File tree

8 files changed

+12
-13
lines changed

8 files changed

+12
-13
lines changed

contracts/account/utils/draft-ERC7579Utils.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ library ERC7579Utils {
204204
revert ERC7579DecodingError();
205205

206206
assembly ("memory-safe") {
207-
executionBatch.offset := add(add(executionCalldata.offset, arrayLengthOffset), 32)
207+
executionBatch.offset := add(add(executionCalldata.offset, arrayLengthOffset), 0x20)
208208
executionBatch.length := arrayLength
209209
}
210210
}

contracts/governance/Governor.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
794794
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
795795
// This is not memory safe in the general case, but all calls to this private function are within bounds.
796796
assembly ("memory-safe") {
797-
value := mload(add(buffer, add(0x20, offset)))
797+
value := mload(add(add(buffer, 0x20), offset))
798798
}
799799
}
800800
}

contracts/token/ERC1155/utils/ERC1155Utils.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ library ERC1155Utils {
4242
revert IERC1155Errors.ERC1155InvalidReceiver(to);
4343
} else {
4444
assembly ("memory-safe") {
45-
revert(add(32, reason), mload(reason))
45+
revert(add(reason, 0x20), mload(reason))
4646
}
4747
}
4848
}
@@ -79,7 +79,7 @@ library ERC1155Utils {
7979
revert IERC1155Errors.ERC1155InvalidReceiver(to);
8080
} else {
8181
assembly ("memory-safe") {
82-
revert(add(32, reason), mload(reason))
82+
revert(add(reason, 0x20), mload(reason))
8383
}
8484
}
8585
}

contracts/token/ERC20/utils/ERC1363Utils.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ library ERC1363Utils {
5353
revert ERC1363InvalidReceiver(to);
5454
} else {
5555
assembly ("memory-safe") {
56-
revert(add(32, reason), mload(reason))
56+
revert(add(reason, 0x20), mload(reason))
5757
}
5858
}
5959
}
@@ -87,7 +87,7 @@ library ERC1363Utils {
8787
revert ERC1363InvalidSpender(spender);
8888
} else {
8989
assembly ("memory-safe") {
90-
revert(add(32, reason), mload(reason))
90+
revert(add(reason, 0x20), mload(reason))
9191
}
9292
}
9393
}

contracts/token/ERC721/utils/ERC721Utils.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ library ERC721Utils {
4141
revert IERC721Errors.ERC721InvalidReceiver(to);
4242
} else {
4343
assembly ("memory-safe") {
44-
revert(add(32, reason), mload(reason))
44+
revert(add(reason, 0x20), mload(reason))
4545
}
4646
}
4747
}

contracts/utils/Address.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ library Address {
140140
if (returndata.length > 0) {
141141
// The easiest way to bubble the revert reason is using memory via assembly
142142
assembly ("memory-safe") {
143-
let returndata_size := mload(returndata)
144-
revert(add(32, returndata), returndata_size)
143+
revert(add(returndata, 0x20), mload(returndata))
145144
}
146145
} else {
147146
revert Errors.FailedCall();

contracts/utils/Bytes.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ library Bytes {
9393
// allocate and copy
9494
bytes memory result = new bytes(end - start);
9595
assembly ("memory-safe") {
96-
mcopy(add(result, 0x20), add(buffer, add(start, 0x20)), sub(end, start))
96+
mcopy(add(result, 0x20), add(add(buffer, 0x20), start), sub(end, start))
9797
}
9898

9999
return result;
@@ -108,7 +108,7 @@ library Bytes {
108108
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
109109
// This is not memory safe in the general case, but all calls to this private function are within bounds.
110110
assembly ("memory-safe") {
111-
value := mload(add(buffer, add(0x20, offset)))
111+
value := mload(add(add(buffer, 0x20), offset))
112112
}
113113
}
114114
}

contracts/utils/Strings.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ library Strings {
4848
string memory buffer = new string(length);
4949
uint256 ptr;
5050
assembly ("memory-safe") {
51-
ptr := add(buffer, add(32, length))
51+
ptr := add(add(buffer, 0x20), length)
5252
}
5353
while (true) {
5454
ptr--;
@@ -484,7 +484,7 @@ library Strings {
484484
function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
485485
// This is not memory safe in the general case, but all calls to this private function are within bounds.
486486
assembly ("memory-safe") {
487-
value := mload(add(buffer, add(0x20, offset)))
487+
value := mload(add(add(buffer, 0x20), offset))
488488
}
489489
}
490490
}

0 commit comments

Comments
 (0)