Created
October 30, 2020 21:44
-
-
Save aodhgan/5be911167c2126c6b6a2efb124556da4 to your computer and use it in GitHub Desktop.
gastoken_free.sol
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
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