SlideShare a Scribd company logo
1 of 4
Download to read offline
New smart contract every week with €100
No intentional bugs
DAO Challenge
Please Rob My Smart Contracts
2016-08-30 - Ethereum Developer Meetup Amsterdam - sjors@sprovoost.nl - h>ps://dao-challenge.herokuapp.com/ 1
Buy tokens (), sell tokens refund()
Problem: sender.send can fail silently
contract DaoChallenge { // Version 1
modifier noEther() {if (msg.value > 0) throw; _}
/* This creates an array with all balances */
mapping (address => uint256) public tokenBalanceOf;
uint256 constant tokenPrice = 1000000000000000; // 1 finney
function DaoChallenge () {}
function () {
address sender = msg.sender;
if(tokenBalanceOf[sender] != 0) {
throw;
}
tokenBalanceOf[sender] = msg.value / tokenPrice;
}
function refund() noEther {
address sender = msg.sender;
uint256 tokenBalance = tokenBalanceOf[sender];
if (tokenBalance <= 0) { throw; }
tokenBalanceOf[sender] = 0;
sender.send(tokenBalance * tokenPrice);
}
}
2016-08-30 - Ethereum Developer Meetup Amsterdam - sjors@sprovoost.nl - h>ps://dao-challenge.herokuapp.com/ 2
Can you guess how to rob this?
contract DaoChallenge // Version 2
{
function DaoChallenge () {}
function () {
address sender = msg.sender;
uint256 amount = msg.value;
if (amount % tokenPrice != 0) {
throw;
}
tokenBalanceOf[sender] += amount / tokenPrice;
notifySellToken(amount, sender);
}
function withdrawEtherOrThrow(uint256 amount) {
bool result = msg.sender.call.value(amount)();
if (!result) {
throw;
}
}
function refund() noEther {
address sender = msg.sender;
uint256 tokenBalance = tokenBalanceOf[sender];
if (tokenBalance == 0) { throw; }
tokenBalanceOf[sender] = 0;
withdrawEtherOrThrow(tokenBalance * tokenPrice);
}
}
2016-08-30 - Ethereum Developer Meetup Amsterdam - sjors@sprovoost.nl - h>ps://dao-challenge.herokuapp.com/ 3
contract DaoChallenge // Version 3
{
function DaoChallenge () {}
function () {
address sender = msg.sender;
uint256 amount = msg.value;
if (amount % tokenPrice != 0) {
throw;
}
tokenBalanceOf[sender] += amount / tokenPrice;
notifySellToken(amount, sender);
}
function withdrawEtherOrThrow(uint256 amount) private {
bool result = msg.sender.call.value(amount)();
if (!result) {
throw;
}
}
function refund() noEther {
address sender = msg.sender;
uint256 tokenBalance = tokenBalanceOf[sender];
if (tokenBalance == 0) { throw; }
tokenBalanceOf[sender] = 0;
withdrawEtherOrThrow(tokenBalance * tokenPrice);
}
}
2016-08-30 - Ethereum Developer Meetup Amsterdam - sjors@sprovoost.nl - h>ps://dao-challenge.herokuapp.com/ 4

More Related Content

Viewers also liked

"Performance Analysis of In-Network Caching in Content-Centric Advanced Meter...
"Performance Analysis of In-Network Caching in Content-Centric Advanced Meter..."Performance Analysis of In-Network Caching in Content-Centric Advanced Meter...
"Performance Analysis of In-Network Caching in Content-Centric Advanced Meter...Khaled Ben Driss
 
The Ethereum ÐApp IDE: Mix
The Ethereum ÐApp IDE: MixThe Ethereum ÐApp IDE: Mix
The Ethereum ÐApp IDE: Mixgavofyork
 
NodeJS Blockchain.info Wallet
NodeJS Blockchain.info WalletNodeJS Blockchain.info Wallet
NodeJS Blockchain.info WalletSjors Provoost
 
Learning Solidity
Learning SolidityLearning Solidity
Learning SolidityArnold Pham
 
Ingredients for creating dapps
Ingredients for creating dappsIngredients for creating dapps
Ingredients for creating dappsStefaan Ponnet
 
Introduction to Ethereum
Introduction to EthereumIntroduction to Ethereum
Introduction to EthereumArnold Pham
 
The Ethereum Geth Client
The Ethereum Geth ClientThe Ethereum Geth Client
The Ethereum Geth ClientArnold Pham
 
Solidity Simple Tutorial EN
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial ENNicholas Lin
 
State of wifi_2016
State of wifi_2016State of wifi_2016
State of wifi_2016antitree
 
How smart are those smart contract
How smart are those smart contractHow smart are those smart contract
How smart are those smart contractRoman Mandeleil
 
Ethereum Smart Contract Tutorial
Ethereum Smart Contract TutorialEthereum Smart Contract Tutorial
Ethereum Smart Contract TutorialArnold Pham
 
AdsCash Coin: Ethereum Smart Contract based Cryptocurrency for AdWorld
AdsCash Coin: Ethereum Smart Contract based Cryptocurrency for AdWorldAdsCash Coin: Ethereum Smart Contract based Cryptocurrency for AdWorld
AdsCash Coin: Ethereum Smart Contract based Cryptocurrency for AdWorldNigel Mark Dias
 
Devcon2上海 参加報告
Devcon2上海 参加報告Devcon2上海 参加報告
Devcon2上海 参加報告Hiroyasu NOHATA
 

Viewers also liked (17)

"Performance Analysis of In-Network Caching in Content-Centric Advanced Meter...
"Performance Analysis of In-Network Caching in Content-Centric Advanced Meter..."Performance Analysis of In-Network Caching in Content-Centric Advanced Meter...
"Performance Analysis of In-Network Caching in Content-Centric Advanced Meter...
 
The Ethereum ÐApp IDE: Mix
The Ethereum ÐApp IDE: MixThe Ethereum ÐApp IDE: Mix
The Ethereum ÐApp IDE: Mix
 
NodeJS Blockchain.info Wallet
NodeJS Blockchain.info WalletNodeJS Blockchain.info Wallet
NodeJS Blockchain.info Wallet
 
Learning Solidity
Learning SolidityLearning Solidity
Learning Solidity
 
Ingredients for creating dapps
Ingredients for creating dappsIngredients for creating dapps
Ingredients for creating dapps
 
Introduction to Ethereum
Introduction to EthereumIntroduction to Ethereum
Introduction to Ethereum
 
The Ethereum Geth Client
The Ethereum Geth ClientThe Ethereum Geth Client
The Ethereum Geth Client
 
Build dapps 1:3 dev tools
Build dapps 1:3 dev toolsBuild dapps 1:3 dev tools
Build dapps 1:3 dev tools
 
The future of Blockchain
The future of BlockchainThe future of Blockchain
The future of Blockchain
 
Solidity Simple Tutorial EN
Solidity Simple Tutorial ENSolidity Simple Tutorial EN
Solidity Simple Tutorial EN
 
State of wifi_2016
State of wifi_2016State of wifi_2016
State of wifi_2016
 
How smart are those smart contract
How smart are those smart contractHow smart are those smart contract
How smart are those smart contract
 
Ethereum Smart Contract Tutorial
Ethereum Smart Contract TutorialEthereum Smart Contract Tutorial
Ethereum Smart Contract Tutorial
 
Wysiwig on Rails
Wysiwig on RailsWysiwig on Rails
Wysiwig on Rails
 
AdsCash Coin: Ethereum Smart Contract based Cryptocurrency for AdWorld
AdsCash Coin: Ethereum Smart Contract based Cryptocurrency for AdWorldAdsCash Coin: Ethereum Smart Contract based Cryptocurrency for AdWorld
AdsCash Coin: Ethereum Smart Contract based Cryptocurrency for AdWorld
 
Gnosis - Vision and crowdsale
Gnosis - Vision and crowdsaleGnosis - Vision and crowdsale
Gnosis - Vision and crowdsale
 
Devcon2上海 参加報告
Devcon2上海 参加報告Devcon2上海 参加報告
Devcon2上海 参加報告
 

Recently uploaded

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 

Recently uploaded (20)

ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 

Dao challenge - Ams Ethereum Developers - 2016-08-30

  • 1. New smart contract every week with €100 No intentional bugs DAO Challenge Please Rob My Smart Contracts 2016-08-30 - Ethereum Developer Meetup Amsterdam - sjors@sprovoost.nl - h>ps://dao-challenge.herokuapp.com/ 1
  • 2. Buy tokens (), sell tokens refund() Problem: sender.send can fail silently contract DaoChallenge { // Version 1 modifier noEther() {if (msg.value > 0) throw; _} /* This creates an array with all balances */ mapping (address => uint256) public tokenBalanceOf; uint256 constant tokenPrice = 1000000000000000; // 1 finney function DaoChallenge () {} function () { address sender = msg.sender; if(tokenBalanceOf[sender] != 0) { throw; } tokenBalanceOf[sender] = msg.value / tokenPrice; } function refund() noEther { address sender = msg.sender; uint256 tokenBalance = tokenBalanceOf[sender]; if (tokenBalance <= 0) { throw; } tokenBalanceOf[sender] = 0; sender.send(tokenBalance * tokenPrice); } } 2016-08-30 - Ethereum Developer Meetup Amsterdam - sjors@sprovoost.nl - h>ps://dao-challenge.herokuapp.com/ 2
  • 3. Can you guess how to rob this? contract DaoChallenge // Version 2 { function DaoChallenge () {} function () { address sender = msg.sender; uint256 amount = msg.value; if (amount % tokenPrice != 0) { throw; } tokenBalanceOf[sender] += amount / tokenPrice; notifySellToken(amount, sender); } function withdrawEtherOrThrow(uint256 amount) { bool result = msg.sender.call.value(amount)(); if (!result) { throw; } } function refund() noEther { address sender = msg.sender; uint256 tokenBalance = tokenBalanceOf[sender]; if (tokenBalance == 0) { throw; } tokenBalanceOf[sender] = 0; withdrawEtherOrThrow(tokenBalance * tokenPrice); } } 2016-08-30 - Ethereum Developer Meetup Amsterdam - sjors@sprovoost.nl - h>ps://dao-challenge.herokuapp.com/ 3
  • 4. contract DaoChallenge // Version 3 { function DaoChallenge () {} function () { address sender = msg.sender; uint256 amount = msg.value; if (amount % tokenPrice != 0) { throw; } tokenBalanceOf[sender] += amount / tokenPrice; notifySellToken(amount, sender); } function withdrawEtherOrThrow(uint256 amount) private { bool result = msg.sender.call.value(amount)(); if (!result) { throw; } } function refund() noEther { address sender = msg.sender; uint256 tokenBalance = tokenBalanceOf[sender]; if (tokenBalance == 0) { throw; } tokenBalanceOf[sender] = 0; withdrawEtherOrThrow(tokenBalance * tokenPrice); } } 2016-08-30 - Ethereum Developer Meetup Amsterdam - sjors@sprovoost.nl - h>ps://dao-challenge.herokuapp.com/ 4