Last active
September 14, 2020 09:24
-
-
Save nikita-fuchs/d98676dd282d25c4b7fb8b215cd452c2 to your computer and use it in GitHub Desktop.
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
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