Fundamental concepts

Fundamental concepts

TECHNIQUES FOR TRUST AND INTEGRITY (CH03) B. RAMAMURTHY 2019, ALL RIGHTS RESERVED [email protected] HTTP://WW.CSE.BUFFALO.EDU/FACULTY/BINA TEACHING PROFESSOR COMPUTER SCIENCE AND ENGINEERING DIRECTOR, BLOCKCHAIN THINKLAB PROGRAM DIRECTOR, DATA-INTENSIVE COMPUTING PROGRAM Topics for discussion

Read chapter 3 of the text book Establishing trust in decentralized systems through verification, validation, and recording Trust intermediation by defining and applying rules using Solidity features - Designing state transitions in smart contracts Incremental development of smart contracts using the Remix IDE Tips for testing smart contracts Summary 22 READ READ READ Fiction or non-fiction

Poetry or prose Technical or non-technical Always have a book next to you --Bina 3 How to develop a Dapp? You must understand Dapp programming is not your traditional programming. There are many new concepts that you must understand before you start coding. 44

SC compile, deploy and invoke SC compile generates ABI (Abstract binary interface: json version of the SC) SC deploy generates the address of the SC An application working on behalf of a peer participant will use the SC address and ABI to access the functions of the SC. - From last lecture.. 55 What are we going to do today?

Trust and integrity are essential requirements for any system, but this is especially true in a decentralized system where the peer participants operate beyond the traditional boundaries of trust. Today, youll learn how to add elements that establish trust and integrity to your blockchainbased solution, thus expanding your system model. DEFINITION Trust is a measure of confidence in the credibility of a peer participant in a system. In a blockchain system it is implemented by verification, validation, and immutable recording with the consensus of the stakeholders. 66 Essentials of trust and integrity -

77 Implementing trust intermediation Typically, verification, validation, and exceptions in problems are specified by rules to be enforced and conditions to be checked. Additionally, in a blockchain-based application, you should revert or abort any transactions that violate trust (a rule), to prevent bad or unauthorized transactions from becoming part of the immutable ledger of the blockchain. - This is a key difference of blockchain programming from regular distributed application development.

88 Solidity features for trust and integrity Solidity provides various language features and functions that address these trust requirements, such as: 1. Modifiers to specify access control rules for verifying and managing who has control to data and functions in order to establish trust and privacy (for example, only the owner can register members). 2. The require(condition) declaration, which validates the condition passed as a parameter and reverts the transaction if the check fails. This is commonly used for validation of parameters (for example, age > 21). 3. The revert() function, which allows you to revert a transaction and prevent it from being recorded on the blockchain. This is commonly used in modifier definitions. It can also be

used with regular if statements. 4. The assert(condition) declaration, which validates the condition passed and reverts the transaction if the check fails. This is used for exceptions when you dont want the condition to fail (for example, to validate the head count in the middle of the ocean during a cruise). 99 Example: online balloting PROBLEM STATEMENT Consider an online ballot application. People vote to choose a proposal from a set of proposals. A chairperson registers the people who can vote, and only registered voters can vote (only once) on a proposal of their choice. The chairpersons vote is weighted twice (x2) as heavily as regular peoples votes. The ballot process goes through four states (Init, Regs, Vote, Done), and the respective operations (initialize, register, vote, count

votes) can be performed only in the corresponding states. - This is a plain and simple rudimentary definition of online digital balloting. 10 10 Use Design Principles as guideline DESIGN PRINCIPLE 1 Design before you code, develop, and deploy on a test chain, and thoroughly test before you deploy on a production blockchain, because once the smart contract is deployed it is immutable.

DESIGN PRINCIPLE 2 Define the users of and use cases for the system. Users are entities that generate the actions and input and receive the output from the system youll be designing. DESIGN PRINCIPLE 3 Define the digital assets, peer participants and their roles, rules to be enforced, and transactions to be recorded for the system youll be designing. DESIGN PRINCIPLE 4 Define a contract diagram that specifies the name, digital assets, functions, and rules for execution of functions and access of data. 11 11 Steps in solving ballot problem The following are the steps for solving the defined ballot problem:

Apply design principles 1, 2, and 3 to design the use case diagram and define the users, digital assets, and transactions. Using design principle 4, design the contract diagram that defines the data, modifiers or rules for verification and validation, and functions. Using the contract diagram, design the smart contract (in Solidity). Compile and deploy the smart contract in the Remix IDE, and test it. 12 12 Use case diagram -

13 13 Ballot roles and data definitions pragma solidity ^0.5.0; contract BallotV1 { struct Voter { uint weight; bool voted; uint8 vote; } struct Proposal { uint voteCount; }

#A #B - address chairperson; mapping(address => Voter) voters; #C Proposal[] proposals; enum Phase {Init, Regs, Vote, Done} #D Phase public state = Phase.Init; } #A Type Voter contains the voter details

#B Type Proposal contains proposal details: for now, only voteCount #C Mapping of voter address to voter details #D Various phases (0,1,2,3) of voting, state initialized to Init phase 14 14 System dynamics using UML state diagram DESIGN PRINCIPLE 5 Use a finite state machine UML diagram to represent system dynamics such as state transitions within a smart contract. Here are some constraints for our ballot problem: - a specific deadline. Registration has to be completed before voting, and before

The functions cannot be called in any order. Voting is open only for a specified period. The winner can be determined only after the voting is complete. 15 15 FSM for the ballot states - 16 16

Constructor and a function to manage state constructor (uint8 numProposals) public { #B chairperson = msg.sender; #B voters[chairperson].weight = 2; // weight 2 for testing purposes proposals.length = numProposals; #C } // function for changing Phase: can be done only by chairperson function changeState(Phase x) public { #D if (msg.sender != chairperson) {revert();} #E if (x < state) revert(); #F state = x; } }

#A Internally coded as 0,1,2,3 #B Constructor makes contract deployer the chairperson #C Number of proposals is a parameter for constructor #D State changer function #E Only chairperson can change state; else revert #F State has to progress in 1,2,3,4 order; else revert 17 17 Modifiers in Solidity DEFINITION Modifiers are a language feature that supports explicit specification of rules for validation and verification. These are the gatekeepers that do the verification and validation, and thus are specifically meant for realizing trust.

modifier name_of_modifier (parameters) //syntax { require { conditions_to_be_checked}; _; } - modifier validPhase(Phase reqPhase) //example { require(state == reqPhase); _; } function register(address voter) public validPhase(Phase.Regs) { //usage //if (state != Phase.Regs) {revert();} #B if (msg.sender != chairperson || voters[toVoter].voted) return;

voters[voter].weight = 1; voters[voter].voted = false; 18 18 Contract diagram with modifiers - 19 19 Demo of Ballot contract

Here is Ballot.sol for you to follow along Lets do some basic testing: this is not automated testing, well learn that later Some positive tests and some negative tests Now it is time for you to go through chapter 3. Read and understand how to program a SC in Solidity and test it using Remix IDE. 20 20

Recently Viewed Presentations

  • Calculus 6.3 day 1

    Calculus 6.3 day 1

    6.3 day 1 Integration By Parts Badlands, South Dakota Greg Kelly, Hanford High School, Richland, Washington Photo by Vickie Kelly, 1993 6.3 day 1 Integration By Parts Start with the product rule: This is the Integration by Parts formula.
  • Resources Induction

    Resources Induction

    Related links Intranet home page Internet and email code of conduct About the Group Getting around Finding things Getting help All about you Home Resources Group Induction Network areas Intranet Guide to Using the Intranet Related links Intranet home page...
  • American Imperialism - Weebly

    American Imperialism - Weebly

    Reasons for American Imperialism. Closure of the frontier. Fears that natural resources would run out. Success in subjugating Native American tribes in the West. Social Darwinism applied to world affairs. Need for new markets. Cultural superiority. Spread Christianity and democracy
  • Cells: The Basic Units of Life - Madison County Schools ...

    Cells: The Basic Units of Life - Madison County Schools ...

    The Cell Theory . Matthias Schleiden - 1838 - all plant parts are made of cells. Theodore Swann - 1839 - wrote the first part of the cell theory. All organisms are composed of one or more cells. The cell...
  • Philosophy of Religion - ТДМУ

    Philosophy of Religion - ТДМУ

    Philosophy of Religion ... Argument Gaunilo- Anti Ontological Argument St. Thomas Aquinas- 5 Proofs William Paley- Watch on Beach David Hume- Weak Analogy St. Anselm (1033- 1109) St. Anselm argues for the necessary existence of a perfect being. His argument...
  • IEEE 1 1 June 11, 2010 IEEE TAG

    IEEE 1 1 June 11, 2010 IEEE TAG

    IEEE Framework Group on Earth Observations www.earthobservations.org Global Earth Observation System of Systems IEEE-GEO Collaboration Opportunities Group on Earth Observations Global Earth Observation System of Systems GEOSS Global, Coordinated, Comprehensive Sustained System of Observing Systems GEOSS Global Earth Observation System...
  • Chapter 17: The West Between the Wars 1919 - 1939

    Chapter 17: The West Between the Wars 1919 - 1939

    Chapter 17: The West Between the Wars 1919 - 1939 Section 4: Cultural and Intellectual Trends Chapter 17: The West Between the Wars 1919 - 1939 Section 4: Cultural and Intellectual Trends Mass Culture: Radio and Movies In the late...
  • North Country Access Improvements Stakeholder Advisory Committee Meeting

    North Country Access Improvements Stakeholder Advisory Committee Meeting

    Pam Yonkin, Economics Task Leader. Presentation slide for courses, classes, lectures et al. Analyzed existing conditions. Population. ... Clarkson University. SUNY Potsdam. SUNY Potsdam Start-Up NY. Canton-Potsdam Hospital. 4 Economic Development and Planners.