Skip to content

Instantly share code, notes, and snippets.

@aodhgan
Last active October 30, 2020 21:27
Show Gist options
  • Save aodhgan/78424912a25fb78014c706a879e97c00 to your computer and use it in GitHub Desktop.
Save aodhgan/78424912a25fb78014c706a879e97c00 to your computer and use it in GitHub Desktop.
mint_gastoken.sol
function mint(uint256 value) public {
uint256 storage_location_array = STORAGE_LOCATION_ARRAY; // can't use constants inside assembly
if (value == 0) {
return;
}
// Read supply
uint256 supply;
assembly {
supply := sload(storage_location_array)
}
// Set memory locations in interval [l, r]
uint256 l = storage_location_array + supply + 1;
uint256 r = storage_location_array + supply + value;
assert(r >= l);
for (uint256 i = l; i <= r; i++) {
assembly {
sstore(i, 1)
}
}
// Write updated supply & balance
assembly {
sstore(storage_location_array, add(supply, value))
}
s_balances[msg.sender] += value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment