Selaa lähdekoodia

Rewrite assembly slot offset for consistency (#5325)

Hadrien Croubois 5 kuukautta sitten
vanhempi
sitoutus
633a1c85ca

+ 1 - 1
contracts/account/utils/draft-ERC7579Utils.sol

@@ -204,7 +204,7 @@ library ERC7579Utils {
                 revert ERC7579DecodingError();
 
             assembly ("memory-safe") {
-                executionBatch.offset := add(add(executionCalldata.offset, arrayLengthOffset), 32)
+                executionBatch.offset := add(add(executionCalldata.offset, arrayLengthOffset), 0x20)
                 executionBatch.length := arrayLength
             }
         }

+ 1 - 1
contracts/governance/Governor.sol

@@ -794,7 +794,7 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
     function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
         // This is not memory safe in the general case, but all calls to this private function are within bounds.
         assembly ("memory-safe") {
-            value := mload(add(buffer, add(0x20, offset)))
+            value := mload(add(add(buffer, 0x20), offset))
         }
     }
 }

+ 2 - 2
contracts/token/ERC1155/utils/ERC1155Utils.sol

@@ -42,7 +42,7 @@ library ERC1155Utils {
                     revert IERC1155Errors.ERC1155InvalidReceiver(to);
                 } else {
                     assembly ("memory-safe") {
-                        revert(add(32, reason), mload(reason))
+                        revert(add(reason, 0x20), mload(reason))
                     }
                 }
             }
@@ -79,7 +79,7 @@ library ERC1155Utils {
                     revert IERC1155Errors.ERC1155InvalidReceiver(to);
                 } else {
                     assembly ("memory-safe") {
-                        revert(add(32, reason), mload(reason))
+                        revert(add(reason, 0x20), mload(reason))
                     }
                 }
             }

+ 2 - 2
contracts/token/ERC20/utils/ERC1363Utils.sol

@@ -53,7 +53,7 @@ library ERC1363Utils {
                 revert ERC1363InvalidReceiver(to);
             } else {
                 assembly ("memory-safe") {
-                    revert(add(32, reason), mload(reason))
+                    revert(add(reason, 0x20), mload(reason))
                 }
             }
         }
@@ -87,7 +87,7 @@ library ERC1363Utils {
                 revert ERC1363InvalidSpender(spender);
             } else {
                 assembly ("memory-safe") {
-                    revert(add(32, reason), mload(reason))
+                    revert(add(reason, 0x20), mload(reason))
                 }
             }
         }

+ 1 - 1
contracts/token/ERC721/utils/ERC721Utils.sol

@@ -41,7 +41,7 @@ library ERC721Utils {
                     revert IERC721Errors.ERC721InvalidReceiver(to);
                 } else {
                     assembly ("memory-safe") {
-                        revert(add(32, reason), mload(reason))
+                        revert(add(reason, 0x20), mload(reason))
                     }
                 }
             }

+ 1 - 2
contracts/utils/Address.sol

@@ -140,8 +140,7 @@ library Address {
         if (returndata.length > 0) {
             // The easiest way to bubble the revert reason is using memory via assembly
             assembly ("memory-safe") {
-                let returndata_size := mload(returndata)
-                revert(add(32, returndata), returndata_size)
+                revert(add(returndata, 0x20), mload(returndata))
             }
         } else {
             revert Errors.FailedCall();

+ 2 - 2
contracts/utils/Bytes.sol

@@ -93,7 +93,7 @@ library Bytes {
         // allocate and copy
         bytes memory result = new bytes(end - start);
         assembly ("memory-safe") {
-            mcopy(add(result, 0x20), add(buffer, add(start, 0x20)), sub(end, start))
+            mcopy(add(result, 0x20), add(add(buffer, 0x20), start), sub(end, start))
         }
 
         return result;
@@ -108,7 +108,7 @@ library Bytes {
     function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
         // This is not memory safe in the general case, but all calls to this private function are within bounds.
         assembly ("memory-safe") {
-            value := mload(add(buffer, add(0x20, offset)))
+            value := mload(add(add(buffer, 0x20), offset))
         }
     }
 }

+ 2 - 2
contracts/utils/Strings.sol

@@ -48,7 +48,7 @@ library Strings {
             string memory buffer = new string(length);
             uint256 ptr;
             assembly ("memory-safe") {
-                ptr := add(buffer, add(32, length))
+                ptr := add(add(buffer, 0x20), length)
             }
             while (true) {
                 ptr--;
@@ -484,7 +484,7 @@ library Strings {
     function _unsafeReadBytesOffset(bytes memory buffer, uint256 offset) private pure returns (bytes32 value) {
         // This is not memory safe in the general case, but all calls to this private function are within bounds.
         assembly ("memory-safe") {
-            value := mload(add(buffer, add(0x20, offset)))
+            value := mload(add(add(buffer, 0x20), offset))
         }
     }
 }