Ethereum. Smart Contracts Programming Model

Similar documents
FXY TOKEN SMART CONTRACT AUDIT RESULTS FOR FIXY NETWORK LTD

Wanchain Hackathon Handbook San Jose

Secure Token Development and Deployment. Dmitry Khovratovich and Mikhail Vladimirov, University of Luxembourg and ABDK Consulting

Brown University. Yana Hrytsenko. Final Project: Blockchain for PKI: Using Blockchain data structure for Public Key. Infrastructure.

Lecture 10. A2 - will post tonight - due in two weeks

FanChain Contract Audit

Active Planning Committee John Lindsay, Patent Attorney Tony Schuman, Investment Advisor Todd Russell, Gov t Contract Opportunities

GUTS Token Sale Audit

Implementing and Mechanically Verifying Smart Contracts

Wanchain Documentation

Wanchain Documentation

LECTURE 2 BLOCKCHAIN TECHNOLOGY EVOLUTION

An Analysis of Atomic Swaps on and between Ethereum Blockchains Research Project I

The power of Blockchain: Smart Contracts. Foteini Baldimtsi

MYETHERWALLET GUIDE 1

Security Audit of FuzeX Smart Contract This report is public. ChainSecurity Ltd. January 11, 2018

BLOCKCHAIN CADEC Pär Wenåker & Peter Larsson

GENESIS VISION NETWORK

Hawk: The Blockchain Model of Cryptography and Privacy-Preserving Smart Contracts. Yashar Dehkan Asl

How to buy LIVE Token with Ethereum and Bitcoin step by step

Learn Blockchain Programming. Ali Dorri

A Java Framework for Smart Contracts

TABLE OF CONTENTS 1.0 TOKEN SALE SUMMARY INTRODUCTION HOW TO BUY LION HOW TO BUY LION WITH METAMASK

A Concurrent Perspective on Smart Contracts. 1st Workshop on Trusted Smart Contracts

Beerchain. Creating the beer-based cryptocurrency. Yellowpaper version 0.3, 3/11/2018

Securify: Practical Security Analysis of Smart Contracts

FLIP Token (FLP) How to Participate in the FLIP Token (FLP) Sale Event. 1 Disclaimer 2. 2 What You Will Need 2

Table of contents. Abstract. Disclaimer. Scope. Procedure. AS-IS overview. Audit overview. Conclusion. Appendix A. Automated tools reports 12

Pillar Token Code Review

MCFT: Multi-Class Fungible Token

Theta Token - SLIVER.tv Deposit Guide

For further information about the GRID token sale, please visit gridplus.io/token-sale.

QIIBEE Security Audit

kasko2go Token Contract Audit

The Technology behind Smart Contracts

Whitepaper Rcoin Global

Who wants to be a millionaire? A class in creating your own cryptocurrency

TeleX AI. Cryptocurrency Wallet and Exchange Services on Telegram. Telex AI Company Ltd telexai.com November 2017

DISTRIBUTION PLAN. Operation of EMMARES smart contract. EMA Token Allocation

HOW TO PARTICIPATE IN VESTARIN PRE-ICO & ICO with ETHERIUM

Plutus and Extended UTxO

CREDITS Web-version 2 Web-version specification CREDITS Desktop Client vs. Web-client What is the CREDITS Wallet? 2 1.

Smart Contract Security Tips. Ethereum devcon2 Sep Joseph Chow

ZILLIQA / ZILIKƏ/ NEXT GEN HIGH-THROUGHPUT BLOCKCHAIN PLATFORM DONG XINSHU, CEO JIA YAOQI, BLOCKCHAIN ZILLIQA.

Verifiable Computation in Smart Contracts

Knowledge Platform TOKEN SALE. GUIDELINE (MetaMask & MyEtherWallet)

CS 251: Bitcoin and Crypto Currencies Fall 2015

SECURITY AUDIT REPORT

Smart Contract Security Audit Report. Loopring Protocol Smart Contract version 2

DTX Token. Starter guide

Vladimir Groshev. COO, Project Coordinator.

ISSUSE AND FEATURES TO CONSIDER WHEN SELECTING A BLOCKCHAIN SYSTEM. Find us at

Token Sale. Participation guide

The promise and peril of smart contracts

Privacy-Enabled NFTs: User-Mintable, Non-Fungible Tokens With Private Off-Chain Data

Introduction to Blockchain

A living programming environment for a living blockchain

Christian Rossow CISPA, Saarland University, Saarland Informatics Campus. Johannes Krupp CISPA, Saarland University, Saarland Informatics Campus

What is Bitcoin? Consensus technology has the power to do for economics what the internet did for information - Dan Larimer

How Can I See My ENJ? 15. Acquiring Ether (ETH) 16

A SYSTEM FOR ENABLING SHORT-TERM FINANCING

Technical Specifications for Platform Development

MyEtherWallet Step by Step Tutorial

TOKEN PAPER.

Bob s Repair Contract Audit

Instruction for creating an Ethereum based wallet and MUH ICO participation

Short review of the Coinmama.com. Registration on the Coinmama

Token White Paper. Global marketplace based on Block chain for small-scale business I ver P a g e

How to Invest in the Gizer Token Sale. A guide for contributing to the Initial Offering of GZR Tokens

Mobilink-Network Partial List of Partners

Three-Dimensional Scalable Blockchain. Tokenomics draft v. 0.3 (En)

TABLE OF CONTENTS 1.0 TOKEN SALE SUMMARY INTRODUCTION HOW TO BUY LION HOW TO BUY LION WITH METAMASK

CS 251: Bitcoin and Cryptocurrencies Fall 2016

Smart!= Secure - Breaking Ethereum Smart Contracts. Elliot Ward & Jake Humphries

OW TO PARTICIPAT HOW TO PARTICIPATE

Abstraction: Distributed Ledger

a new cryptocurrency STK GLOBAL PAYMENTS USER GUIDE USER GUIDE: PARTICIPATING IN IN STK STK TOKEN TOKEN SALE USING SALE MYETHERWALLET

POLAR INTERNET SHARING, A CONNECTION OF CONSTELLATIONS

Technical White Paper of. MOAC Mother of All Chains. June 8 th, 2017

Building Decentralized Applications with Ethereum

Asch. A decentralized application platform based on side-chain technology V1.0.2

A decentralized application platform based on side-chain technology

ENEE 457: E-Cash and Bitcoin

Blockchain Bitcoin & Ethereum

Mobilink-Network Partial List of Partners

INX Tokenomics I

Prelude. The notes within this Whitepaper publication are intended to formally document the concepts and features of the Aegeus cryptocurrency.

Bitcoin, a decentralized and trustless protocol

Lina Token Generation Event

Enjin Coin Yellow Paper

How to use Fusioncoin Wallet

BUYING HEARDBEATS VIA KRAKEN

Ethereum. Campbell R. Harvey* Duke University and NBER. Ashwin Ramachandran Duke University. Brent Xu ConsenSys. Innovation and Cryptoventures

SmartDec icumulate.io Smart Contracts Security Analysis

Ergo platform. Dmitry Meshkov

How to Buy TRVR Tokens

Erays: Reverse Engineering Ethereum s Opaque Smart Contracts

XSN coin. TPoS Setup Guide.

Location-based Peer-to-Peer On-Demand Live video streaming and Sensor Mining. Technical and ICO Crowdfunding White Paper

How to use Fusioncoin Wallet

Transcription:

Cryptocurrency Technologies Recall: Bitcoin scripting: non Turing-complete limited/limiting Solutions: Add application-specific functionality in scripting of altcoin Create altcoin with Turing-complete scripting Smart Contracts Programming Model Smart Contract (Nick Szabo 1994):... is a computerized transaction protocol that executes the terms of a contract. Classical example of mechanized contract: Vending Machine In, contracts are stored in the blockchain. Written in Solidity programming language Users can make procedure calls to the contract. 1

Example: Namecoin in contract NameRegistry { mapping(bytes32 => address) public registrytable; function claimname(bytes32 name) { if (msg.value < 10) { throw; if (registrytable[name] == 0) { registrytable[name] = msg.sender; Namecoin in - Improvements contract NameRegistry { mapping(bytes32 => address) public registrytable; function claimname(bytes32 name) { if (msg.value < 10) { throw; if (registrytable[name] == 0) { registrytable[name] = msg.sender; 1. Add more data with mapping. 2. Require periodic reregistration last-updated field 3. Add function to withdraw funds suppors security features 2

Example: Simple Currency contract MyToken { /* This creates an array with all balances */ mapping (address => uint256) public balanceof; /* Initializes contract with initial supply tokens to the creator of the contract */ function MyToken( uint256 initialsupply ) { balanceof[msg.sender] = initialsupply; // Give the creator all initial tokens /* Send coins */ function transfer(address _to, uint256 _value) { if (balanceof[msg.sender] < _value) throw; // Check if sender has enough if (balanceof[_to] + _value < balanceof[_to]) throw; // Check for overflows balanceof[msg.sender] -= _value; // Subtract from the sender balanceof[_to] += _value; // Add the same to the recipient Some more basic Information /* Initializes contract with initial supply tokens to the creator of the contract */ function MyToken(uint256 initialsupply, string tokenname, uint8 decimalunits, string tokensymbol) { balanceof[msg.sender] = initialsupply; // Give the creator all initial tokens name = tokenname; // Set the name for display purposes symbol = tokensymbol; // Set the symbol for display purposes decimals = decimalunits; // Amount of decimals for display purposes 3

Events /* This generates a public event on the blockchain that will notify clients */ event Transfer(address indexed from, address indexed to, uint256 value); /* Send coins */ function transfer(address _to, uint256 _value) { if (_to == 0x0) throw; // Prevent transfer to 0x0 address if (balanceof[msg.sender] < _value) throw; // Check if sender has enough if (balanceof[_to] + _value < balanceof[_to]) throw; // Check for overflows balanceof[msg.sender] -= _value; // Subtract from the sender balanceof[_to] += _value; // Add the same to the recipient Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place Wallet 4

Deploying a Contract Deploying a Contract 5

Deploying a Contract Using the Contract 6

Watch Token... Improvement: Add Central Administrator contract owned { address public owner; function owned() { owner = msg.sender; modifier onlyowner { if (msg.sender!= owner) throw; _; function transferownership(address newowner) onlyowner { owner = newowner; 7

Adding Central Administrator contract MyToken is owned { /* Rest of the contract as usual */ Adding Central Administrator contract MyToken is owned { /* This creates an array with all balances */ mapping (address => uint256) public balanceof; /* Initializes contract with initial supply tokens to the creator of the contract */ function MyToken( uint256 initialsupply ) { balanceof[msg.sender] = initialsupply; // Give the creator all initial tokens /* Send coins */ function transfer(address _to, uint256 _value) { if (balanceof[msg.sender] < _value) throw; // Check if the sender has enough if (balanceof[_to] + _value < balanceof[_to]) throw; // Check for overflows balanceof[msg.sender] -= _value; // Subtract from the sender balanceof[_to] += _value; // Add the same to the recipient 8

Central Mint function minttoken(address target, uint256 mintedamount) onlyowner { balanceof[target] += mintedamount; totalsupply += mintedamount; Transfer(0, owner, mintedamount); Transfer(owner, target, mintedamount); contract owned {... modifier onlyowner { if (msg.sender!= owner) throw; _;... Improvement: Freezing Assets mapping (address => bool) public frozenaccount; event FrozenFunds(address target, bool frozen); function freezeaccount(address target, bool freeze) onlyowner { frozenaccount[target] = freeze; FrozenFunds(target, freeze); function transfer(address _to, uint256 _value) { if (frozenaccount[msg.sender]) throw;... 9

Improvement: Automatic Selling and Buying uint256 public sellprice; uint256 public buyprice; function setprices(uint256 newsellprice, uint256 newbuyprice) onlyowner { sellprice = newsellprice; buyprice = newbuyprice; Automated Selling and Buying function buy() payable returns (uint amount){ amount = msg.value / buyprice; // calculates the amount if (balanceof[this] < amount) throw; // checks if it has enough to sell balanceof[msg.sender] += amount; // adds the amount to buyer's balance balanceof[this] -= amount; // subtracts same from seller's bal. Transfer(this, msg.sender, amount); // execute an event about the change return amount; // ends function and returns 10

Automated Selling and Buying function sell(uint amount) returns (uint revenue){ if (balanceof[msg.sender] < amount ) throw; // checks if the sender has enough to sell balanceof[this] += amount; // adds the amount to owner's balance balanceof[msg.sender] -= amount; revenue = amount * sellprice; if (!msg.sender.send(revenue)) { throw; else { Transfer(msg.sender, this, amount); return revenue; // subtracts amount from seller's balance // sends ether to the seller: it's important // to do this last // to prevent recursion attacks // executes event reflecting on the change // ends function and returns Improvement: Autorefill uint minbalanceforaccounts; function setminbalance(uint minimumbalanceinfinney) onlyowner { minbalanceforaccounts = minimumbalanceinfinney * 1 finney; // 1 finney = 0.001 ether /* Send coins */ function transfer(address _to, uint256 _value) {... if(_to.balance<minbalanceforaccounts) _to.send(sell((minbalanceforaccounts-_to.balance)/sellprice)); 11

Improvement: Proof-of-Work function giveblockreward() { balanceof[block.coinbase] += 1; Example: Crowdfunding 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; mapping(address => uint256) public balanceof; bool fundinggoalreached = false; event GoalReached(address beneficiary, uint amountraised); event FundTransfer(address backer, uint amount, bool iscontribution); bool crowdsaleclosed = false; /* data structure to hold information about campaign contributors */... 12

Crowdfunding /* at initialization, setup the owner */ function Crowdsale( address ifsuccessfulsendto, ) { uint fundinggoalinethers, uint durationinminutes, uint ethercostofeachtoken, token addressoftokenusedasreward beneficiary = ifsuccessfulsendto; fundinggoal = fundinggoalinethers * 1 ether; deadline = now + durationinminutes * 1 minutes; price = ethercostofeachtoken * 1 ether; tokenreward = token(addressoftokenusedasreward); Crowdfunding: Raise Funds /* The function without name is the default function that is called whenever anyone sends funds to a contract */ function () payable { if (crowdsaleclosed) throw; uint amount = msg.value; balanceof[msg.sender] = amount; amountraised += amount; tokenreward.transfer(msg.sender, amount / price); FundTransfer(msg.sender, amount, true); 13

Crowdfunding: Deadline modifier afterdeadline() { if (now >= deadline) _; /* checks if goal / time limit has been reached; ends the campaign */ function checkgoalreached() afterdeadline { if (amountraised >= fundinggoal){ fundinggoalreached = true; GoalReached(beneficiary, amountraised); crowdsaleclosed = true; Closing Crowdfunding Round (1) function safewithdrawal() afterdeadline { if (!fundinggoalreached) { uint amount = balanceof[msg.sender]; balanceof[msg.sender] = 0; if (amount > 0) { if (msg.sender.send(amount)) { FundTransfer(msg.sender, amount, false); else { balanceof[msg.sender] = amount; if (fundinggoalreached && beneficiary == msg.sender) {... 14

Closing Crowdfunding Round (2) function safewithdrawal() afterdeadline { if (!fundinggoalreached) {... if (fundinggoalreached && beneficiary == msg.sender) { if (beneficiary.send(amountraised)) { FundTransfer(beneficiary, amountraised, false); else { //If we fail to send the funds to beneficiary, unlock funders balance fundinggoalreached = false; 15