BPMN on Ethereum - ut BPMN%ENGINE%ON%ETHEREUM%%%%%LUCIANO%GARCÍA2BAÑUELOS% 12...

21
A lightweight BPMN Execution Engine on Ethereum Luciano GarcíaBañuelos University of Tartu

Transcript of BPMN on Ethereum - ut BPMN%ENGINE%ON%ETHEREUM%%%%%LUCIANO%GARCÍA2BAÑUELOS% 12...

A lightweight BPMN Execution Engine on Ethereum Luciano  García-­‐Bañuelos

University  of  Tartu

Blockchain  ...

BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS  8/11/16   1  

Taken  from  hBp://smartmoney.startupitalia.eu/wp-­‐content/uploads/sites/7/2016/03/catena-­‐bitcoin.jpg  

From  the  point  of  view  of  this  talk • Distributed,  highly  (fully?)  replicated,  append  only  database  

• Each  record  that  is  inserted  into  the  database  is  secured  from  tampering  and  revision  

• Keywords  ◦ Distributed:  The  database  is  highly  replicated,  following  a  peer-­‐to-­‐peer  architecture  (there  is  not  a  central  master  node)  

◦ Append-­‐only  storage:  Wri_ng  to  the  database  can  only  happen  by  adding  new  records  at  the  end  of  it  

◦ Descentralized  consensus:  the  majority  of  nodes  needs  to  agree  that  a  yet-­‐to-­‐be-­‐added  record  is  legi_mate  or  not  

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   2  

Bitcoin’s  take  on  blockchain

Assume  “Alice”  sends  some  bitcoins  to  “Bob”,  a  bitcoin  transac_on  will  accordingly  store:    •  An  input:  This  is  a  record  of  which  bitcoin  address  was  used  to  send  the  bitcoins  to  “Alice”  in  the  first  place  

•  An  amount:  The  amount  of  bitcoins  being  traded  

•  An  output:  This  is  “Bob”’s  bitcoin  address    

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   3  

Image  taken  from  “Mastering  Bitcoin”  by  Andreas  M.  Antonopoulos,  O’Really  

Ethereum’s  take  on  blockchain

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   4  

Image  taken  from  hBps://blog.ethereum.org/wp-­‐content/uploads/2015/11/ethblockchain_full.png  

Ethereum  components:          1)  A  distributed  blockchain  (similar  to  Bitcoin)  2)  A  compu_ng  plahorm  that  enables  the  execu_on  of  Smart  Contracts  

The  above  is  done  on  top  of  the  Ethereum  Virtual  Machine  (EVM)  

Smart  contract  … • Programs  living  on  the  blockchain  (e.g.  Ethereum)  with  their  own  memory  and  code  

• Blockchain  transac_ons  via  execu_on  of  contract  func_ons  (clauses)  

• Manipulate  persistent  data  (contract  state),  transfer  ether,  interact  with  other  contracts  or  with  “agents”  

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   5  

Blockchain  as  a  plaEorm  for  collaboraFve  business  processes • Par_cipants  agree  on  a  collabora_ve  process  and  a  model  for  it  

• The  model  is  translated  to  a  smart  contract(s)  to  be  executed  on  the  blockchain  

• Smart  contracts  listen  to  process  execu_on  events  and  interact  with  agents  or  other  smart  contracts  in  order  to  monitor  and/or  execute  the  process  

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   6  

Blockchain  as  a  plaEorm  for  collaboraFve  business  processes

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   7  

Blockchain  as  a  plaEorm  for  collaboraFve  business  processes

• The  model  is  translated  to  a  smart  contract(s)  to  be  executed  on  the  blockchain  

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   8  

6 Weber, Xu, Riveret, Governatori, Ponomarev, and Mendling

Translator

BPMN model

Design Time

Factory contract

Process implementation

Figure 2: Overview of our approach

3.2 Design Time: Translator

The translator is used at design time: it takes an existing business processspecification as input and generates smart contracts. These implement the C-Monitor or mediator and can be deployed and executed on the blockchain.

In a collaborative process, this functionality must be split and distributedbetween the smart contract and the triggers. The translator creates the artifactsin such a way that the triggers and the smart contract can collaborate directlywith each other over the blockchain network.

When the translator is called, it may not be known which participants willplay which roles. Therefore, the translator outputs only a factory contract,which in turn contains all information needed for instantiating the process. Thefactory contract includes the methods for instantiation and two types of artifacts:(i) an interface specification per role (e.g., buyer, manufacturer, and shipper) ina collaborative process, to be distributed to the respective triggers, and (ii) aprocess instance contract, which is deployed to the blockchain when the processis instantiated. The process instance contract contains the implementation of thebusiness logic and takes the form of a C-Monitor or mediator, depending on thecontent of the original process specification.

The overall translation algorithm has two phases. First, the translator parsesthe input process model and iterates through all its elements, where it generatestwo lists per element in the process model: one list of previous elements and oneof next elements. Then, the translator translates each element with its respectivelinks, generating Solidity code based on the translation rules for di↵erent typesof elements as detailed in the TR [23]. Note that, in the current implementation,only some combinations of consecutive gateways can be connected to each otherwithout tasks in between. The previous element list is used by the translator todetermine which other elements need to be deactivated when the current element

Blockchain  as  a  plaEorm  for  collaboraFve  business  processes

• Smart  contracts  listen  to  process  execu_on  events  and  interact  with  agents  or  other  smart  contracts  in  order  to  monitor  and/or  execute  the  process  

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   9  

6 Weber, Xu, Riveret, Governatori, Ponomarev, and Mendling

Run Time

On blockchain

Off blockchain

Internal process

Interface

Internal process

Interface

Internal process

Interface

Data payload

Data payload

Data payload

Key distributor

Trigger

Factory contract

Process instance contract ( Mediator / Monitor )

Escrow

Verification

Deposit collector

Execution state

Partial data payload

Participants account

Business logic ( Active / passive )

Trigger Trigger

Figure 2: Overview of our approach

3.2 Design Time: Translator

The translator is used at design time: it takes an existing business processspecification as input and generates smart contracts. These implement the C-Monitor or mediator and can be deployed and executed on the blockchain.

In a collaborative process, this functionality must be split and distributedbetween the smart contract and the triggers. The translator creates the artifactsin such a way that the triggers and the smart contract can collaborate directlywith each other over the blockchain network.

When the translator is called, it may not be known which participants willplay which roles. Therefore, the translator outputs only a factory contract,which in turn contains all information needed for instantiating the process. Thefactory contract includes the methods for instantiation and two types of artifacts:(i) an interface specification per role (e.g., buyer, manufacturer, and shipper) ina collaborative process, to be distributed to the respective triggers, and (ii) aprocess instance contract, which is deployed to the blockchain when the processis instantiated. The process instance contract contains the implementation of thebusiness logic and takes the form of a C-Monitor or mediator, depending on thecontent of the original process specification.

The overall translation algorithm has two phases. First, the translator parsesthe input process model and iterates through all its elements, where it generatestwo lists per element in the process model: one list of previous elements and oneof next elements. Then, the translator translates each element with its respectivelinks, generating Solidity code based on the translation rules for di↵erent typesof elements as detailed in the TR [23]. Note that, in the current implementation,only some combinations of consecutive gateways can be connected to each otherwithout tasks in between. The previous element list is used by the translator todetermine which other elements need to be deactivated when the current element

Smart  contract  ...   • Described  by  Nick  Szabo  in  the  late  90s  

The  basic  idea  behind  smart  contracts  is  that  many  kind  of  contractual  clauses  (e.g.  collaterals,  bonding,  delinea_on  of  property  rights)  can  be  embedded  in  hardware  and  solware  in  such  a  way  as  to  make  breach  of  contract  expensive  for  the  breacher  

BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS  8/11/16   10  

Smart  contract? • Contract:  Tradi_onal  way  to  formalize  a  rela_onship  

• Defini_on  from  Merriam-­‐Webster  ◦ A  binding  agreement  between  two  or  more  persons  or  par_es,  especially  one  legally  enforceable  

◦ A  business  arrangement  for  the  supply  of  goods  or  services  at  a  fixed  price  

◦ The  act  of  marriage  or  an  agreement  to  marry  

◦ A  document  describing  the  terms  of  a  contract  

BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS  8/11/16   11  

A  concrete  example  … • Within  a  limited  amount  of  poten_al  loss,  the  vending  machine  takes  in  coins  and  dispenses  change  and  product  according  to  the  displayed  price  

• Vending  machine  implements  a  sort  of  contract  with  bearer:  ◦ Anybody  with  coins  can  par_cipate  

◦  Some  security  mechanisms  protect  stored  coins  and  product  from  aBackers  

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   12  

By  Minnesota  Historical  Society  -­‐  Original  Image  taken  from  The  Minnesota  Historical  Society  on  Flickr,  CC  BY-­‐SA  2.0,  hBps://commons.wikimedia.org/w/index.php?curid=6608597  

Another  example:  Remote  purchase

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   13  

BPMN  view  of  the  process

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   14  

Escrow (S

mart contract)

Purchase contractcreated

Notify Buyer about contract 

creation

Confirm purchase (payment)

Notify Seller about payment

Confirm reception

Notify Seller about reception

Buyer

Seller

Remote purchase - Choreography

Create purchase contract

Seller

Buyer

Confirm purchase(payment)

Seller

Buyer

Ship product

Seller

Shipping company

Confirm reception

Seller

Buyer

Purchase details

Payment details

Shipment details

Delivery details

Deliver product

Shipping company

Buyer

Another  example:  Remote  purchase

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   15  

Remote  purchase    (cont)

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   16  

Remote  purchase  …  middleman

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   17  

Escrow  

Smart  contract  on  BPMN

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   18  

Escrow (S

mart contract)

Purchase contractcreated

Block Seller deposit

Notify Buyer about contract 

creation

Notify Seller about payment

Confirm purchase

Confirm reception

Transfer payment to Seller and 

unblock Seller's deposit

Block buyer's payment and 

depositPurchase completed

Notify Seller about reception

Unblock Buyer's deposit

Cancel transaction

Unblock Seller'sdeposit

Purchase cancelled by 

Seller

Seller

Buyer

Demo  Fme

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   19  

Temporal  constraints  on  BPMN

8/11/16   BPMN  ENGINE  ON  ETHEREUM                              LUCIANO  GARCÍA-­‐BAÑUELOS   20  

Cancellation by guest

Cancellation by host

Block host & guest deposit

7 days before check­in