Created
July 2, 2023 18:27
-
-
Save ylv-io/7635de608159507cc66dd2d669c7cc32 to your computer and use it in GitHub Desktop.
External Storage Read
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extsload(bytes32 slot) external view returns (bytes32 value) { | |
/// @solidity memory-safe-assembly | |
assembly { | |
value := sload(slot) | |
} | |
} | |
function extsload(bytes32 startSlot, uint256 nSlots) external view returns (bytes memory) { | |
bytes memory value = new bytes(32 * nSlots); | |
/// @solidity memory-safe-assembly | |
assembly { | |
for { let i := 0 } lt(i, nSlots) { i := add(i, 1) } { | |
mstore(add(value, mul(add(i, 1), 32)), sload(add(startSlot, i))) | |
} | |
} | |
return value; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment