Created
May 6, 2020 18:11
-
-
Save mariano-aguero/4d9e37034fd36c307f0aa0be1f09d880 to your computer and use it in GitHub Desktop.
Approve
This file contains hidden or 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
const emptyOps : list(operation) = list end; | |
function approve (const addressSpender : address; const value : nat; var store : store) : return is | |
block { | |
// If sender is the spender approving is not necessary | |
if sender = addressSpender then skip; | |
else block { | |
const senderAccount: account = getAccount(sender, store.accounts); | |
var allowance: nat := getAllowance(addressSpender, senderAccount.allowances); | |
// Changing allowance value from non-zero value to a non-zero value is forbidden to prevent the corresponding attack vector. | |
if allowance =/= 0n then failwith("UnsafeAllowanceChange"); | |
else block { | |
senderAccount.allowances[addressSpender] := value; | |
store.accounts[sender] := senderAccount; | |
} | |
} | |
} with (emptyOps, store); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment