Created
September 2, 2026 19:40
-
-
Save DanielVF/8ac095c6cc5f1d1b1a99b8d8004961c6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| library PStore { | |
| function pload(uint256 memoryStart, uint256 slotStart, uint256 slotCount) internal view { | |
| assembly { | |
| function run(memoryEnd, slot, memoryCursor) { | |
| for {} xor(memoryCursor, memoryEnd) {} { | |
| mstore(memoryCursor, sload(slot)) | |
| // memoryCursor is already at the top. | |
| memoryCursor := add(memoryCursor, 0x20) | |
| // slot is immediately below memoryCursor. | |
| slot := add(slot, 1) | |
| } | |
| } | |
| if shr(251, slotCount) { invalid() } | |
| run(add(memoryStart, shl(5, slotCount)), slotStart, memoryStart) | |
| } | |
| } | |
| function pstore(uint256 memoryStart, uint256 slotStart, uint256 slotCount) internal { | |
| assembly { | |
| function run(memoryEnd, slot, memoryCursor) { | |
| for {} xor(memoryCursor, memoryEnd) {} { | |
| sstore(slot, mload(memoryCursor)) | |
| memoryCursor := add(memoryCursor, 0x20) | |
| slot := add(slot, 1) | |
| } | |
| } | |
| if shr(251, slotCount) { invalid() } | |
| run(add(memoryStart, shl(5, slotCount)), slotStart, memoryStart) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment