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

An Agile Software Engineering Method to Design Blockchain Applications

SECR 2018
October 13, 2018

An Agile Software Engineering Method to Design Blockchain Applications

SECR 2018
Микеле Маркези
Professor, Dept. of Mathematics and Computer Science, Университет Кальяри

В докладе рассматривается процесс создания блокчейн-приложений: сбор требований, анализ, проектирование, разработка, тестирование и развертывание .

Данный процесс основан на agile-практиках, но использует и более формальные подходы, такие как UML-диаграммы, модифицированные для представления специфических понятий, характерных для блокчейн-приложений.

В докладе будет приведен пример, показывающий, как данный метод работает на практике.

SECR 2018

October 13, 2018
Tweet

More Decks by SECR 2018

Other Decks in Programming

Transcript

  1. An Agile Software Engineering Method to Design Blockchain Applications Michele

    Marchesi, Lodovica Marchesi, Roberto Tonelli University of Cagliari Software Engineering Conference Russia 2018 October 12-13 Moscow
  2. 2 Blockchain • The Blockchain was a technology whose first

    application was to run the Bitcoin cryptocurrency in a decentralized and secure way • It is a distributed data structure characterized by: –data redundancy –check of transaction requirements before validation –recording of transactions in sequentially ordered blocks –ownership based on public-key cryptography –immutability –a transaction scripting language, associated to the transactions – the corresponding program is executed by all nodes
  3. 3 Smart Contracts (SC) • The software associated to transactions

    and running on the Blockchain • The SC run in every node • All executions must produce the same result • The calls and the storage modifications are recorded • A SC cannot access any device or network • The figure outlines the Ethereum approach for SC
  4. 4 Software Engineering for dApps • In the past few

    years, there has been a strong increase of interest in cryptocurrencies, in Blockchain applications and in Smart Contracts • This led to a huge inflow of money and of startup ideas • Many projects were born and quickly developed software • The scenario is that of a rush to be the first on the market, fearing of missing out • This unruled and hurried software development does not assure neither software quality, nor that the basic concepts of software engineering are taken into account
  5. 5 Goals • We propose a software development process to:

    − Gather the requirements −Analyze, Design −Develop, Test −Deploy Blockchain applications • The process is based on Agile practices • It makes also use of more formal notations, modified to represent specific concepts found in Blockchain development
  6. 6 BOS Design Method — Main Steps • Steps 1-3:

    Gather requirements (without assuming the use of a blockchain) • Step 4: Divide the system in two subsystems:  Step 5: the blockchain system (SC)  Step 6: the external system (server, client, GUI) • Step 7: Test the two subsystems • Step 8: Integrate and deploy
  7. 7 Steps 1 and 2 1.Define in one or two

    sentences the goal of the system. For instance: To create a simple crowfunding system, managing various projects that can be financed using Ethers 2.Identify the actors (human and external systems/devices). For instance: 1.System Administrator: s/he accepts the projects and their property; takes action in the case of problems 2.Fund Raiser: they give the crowfunding project data, including the address receiving the money 3.Crowfunder: they finance projects sending Ethers
  8. 8 Step 3 – User Stories • Write the system

    requirements in term of user stories or features:  Create System: The Administrator creates the contract, that register his address  Start Campaign: A Fund Raiser activates a CF project, giving its data: soft and hard cap, end date, address where to send money to  Cash Campaign: The Fund Raiser, if the time of the CF has expired, or if the hard cap has been reached, cashes out the Ethers given to the project
  9. 9 Step 3 – User Stories  Delete Campaign: The

    Fund Raiser cancels the project; the Ethers are given back to Crowfunders  End Campaign: The Administrator, or the Fund Raiser, if the time of the CF has expired and the soft cap has not been reached, ends the project; the Ethers are given back to Crowfunders  Finance a Project: a Crowfunders sends Ethers to a project
  10. 11 Step 4 - Divide into SC system and external

    system • Divide the system in two separate systems: −The Blockchain system, composed by the SCs −The external system that interacts with the first, sending transactions to the Blockchain and receiving the results • The SC system interacts with the outside exclusively through blockchain transactions. −It has actors, recognized by the respective address −It can use libraries and external contracts −It can generate transactions to other contracts, or can send Ethers • The client / server system is the one described in the previous steps −But it adds the interface to the SCs
  11. 13 Step 5 - Design of the SC subsystem •

    Redefine the actors and the user stories • Define the decomposition in SCs (one or more) • For each SC, define the structure, the flow of messages and Ether transfers, the state diagram (if needed), the data structure, the external interface (ABI), the events, the modifiers... • Define the tests and the security assessment practices
  12. 14 Step 6 – Design of the external subsystem •

    Redefine the actors and the user stories, adding the new (passive) actors represented by the SCs • Decide the architecture of the system • Define the decomposition in modules, and their interfaces • Define the User Interface of the relevant modules • Perform a detailed design of the subsystem • Perform a security assessment
  13. 15 BOS Design Method – Steps 7 and 8 7.

    Code and test the systems; in parallel: −Write and test the SCs, starting from their data structure and functions; −Implement the USs of external subsystem with an agile approach (Scrum or Kanban); 8. Integrate, test and deploy the overall system.
  14. 16 A Case Study: Corporate voting management 1. GOAL OF

    THE SYSTEM: • To manage in a simplified way voting in corporate assemblies 2. IDENTIFY ACTORS: • Corporate administrator: manages the system, manages the shareholders and their shares, convenes assemblies, calls for votings • Shareholder: participates to assemblies, casts his votes, delegates participation to assemblies
  15. 19 Step 4. Divide the system •In this case the

    subdivision is trivial, because all US make use of Smart Contracts. •The DApp subsystem US are the same. Each includes the Blockchain as further Actor. •The Blockchain subsystem US are the same. The identifiers of the Actors are their unique adresses: −Corporate administrator: her/his address is at first the address that creates the contract, and then possibily a further address set by the Change administrator US −Shareholder: their addresses are specified and managed by the Administrator.
  16. 20 Step 5. Design of the SC subsystem •The system

    is quite simple, so a single SC is the best option •Following a SC standard, the “Ownable” standard contract is used to manage the ownership of the SC, held by the Administrator, who creates the SC contract Ownable { address public _owner; modifier onlyOwner() { require(msg.sender == _owner); _; } constructor() public { _owner = msg.sender; . . . }
  17. 21 Step 5. Design of the SC Data structure of

    the SC shown using a modified UML class diagram
  18. 22 UML State diagram of a Shareholder • showing the

    possible ways of her/his participation to an assembly:
  19. 23 Step 5. The Dynamic model of the SC subsystem

    •Modifiers: −onlyOwner() −onlyShareholder() −onlyOwnerOrShareholder() −assemblyRunning() – enforces that there is actually an assembly running at the time of the call −assemblyNotRunning() – enforces that there is no assembly running at the time of the call •Functions: −AndSoOnAndSoOn...()
  20. 24 Step 6. Design of the external subsystem (ESS) •Actors

    of the ESS: −Administrator −Shareholder −SC subsystem •Architecture: −A responsive application for managing the system −An app for the shareholders (voting and delegating) •The app GUIs are designed •The apps are developed using the Ethereum API web3.js library and a dev environment of choice
  21. 25 Steps 7 and 8: coding, testing, deploying the system

    • Here we give some details of SC security assessment • We apply a checklist to SC design and code, to assess their security against known attacks: −Minimize external calls and check for reentrancy −Follow the "checks-effects-interactions" pattern −Check the proper use of assert(), require(), revert() −Check if there are ways to make the SC permanently stuck due to gas consumption above the limit −Have some way to update the contract in the case some bugs will be discovered −. . .
  22. 26 Conclusions • Despite the huge effort presently ongoing in

    developing DApps, software engineering practices are still poorly applied • A sound software engineering approach might greatly help in overcoming many of the issues plaguing blockchain development: −Security issues −Software quality and maintenance issues • Researchers in software engineering have a big opportunity to start studying a field that is very important and brand new • Blockchain firms, including ICO startups, could develop a competitive advantage using SE practices since the beginning