Skip to content

Instantly share code, notes, and snippets.

@nikita-fuchs
Last active September 14, 2020 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikita-fuchs/d98676dd282d25c4b7fb8b215cd452c2 to your computer and use it in GitHub Desktop.
Save nikita-fuchs/d98676dd282d25c4b7fb8b215cd452c2 to your computer and use it in GitHub Desktop.
include "List.aes"
contract SomeBasicToken =
record state = {
balances: map(address, int)} // define map for balances
stateful entrypoint init() : state = {
balances = {[Call.caller] = 1337}} // give the deployer some tokens
stateful entrypoint batch_transfer(receivers : list(address), value : int) =
let count = List.length(receivers)
let amount = count * value // <-------------- potential overflow here
let balance = state.balances[Call.caller]
require(count > 0 && count =< 20, "incorrect count")
// bypassable security check in next line:
require(value > 0 && balance >= amount, "incorrect value or balance")
// subtract tokens from sender
let substracted_balance = state.balances{ [Call.caller] = balance - amount}
put(state{ balances = substracted_balance })
// helpfer function to add tokens to recipients' balance
let add_balance_function =
(receiver) =>
let receiver_balance = state.balances[receiver]
let added_balance = state.balances{ [receiver] = receiver_balance + value}
put(state{ balances = added_balance })
// add tokens to recipients' balance
List.map(add_balance_function, receivers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment