-
Notifications
You must be signed in to change notification settings - Fork 6
Assignment 2
Released 5 October, due 19 October at 11:59pm
In this assignment we'll be exploring Ethereum, and in particular the DAO (Decentralized Autonomous Organization). You'll be implementing portions of something like the DAO in Solidity. Phase 1 is notably longer than the other phases. Read everything (including the written portion) before you start coding.
First, in dao.sol implement a smart contract which has the following data and operations:
- A constructor which saves the identity of the creator
- An initial
totalBalanceof0.0 - A
balancesmapping from addresses to amounts - A default
valuationof1.0 - A default
curator, the creator -
delegateCuratorwhich the curator can call to change the curator to another address this cannot be called while an unsealed proposal exists -
depositwhich can be paid into to gain tokens (saved inbalancesandtotalBalance) atvaluationexchange rate -
withdrawwhich pays eth out at a rate ofvaluationfor a specified number of tokens
- this cannot be called on tokens which are in a proposal
- this must fail if
balancesortotalBalanceare insufficient
- A
getBalancefunction for an address -
createProposalwhich the curator can call to create a new proposal with only 1 unsealed proposal can exist at a given time -
votewhich commits a user's tokens toyesornofor a given proposal - Votes cannot be changed
- A deposit made by someone who has voted also commits the new tokens to their vote
- Once a proposal has more than
50%of the tokens which existed at the time of its creation onyesornoit is sealed - A sealed proposal cannot be voted on
- If the majority says
noall tokens are released back for future votes andvaluationis unchanged - If the majority says
yesall tokens are released back for future votes andvaluationis multiplied by a random value from0.0to10.0(increments of0.1) - This random value must be selected from a normal distribution centered at
2.0 - If
valuationhits0.0all tokens are invalidated (totalBalanceandbalancesreset) andvaluationgoes to1.0
Copy dao.sol to race.sol and make your withdraw function vulnerable to a race-to-empty attack as described
in vessenes blog linked in the resources below, if it's not already (ignoring the send caveat). Fix your dao.sol
with remediation approach 1.
Copy dao.sol to split.sol and add a split function. This function:
- Can only be called by someone who has voted on a proposal which is not yet sealed
- Once the proposal is sealed, if a voter has
split, their tokens can be withdrawn at the previousvaluationunless the valuation has become0.0(then there's nototalBalanceto withdraw) - A voter who has
splitcannotdeposituntil the proposal is sealed - Additionally make the
splitwithdrawal vulnerable to the race-to-empty attack
Submit 1-2 paragraph answers to the following questions/prompts:
- Describe your experience writing Solidity code. What was easy, what was hard, what surprised you?
- Describe the
gascosts for the operation ofdao.sol - What types of attack would the contract
dao.solneed to consider and defend against? - Does your implementation in
dao.soldefend against these attacks? - Describe the attack which exploits
race.soland how someone can steal fromtotalBalance - These attacks are similar to what happened to the actual DAO, but not exactly the same. What happened in the actual DAO?
- Read about and describe the stalking attack which the DAO enabled, and the DAO rebuttal
- https://remix.ethereum.org/#optimize=false&version=soljson-v0.5.1+commit.c8a2cb62.js
- https://solidity.readthedocs.io/en/v0.5.4/introduction-to-smart-contracts.html
- https://solidity.readthedocs.io/en/v0.5.4/solidity-by-example.html
- https://solidity.readthedocs.io/en/v0.5.4/solidity-in-depth.html
- http://hackingdistributed.com/2016/06/18/analysis-of-the-dao-exploit/
- https://vessenes.com/more-ethereum-attacks-race-to-empty-is-the-real-deal/
This is an individual assignment, you are not allowed to collaborate. Submit the written portion and code separately via Gradescope. Anything aside from typed PDFs for the written portion will receive zero credit. Document code thoroughly!