Update declaration of memory safe assembly blocks (#5172)

This commit is contained in:
Hadrien Croubois
2024-08-29 23:07:17 +02:00
committed by GitHub
parent 1e7ca3eea6
commit d8bbd34676
32 changed files with 91 additions and 182 deletions

View File

@ -43,8 +43,7 @@ const namespace = `\
* @dev Derive an ERC-7201 slot from a string (namespace).
*/
function erc7201Slot(string memory namespace) internal pure returns (bytes32 slot) {
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
mstore(0x00, sub(keccak256(add(namespace, 0x20), mload(namespace)), 1))
slot := and(keccak256(0x00, 0x20), not(0xff))
}
@ -65,8 +64,7 @@ function offset(bytes32 slot, uint256 pos) internal pure returns (bytes32 result
* @dev Derive the location of the first element in an array from the slot where the length is stored.
*/
function deriveArray(bytes32 slot) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
mstore(0x00, slot)
result := keccak256(0x00, 0x20)
}
@ -78,8 +76,7 @@ const mapping = ({ type }) => `\
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, ${type} key) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
mstore(0x00, key)
mstore(0x20, slot)
result := keccak256(0x00, 0x40)
@ -92,8 +89,7 @@ const mapping2 = ({ type }) => `\
* @dev Derive the location of a mapping element from the key.
*/
function deriveMapping(bytes32 slot, ${type} memory key) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
assembly ("memory-safe") {
let length := mload(key)
let begin := add(key, 0x20)
let end := add(begin, length)