Homework 8 SOlution

$30.00

Category:

Description

  1. Read about Ethereum smart contract security:

 

  1. https://consensys.github.io/smart-contract-best-practices/

 

  1. Your score on the homework will be reduced if you submit insecure code.

 

  1. Start up the vagrant-managed virtual machine included in the homework 8 zip, log into it using ssh. Then, start the Ethereum node server, and then use truffle to test the provided contracts. The tests should run, but most should not pass. Note: You must run “npm install” once under the homework8/auction directory before running truffle. The command installs code packages needed for the project.

 

  1. Read about Dutch auctions: https://en.wikipedia.org/wiki/Dutch_auction

 

  1. Read and thoroughly understand the provided code

 

  1. contracts/DutchAuction.sol: an incomplete, skeletal implementation of a Dutch auction.

 

  1. test/<k>_dutch_auction.js: mocha tests for the contract

 

  1. test/framework.js: a testing harness to make tests easier to write

 

  1. Part A: You will write a smart contract that implements a Dutch auction.

 

  1. The seller instantiates a DutchAuction contract to manage the auction of a single, physical item at a single auction event. The contract is initialized with the following parameters:

 

  1. reservePrice: the minimum amount of wei that the seller is willing to accept for the item

 

  1. numBlocksAuctionOpen: the number of blockchain blocks that the auction is open for

 

  • offerPriceDecrement: the amount of wei that the auction price should decrease by during each subsequent block.

 

  1. judgeAddress: used by another part in this assignment.

 

  1. The seller is the owner of the contract.

 

  1. The auction begins at the block in which the contract is created.

 

  1. The initial price of the item is derived from reservePrice, numBlocksAuctionOpen, and offerPriceDecrement: initialPrice = reservePrice + numBlocksAuctionOpen*offerPriceDecrement

 

  1. A bid can be submitted by any Ethereum externally-owned account.

 

  1. The first bid processed by the contract that sends wei greater than or equal to the current price is the winner. The wei should be transferred immediately to the sender and the contract should not accept any more bids. All bids besides the winning bid should be refunded immediately.

 

  1. Part B: You will enhance the DutchAuction contract so that a judge can be designated for the auction. The judge behaves like an escrow in that he ensures that the seller received the wei of the winning bid if and only if the winner receives the item. A judge is specified by the judgeAddress parameter in the contract constructor. If a judgeAddress is not provided then, the contract should behave exactly as in Part A. However, if a judge is specified, then the behavior of the contract should be enhanced as follows:

 

  1. The wei of the winning bid is no longer automatically sent to the seller.

 

  1. Instead, a call to the finalize() function is now required after the winning bid is made, which will send the wei of the winning bid to the seller.

 

  1. The finalize() function can either be called by the judge or by the winner. The winner is expected to call this function to acknowledge that he received the physical item. If the winner doesn’t call it, the judge may intervene and call the finalize() function himself to forcibly send the wei to the seller.

 

  1. If the winner does not call finalize() and the judge also does not call finalize, then the judge can call the refund() function to send the wei of the bid back to the winner. You must ensure that the judge can only call one of these functions once and that the judge cannot send the wei to himself.

 

  1. Notes:

 

  1. You may assume Ethereum block numbers are sequential and consecutive.

 

  1. The ganache-cli test utility is configured by default to generate a new block for each transaction submitted to the local Ethereum test network. You may assume this behavior when writing your tests.

 

  1. Minimal tests are provided for you, but you are required to thoroughly test your work. The tests used to grade your submission will be different than the provided tests.

 

  1. You may only make modifications to DutchAuction.sol. All other code changes will be ignored during grading.

 

  1. Truffle may not properly recompile your code unless you first delete the build directory and then run

 

“truffle compile”.

 

 

Acknowledgement: This homework is based on an assignment designed at Stanford University.


error: Content is protected !!