Skip to content

Instantly share code, notes, and snippets.

@mariano-aguero
Created April 20, 2020 18:53
Show Gist options
  • Save mariano-aguero/1e3426b4c2f3cc853d25ac017c4daa91 to your computer and use it in GitHub Desktop.
Save mariano-aguero/1e3426b4c2f3cc853d25ac017c4daa91 to your computer and use it in GitHub Desktop.
FA12.ligo
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