Skip to content

Instantly share code, notes, and snippets.

@cwhinfrey
Created November 7, 2018 18:44
Show Gist options
  • Save cwhinfrey/545bdf5457558dd8fa7e8e922a00715f to your computer and use it in GitHub Desktop.
Save cwhinfrey/545bdf5457558dd8fa7e8e922a00715f to your computer and use it in GitHub Desktop.
MemoryAndStorageViewer.sol
contract MemoryAndStorageViewer {
uint256 storageVar1 = 23;
bytes32 storageVar2 = 0x12345;
uint8 storageVar3 = 55;
uint8 storageVar4 = 123;
function printStorage()
public
view
returns (
bytes32 slot0,
bytes32 slot1,
bytes32 slot2,
bytes32 slot3,
bytes32 slot4,
bytes32 slot5,
bytes32 slot6,
bytes32 slot7,
bytes32 slot8,
bytes32 slot9
) {
assembly {
slot0 := sload(0x000)
slot1 := sload(0x020)
slot2 := sload(0x040)
slot3 := sload(0x060)
slot4 := sload(0x080)
slot5 := sload(0x0a0)
slot6 := sload(0x0c0)
slot7 := sload(0x0e0)
slot8 := sload(0x100)
slot9 := sload(0x120)
}
}
function printMemory(
bytes32 arg1,
bytes arg2,
uint256 arg3
)
public
view
returns (
bytes32 slot0,
bytes32 slot1,
bytes32 slot2,
bytes32 slot3,
bytes32 slot4,
bytes32 slot5,
bytes32 slot6,
bytes32 slot7,
bytes32 slot8,
bytes32 slot9
) {
uint var1 = 23;
string memory var2 = "hello";
uint256 var3 = 12345;
assembly {
slot0 := mload(0x000)
slot1 := mload(0x020)
slot2 := mload(0x040)
slot3 := mload(0x060)
slot4 := mload(0x080)
slot5 := mload(0x0a0)
slot6 := mload(0x0c0)
slot7 := mload(0x0e0)
slot8 := mload(0x100)
slot9 := mload(0x120)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment