The ethereum.org crowdsale tutorial: contributions run to a deadline against a goal, pay out a separate reward token, and are refunded if the goal is missed.
Historical Significance
The ethereum.org crowdsale tutorial was the worked example most token sales of the period started from, and its shape, a deadline, a goal, a fixed price and a refund if the goal is missed, is the one the sales of the following two years repeated. The flaws are instructive too: unchecked send() calls and an unbounded refund loop are exactly the failures auditors spent the next years writing up.
Context
By 2016 the ethereum.org tutorial had been rewritten around the transfer interface that ERC-20 was standardising, and its crowdsale took its funding goal and token price in whole ether rather than wei. Copies of it went on chain steadily through the year, most of them as trials with short deadlines and small goals rather than as real sales.
Key Facts
Description
The crowdfunding contract from the ethereum.org tutorial. Its constructor fixes the beneficiary, the funding goal in whole ether, the length of the campaign in minutes, the price of one reward token in whole ether, and the token contract that pays contributors. None of them can be changed afterwards.
Contributions arrive through the fallback function, which records the sender and amount in a public funders array and calls transfer on the reward token for the amount divided by the price. After the deadline anyone may call checkGoalReached(): if the goal was met the balance is sent to the beneficiary, otherwise the contract loops over the funders and refunds them, and in both cases whatever remains is swept to the beneficiary and the sale is marked closed.
The reward tokens must already be held by this contract when the sale opens, and nothing checks that they are. The refund loop is unbounded and no send() return value is checked, so a campaign with many contributors can leave funds it cannot pay out.
This one pays 0x5a27334e0167781c373aeac1cf7fa32c84c3fa51 on success. It was opened with a goal of 50 ether, a window of 30 minutes, and a price of 1 ether for one token, handing out the token at 0xdf5182b3fefe338d9badce30a586611a9aad8b5d.
Heuristic Analysis
The following characteristics were detected through bytecode analysis and may not be accurate.
Homestead Era
The first planned hard fork. Removed the canary contract, adjusted gas costs.
Bytecode Overview
Verified Source Available
This contract has verified source code on Etherscan.
Show source code (Solidity)
// Submitted by EthereumHistory (ethereumhistory.com)
contract token { mapping (address => uint) public coinBalanceOf; function token() {} function sendCoin(address receiver, uint amount) returns(bool sufficient) { } }
contract Crowdsale {
address public beneficiary;
uint public fundingGoal; uint public amountRaised; uint public deadline; uint public price;
token public tokenReward;
Funder[] public funders;
event FundTransfer(address backer, uint amount, bool isContribution);
/* data structure to hold information about campaign contributors */
struct Funder {
address addr;
uint amount;
}
/* at initialization, setup the owner */
function Crowdsale(address _beneficiary, uint _fundingGoal, uint _duration, uint _price, token _reward) {
beneficiary = _beneficiary;
fundingGoal = _fundingGoal;
deadline = now + _duration * 1 minutes;
price = _price;
tokenReward = token(_reward);
}
/* The function without name is the default function that is called whenever anyone sends funds to a contract */
function () {
uint amount = msg.value;
funders[funders.length++] = Funder({addr: msg.sender, amount: amount});
amountRaised += amount;
tokenReward.sendCoin(msg.sender, amount / price);
FundTransfer(msg.sender, amount, true);
}
modifier afterDeadline() { if (now >= deadline) _ }
/* checks if the goal or time limit has been reached and ends the campaign */
function checkGoalReached() afterDeadline {
if (amountRaised >= fundingGoal){
beneficiary.send(amountRaised);
FundTransfer(beneficiary, amountRaised, false);
} else {
FundTransfer(0, 11, false);
for (uint i = 0; i < funders.length; ++i) {
funders[i].addr.send(funders[i].amount);
FundTransfer(funders[i].addr, funders[i].amount, false);
}
}
suicide(beneficiary);
}
}
External Links
Related contracts
Association
Same deployerThe ethereum.org democracy tutorial: token holders propose a transaction, vote on it for a fixed period, and the contract sends it if it passes.
0x96cd53...04d65bJune 28, 2016Association
Same eraThe ethereum.org democracy tutorial: token holders propose a transaction, vote on it for a fixed period, and the contract sends it if it passes.
0x8bfd7f...2aea40March 16, 2016Crowdsale
Same eraThe ethereum.org crowdsale tutorial: contributions run to a deadline against a goal, pay out a separate reward token, and are refunded if the goal is missed.
0x9af2b1...3a4858March 17, 2016Crowdsale
Same eraThe ethereum.org crowdsale tutorial: contributions run to a deadline against a goal, pay out a separate reward token, and are refunded if the goal is missed.
0xb83820...872c31March 24, 2016token
Same eraA shares contract that reports every balance as zero until three rounds of delegation have run, then answers with the delegated weight.
0xe81537...03263bMarch 26, 2016Contract 0x6960a6...8464a1
Same eraThe ethereum.org democracy tutorial: token holders propose a transaction, vote on it for a fixed period, and the contract sends it if it passes.
0x6960a6...8464a1March 26, 2016