Skip to content

Instantly share code, notes, and snippets.

@petejkim
Last active December 21, 2020 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petejkim/ee5462c1109bdfc13a9875bce0524e53 to your computer and use it in GitHub Desktop.
Save petejkim/ee5462c1109bdfc13a9875bce0524e53 to your computer and use it in GitHub Desktop.
USDC v2: Upgrading a $1.4B Token - sload/sstore example
contract Foo {
bytes32 private constant NUM_SLOT = keccak256("Foo.num");
function num() public view returns (uint256 val) {
bytes32 slot = NUM_SLOT;
assembly {
val := sload(slot)
}
}
function setNum(uint256 val) public {
bytes32 slot = NUM_SLOT;
assembly {
sstore(slot, val)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment