Skip to content

Instantly share code, notes, and snippets.

@aodhgan
Created October 30, 2020 21:44
Show Gist options
  • Save aodhgan/5be911167c2126c6b6a2efb124556da4 to your computer and use it in GitHub Desktop.
Save aodhgan/5be911167c2126c6b6a2efb124556da4 to your computer and use it in GitHub Desktop.
gastoken_free.sol
function freeStorage(uint256 value) internal {
uint256 storage_location_array = STORAGE_LOCATION_ARRAY; // can't use constants inside assembly
// Read supply
uint256 supply;
assembly {
supply := sload(storage_location_array)
}
// Clear memory locations in interval [l, r]
uint256 l = storage_location_array + supply - value + 1;
uint256 r = storage_location_array + supply;
for (uint256 i = l; i <= r; i++) {
assembly {
sstore(i, 0)
}
}
// Write updated supply
assembly {
sstore(storage_location_array, sub(supply, value))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment