Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Decentralized finance on Ethereum

Decentralized finance on Ethereum

Exactpro

April 08, 2022
Tweet

More Decks by Exactpro

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. 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
  4. 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/
  5. 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
  6. 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
  7. 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 $$ ££ $$ ££
  8. 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 $$ $$ $$ $$
  9. 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
  10. 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 $$ $$$
  11. 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 $$ $$ $$ $$$
  12. • 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
  13. 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
  14. ICO Smart contract Alice, Bob, Carol, and other participants send

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

    ETH. The smart contract sends back the ICO tokens. Bob Alice Contract Carol 20 $$$
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. • 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
  22. 28

  23. 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
  24. 31

  25. 32 Instructions for compiler Declare a state variable Functions to

    modify or retrieve the value of the variable
  26. 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
  27. 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
  28. 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
  29. 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
  30. Deadline: Monday, 18 April 2022 • Theory test https://forms.gle/t3MHfPFf7N4JNCaK8 •

    Implement smart contract on Solidity for simple p2p exchange of ERC20 tokens 42