Skip to content

Instantly share code, notes, and snippets.

@ylv-io
Created July 2, 2023 18:27
Show Gist options
  • Save ylv-io/7635de608159507cc66dd2d669c7cc32 to your computer and use it in GitHub Desktop.
Save ylv-io/7635de608159507cc66dd2d669c7cc32 to your computer and use it in GitHub Desktop.
External Storage Read
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