Created
April 20, 2020 18:53
-
-
Save mariano-aguero/1e3426b4c2f3cc853d25ac017c4daa91 to your computer and use it in GitHub Desktop.
FA12.ligo
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
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 allowed: 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 allowed =/= 0n then failwith("UnsafeAllowanceChange"); | |
else block { | |
// TODO: maybe this need a patch ? | |
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