Slide 1

Slide 1 text

Rostislav Yavorskiy, PhD Head of Research at Exactpro VERIFICATION OF SMART CONTRACTS ON THE ETHEREUM BLOCKCHAIN Lecture #2 Decentralized finance on Ethereum 08 April 2022

Slide 2

Slide 2 text

Plan 1. Blockchain basics 2. Smart contracts 3. Cryptonomics, Initial coin offering (ICO) 4. Decentralized autonomous organization (DAO) 5. Solidity syntax, Ethereum virtual machine (EVM) 2

Slide 3

Slide 3 text

Blockchain basics 3

Slide 4

Slide 4 text

What is blockchain Bob Alice Carol David Elizabeth ¤90 ¤180 ¤90 ¤500 ¤220 4

Slide 5

Slide 5 text

A blockchain is a digital ledger of transactions that is duplicated and distributed across the entire network ID Source Account Dest Account Date/Time Amount (¤) 1 A24643 C98765 2022-01-10 15:22:16 180 2 B13579 C98765 2022-01-11 09:19:48 90 3 D85580 C98765 2022-01-11 12:42:33 90 4 E30003 A24643 2022-01-11 17:21:49 220 5 C98765 E30003 2022-01-12 10:09:57 500 … … … … 5

Slide 6

Slide 6 text

What is blockchain Bob Alice Carol David Elizabeth 6

Slide 7

Slide 7 text

A distributed ledger is a database that is consensually shared and synchronized across multiple sites, institutions, or geographies, accessible by multiple people. It allows transactions to have public "witnesses." The participant at each node of the network can access the recordings shared across that network and can own an identical copy of it. 7 https://www.investopedia.com/

Slide 8

Slide 8 text

Why mining? Bitcoin "mining" serves the function ● to validate and confirm new transactions to the blockchain (miners are getting paid for their work) ● to prevent double-spending by bad actors (it is extremely expensive to"hack" the network) It is also the way that new bitcoins are introduced into the system. https://supchina.com/ 8

Slide 9

Slide 9 text

Smart contracts 9

Slide 10

Slide 10 text

It's a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. Smart contracts are programs stored on a blockchain that run when predetermined conditions are met. A smart contract is an agreement between two people in the form of computer code. The transactions are processed automatically without a third party. A smart contract is a self-executing contract with the terms of the agreement between buyer and seller being directly written into lines of code. Smart contract definitions 10

Slide 11

Slide 11 text

Smart contract: p2p exchange Bob Alice Contract Bob sends ● amount in first currency, ● preferable exchange rate, ● gas. Alice sends ● amount in second currency, ● preferable exchange rate, ● gas. The smart contract program computes the exchange rate, the volume and sends the resulting amounts to Bob and Alice. 11 $$ ££ $$ ££

Slide 12

Slide 12 text

Smart contract: lottery Bob Alice Contract Alice, Bob, Carol, and other participants send: ● money to play on, ● seed number for the algorithm ● gas for the contract. The smart contract computes the winner using provably fair random number generator. The winner receives all the money from the contract. Carol 12 $$ $$ $$ $$

Slide 13

Slide 13 text

Smart contract: anonymous voting Bob Alice Contract Alice, Bob, Carol, and other participants send: ● vote, ● gas for the contract. The smart contract computes and publishes the winning decision. Carol result … 13

Slide 14

Slide 14 text

Smart contract: simple investment Alice Contract Alice sends: ● money to invest, ● asset specification, ● gas for the contract. The smart contract finds and purchases an asset. Then, after the specified period, sells it and sends the money back to Alice 14 $$ $$$

Slide 15

Slide 15 text

Smart contract: collective investment Bob Alice Contract Alice, Bob, Carol, and other participants send: ● preferable investment spec, ● money to invest, ● gas for the contract. The smart contract computes the collective decision, invests the money, and sends back the dividends. Carol … 15 $$ $$ $$ $$$

Slide 16

Slide 16 text

Cryptonomics 16

Slide 17

Slide 17 text

● Anyone can launch an ICO to raise money by selling tokens ● ICOs are unregulated, so investors must have a lot of caution and diligence ● ICOs are similar to initial public offerings (IPO), but coins issued in an ICO can also have utility for a software service or product Initial Coin Offering (ICO) https://ambisafe.com/ 17

Slide 18

Slide 18 text

All you need to do is a smart contract that can: ● Issue a specific amount of tokens at start ● Store all the token balances of all the users Initial Coin Offering (ICO) Contract 18

Slide 19

Slide 19 text

ICO Smart contract Alice, Bob, Carol, and other participants send ETH. The smart contract sends back the ICO tokens. Bob Alice Contract Carol 19 $$ $$ $$

Slide 20

Slide 20 text

ICO Smart contract Alice, Bob, Carol, and other participants send ETH. The smart contract sends back the ICO tokens. Bob Alice Contract Carol 20 $$$

Slide 21

Slide 21 text

ERC20 standard: fungible tokens Any one token is exactly equal to any other token; no tokens have special rights or behavior associated with them. ERC20 tokens are useful for ● digital currency, ● voting rights, ● staking etc. https://www.brookings.edu/ 21

Slide 22

Slide 22 text

ERC20 standard interface function name() public view returns (string) function symbol() public view returns (string) function decimals() public view returns (uint8) function totalSupply() public view returns (uint256) function balanceOf(address _owner) public view returns (uint256 balance) function transfer(address _to, uint256 _value) public returns (bool success) function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) function approve(address _spender, uint256 _value) public returns (bool success) function allowance(address _owner, address _spender) public view returns (uint256 remaining) event Transfer(address indexed _from, address indexed _to, uint256 _value) event Approval(address indexed _owner, address indexed _spender, uint256 _value) 22

Slide 23

Slide 23 text

ERC721 standard: non-fungible tokens NFTs can represent ownership over digital or physical assets: ● Physical property — houses, unique artwork ● Virtual collectables — unique pictures of kittens, collectable cards ● “Negative value” assets — loans, burdens and other responsibilities All houses are distinct and no two kittens are alike, and a loan usually has numerous details to make it unique. NFTs are distinguishable and you must track the ownership of each one separately. https://www.besttemplates.com/ 23

Slide 24

Slide 24 text

Decentralized Autonomous Organization (DAO) 24

Slide 25

Slide 25 text

Regulations and law enforcement implemented with computer algorithms is called (known as) ● government by algorithm ● algorithmic regulation ● regulation by algorithms ● algorithmic governance ● algocratic governance ● algorithmic legal order ● algocracy DAO philosophy http://www.thelowdownblog.com/ 25

Slide 26

Slide 26 text

DAO is a member-owned community with no centralized leadership The backbone of a DAO is its smart contract The contract defines the rules of the organization and holds the group's treasury Decisions are governed by proposals and voting Votes counted, and outcome implemented automatically without trusted intermediary DAO implementation https://riskgroupllc.com/ 26

Slide 27

Slide 27 text

● A charity – you can accept membership and donations from anyone in the world and the group can decide how they want to spend donations. ● A freelancer network – you could create a network of contractors who pool their funds for office spaces. ● Ventures and grants – you could create a venture fund that pools investment capital and votes on the investments. DAO examples https://cointelegraph.com 27

Slide 28

Slide 28 text

28

Slide 29

Slide 29 text

Solidity 29

Slide 30

Slide 30 text

Solidity is an object-oriented, high-level language for implementing smart contracts to govern the behaviour of accounts within the Ethereum state Solidity is a curly-bracket language influenced by C++, Python and JavaScript Solidity is statically typed, supports inheritance, libraries and complex user-defined types among other features 30

Slide 31

Slide 31 text

31

Slide 32

Slide 32 text

32 Instructions for compiler Declare a state variable Functions to modify or retrieve the value of the variable

Slide 33

Slide 33 text

Blockchain transactions A blockchain is a globally shared, transactional database. Everyone can read entries in the database just by participating in the network. If you want to change something in the database, you have to create a transaction which has to be accepted by all others. A transaction is a message that is sent from one account to another account. It can include binary data (which is called “payload”) and Ether. 33

Slide 34

Slide 34 text

Why transactions? To ensure that all such processing leaves the database in a consistent state. Example: Money transfer transaction account1.balance = account1.balance - sum account2.balance = account2.balance + sum A transactional system would make both entries pass or both entries would fail. 34

Slide 35

Slide 35 text

There are two kinds of accounts, which share the same address space: ● External accounts that are controlled by public-private key pairs (i.e. humans) ● Contract accounts which are controlled by the code (smart contracts). Every account has a balance in Ether, which can be modified by sending transactions that include Ether. The two types of accounts are treated equally by the Ethereum Virtual Machine (EVM). Ethereum accounts 35

Slide 36

Slide 36 text

What is blockchain Bob Alice Carol David Elizabeth 36

Slide 37

Slide 37 text

What is blockchain Bob Alice Carol David Elizabeth 37 Contract1 Contract2 Contract3

Slide 38

Slide 38 text

EVM is the runtime environment for smart contracts in Ethereum. EVM is completely isolated, which means that code running inside the EVM has no access to network, filesystem or other processes. Smart contracts have limited access to other smart contracts. The Ethereum Virtual Machine (EVM) 38

Slide 39

Slide 39 text

39 DOI: http://dx.doi.org/10.1145/2993600.2993611

Slide 40

Slide 40 text

Solidity in 2 hours https://www.youtube.com/watch?v=ipwxYa-F1uY Tutorialspoint https://www.tutorialspoint.com/solidity/ 101 blockchains https://101blockchains.com/solidity-tutorial/ Solidity tutorials 40

Slide 41

Slide 41 text

Home assignment

Slide 42

Slide 42 text

Deadline: Monday, 18 April 2022 ● Theory test https://forms.gle/t3MHfPFf7N4JNCaK8 ● Implement smart contract on Solidity for simple p2p exchange of ERC20 tokens 42

Slide 43

Slide 43 text

Questions? Thank you! 43