Last active
March 20, 2023 12:48
-
-
Save veridelisi/02a560d14f283c25c43dee34865aa56d to your computer and use it in GitHub Desktop.
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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
contract StorageContract { | |
uint256 a = 9; // Slot 0 | |
uint256 b = 8; // Slot 1 | |
uint256 c = 7; // Slot 2 | |
uint256 d = 6; // Slot 3 | |
function readStorageSlot0(uint yournumber) public view returns (bytes32 result) { | |
assembly { | |
result := sload(yournumber) | |
} | |
} | |
function getSlotNumbers() public pure returns(uint256 slotA, uint256 slotB, uint256 slotC, uint256 slotD) { | |
assembly { | |
slotA := a.slot | |
slotB := b.slot | |
slotC := c.slot | |
slotD := d.slot | |
} | |
} | |
function getVariableOffsets() public view returns(uint256 offsetA, uint256 offsetB, uint256 offsetC, uint256 offsetD) { | |
assembly { | |
offsetA := a.offset | |
offsetB := b.offset | |
offsetC := c.offset | |
offsetD := d.offset | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment