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 0xbf62671ff2564ef16a2fe6037a20be93caf91991 on success. It was opened with a goal of 3 ether, a window of 500 hours, and a price of 1 ether for one token, handing out the token at 0xbf62671ff2564ef16a2fe6037a20be93caf91991.
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 { function transfer(address receiver, uint amount){ } }
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);
bool crowdsaleClosed = false;
/* data structure to hold information about campaign contributors */
struct Funder {
address addr;
uint amount;
}
/* at initialization, setup the owner */
function Crowdsale(address ifSucessfulSendTo, uint fundingGoalInEthers, uint durationInMinutes, uint etherCostOfEachToken, token addressOfTokenUsedAsReward) {
beneficiary = ifSucessfulSendTo;
fundingGoal = fundingGoalInEthers * 1 ether;
deadline = now + durationInMinutes * 1 minutes;
price = etherCostOfEachToken * 1 ether;
tokenReward = token(addressOfTokenUsedAsReward);
}
/* The function without name is the default function that is called whenever anyone sends funds to a contract */
function () {
if (crowdsaleClosed) throw;
uint amount = msg.value;
funders[funders.length++] = Funder({addr: msg.sender, amount: amount});
amountRaised += amount;
tokenReward.transfer(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 {
for (uint i = 0; i < funders.length; ++i) {
funders[i].addr.send(funders[i].amount);
FundTransfer(funders[i].addr, funders[i].amount, false);
}
}
beneficiary.send(this.balance); // send any remaining balance to beneficiary anyway
crowdsaleClosed = true;
}
}
External Links
Related contracts
Association
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, 2016Contract 0xdbbf29...30cace
Same eraBlock-height timelock (Homestead, Apr 2016) that releases its full ETH balance to a fixed beneficiary at releaseBlock, self-scheduling a wake-up via Piper Merri
0xdbbf29...30caceApril 4, 2016