declarative - java forum stuttgart · declarative smart contracts. context 1. an actual contract,...

44
Markus Völter [email protected] www.voelter.de @markusvoelter Declarative Smart Contracts

Upload: others

Post on 21-May-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Markus Vö[email protected]@markusvoelter

DeclarativeSmart

Contracts

Page 2: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Context1

Page 3: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

An actualcontract,executed

automatically.

AnyTuring Complete

Programrunning on

a Blockchain.over time

SMART CONTRACT

Page 4: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

An actual contract,executed automatically.

Multiple Parties.

Decision | | Agreement | | Coordination.

(Legally) Binding & Trusted.

Formal Language.

Checkable.Understandable.

„Event Tracking“Progress over time

Page 5: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Contract Definition

Contract Execution

Page 6: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Contract Definition

Contract Execution

Understand BehaviorFunctional Correctness

Non-RepudiabilityVerified BehaviorNon-Gameability} BC

Page 7: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Blockchainscan provide certain

non-functional propertiesto executable contracts.

Blockchainsare a suitable (partial)

implementation technologyiff these properties are needed.

Page 8: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

VerificationEnsure that the program performscorrectly the things the program

text tells it to do.

ValidationEnsure that the program doesthe correct things, wrt. to the

requirements.

Page 9: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

VerificationEnsure that the program

performs correctly the things the program text tells it to do.

ValidationEnsure that the program doesthe correct things, wrt. to the

requirements.

Contract Execution

Contract Definition

Page 10: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Correct-by-ConstructionThe language/framework/

API/modeling tool doesn’t allowa particular class of mistakes.

Analysis-and-FixYou analyze the code/model after the

fact and try to find problems whichdevs then fix.

Page 11: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Formal Language.Checkable.

Understandable.DSLDomainSpecificLanguage

Page 12: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Well, people realize that these contracts have to run reliably, after all, the programs deal with real values now.

Some Blockchain Guy

Page 13: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Not the first community to realize ... J

Page 14: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Lots of History & Research

Computational LawObligation, PermissionOrdering, Causality, TimeEvent, State

Page 15: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Lots of History & Research

Blockchains

Composing contracts: an adventure in financial engineeringhttps://lexifi.com/files/resources/MLFiPaper.pdf

POETS Process-oriented event-driven transaction systemshttps://github.com/legalese/poets/blob/master/doc/Henglein%20-%20POETS%20Process-oriented%20event-driven%20transaction%20systems.pdf

https://github.com/legalese/poets/blob/master/doc/hvitvedmaster.pdf

Domain-Specific Languages for Enterprise Systems https://bitbucket.org/jespera/poets/raw/c0ee7194ce57d2ad6ca8894c8a44e88e546d5f4a/doc/poets-techreport/tr.pdf

Contracts in Programming and in Enterprise Systems

Page 16: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Solution2

Page 17: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Ethereum VM/Network

Iulia

Hyperledger

Java

Executable Multi-Party Contract Language

DSLLogistics

DSLFinance

DSL…

KernelF

MPS / Convecton

Distribution, Trust Correctness

Valid

atio

n

Sim

ulat

ion

Colla

bora

tion

Expr

essiv

enes

s

SMTLIB

Z3

HTMLJavaScript

CSS

Interaction, Integration

An Architecture For Smart Contracts

Generate to verification tools to build more confidence beyond type checking.

Page 18: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure
Page 19: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Declarative Description

MultiPartyBooleanDecisionA declarative, configurable specification of how a number of parties makes a (Boolean)decision.

Page 20: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Execution and Test

A MPBD instance maintains the state of a decision process as it evolves over time.

Here, we play with an instance in the interactive REPL.

Page 21: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Combination with State Machines

More complex contracts are modeled as state machines; events are the API.

Internally, the use BPBDs.

Page 22: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Combintation with State Machines II

Here, a transition action creates a new AccessControl instance ...

The state of that instance is then used in guard condition for the top level SM.

Page 23: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Preventing Game Theoretical Attacks

Only „valid“ senders can enter this state.

Events can only arrive at limited rate.

States must be entered turn-by-turn.

Page 24: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Ethereum VM/Network

Iulia

Hyperledger

Java

Executable Multi-Party Contract Language

DSLLogistics

DSLFinance

DSL…

KernelF

MPS / Convecton

Distribution, Trust Correctness

Valid

atio

n

Sim

ulat

ion

Colla

bora

tion

Expr

essiv

enes

s

SMTLIB

Z3

HTMLJavaScript

CSS

Interaction, Integration

An Architecture For Smart Contracts

I D E A

Page 25: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Example: HyperCSL

Blockchains

Lisp (Clojure) based internal DSL for specifi-cation of general commercial contracts.

Inspired by Simon Peyton Jones and Jean-Marc Eber and the POETS group at CPHU and ITU in Denmark.

Uses Ken Adams’ Categories of Contract

Language as fundametal semantic building blocks. Interpreter and UI in prototype stage.

Page 26: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Example: HyperCSL

Blockchains

Page 27: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Example: HyperCSL

Blockchains

A UI to visualize the interactive execution of CSL contracts.

Page 28: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Tooling3

Page 29: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Ethereum VM/Network

Iulia

Hyperledger

Java

Executable Multi-Party Contract Language

DSLLogistics

DSLFinance

DSL…

KernelF

MPS / Convecton

Distribution, Trust Correctness

Valid

atio

n

Sim

ulat

ion

Colla

bora

tion

Expr

essiv

enes

s

SMTLIB

Z3

HTMLJavaScript

CSS

Interaction, Integration

An Architecture For Smart Contracts

KernelF is an extensible functional language used at the core of DSLs.

Page 30: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

DSL Development

New Language

GPL Extension

Formalization

Reuse GPL incl. Expressions and TSAdd/Embed DS-extensionsCompatible notational style Reduce to GPL

Analyze Domain to find AbstractionsDefine suitable, new notations. Rely on existing behavioral paradigmReuse standard expression languageInterpret/Generate to one or more GPLs

Use existing notation from domainClean up and formalizeGenerate/InterpretOften import existing „models“

KernelF

Page 31: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Functional Features

Functional, no state at its core.Purity + Effect TrackingThe usual types, literals and op‘sVarious ConditionalsFunctions and BlocksNo null, only opt<T>Error Handling

Immutable Collections and higher-order functionsEnums, tuples, records, all immutableConstraints on types and functions

Boxes (like Clojure‘s ref)Transactional MemoryState MachinesInteractors

Stateful Features

Extensible/Embeddable through modular language implementation and other means.

Page 32: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

(Meta-) Tooling

Language WorkbenchOpen Source, by Jetbrains

Very PowerfulUsed for years by itemis and othersVast Experience

Page 33: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

MPS: Language Toolkit

Page 34: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

MPS: Notational Freedom

Page 35: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

MPS: Language Composition

Page 36: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

VerifyingInfrastructure

4

Page 37: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Ethereum VM/Network

Iulia

Hyperledger

Java

Executable Multi-Party Contract Language

DSLLogistics

DSLFinance

DSL…

KernelF

MPS / Convecton

Distribution, Trust Correctness

Valid

atio

n

Sim

ulat

ion

Colla

bora

tion

Expr

essiv

enes

s

SMTLIB

Z3

HTMLJavaScript

CSS

Interaction, Integration

An Architecture For Smart Contracts

Page 38: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Ethereum VM/Network

Iulia

Hyperledger

Java

Executable Multi-Party Contract Language

DSLLogistics

DSLFinance

DSL…

KernelF

MPS / Convecton

Distribution, Trust Correctness

Valid

atio

n

Sim

ulat

ion

Colla

bora

tion

Expr

essiv

enes

s

SMTLIB

Z3

HTMLJavaScript

CSS

Interaction, Integration

An Architecture For Smart Contracts

<x

TRUST?

Page 39: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Verifying Blockchain Infrastructure

Blockchains

Formal Semantics of the EVM in Khttps://www.ideals.illinois.edu/bitstream/handle/2142/97207/hildenbrandt-saxena-zhu-rodrigues-guth-daian-rosu-2017-tr_0818.pdf

IELE: Register-Based VM for the Blockchainhttps://runtimeverification.com/blog/new-technologies-for-the-blockchain-iele-virtual-machine-and-k-universal-language-framework/

ERC20-K: Formal Executable Spec of ERC20https://github.com/runtimeverification/erc20-semantics

Formal Verification for Solidity Contractshttps://forum.ethereum.org/discussion/3779/formal-verification-for-solidity-contracts

Page 40: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Ethereum VM/Network

Iulia

Hyperledger

Java

Executable Multi-Party Contract Language

DSLLogistics

DSLFinance

DSL…

KernelF

Distribution, Trust Correctness

Valid

atio

n

Sim

ulat

ion

Expr

essiv

enes

s

SMTLIB

Z3

HTMLJavaScript

CSS

Interaction, Integration

An Architecture For Smart Contracts

Did I program/specify the right behaviors?

Will the infrastructure execute the behaviors faithfully?

Page 41: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Ethereum VM/Network

Iulia

Hyperledger

Java

Executable Multi-Party Contract Language

DSLLogistics

DSLFinance

DSL…

KernelF

Distribution, Trust Correctness

Valid

atio

n

Sim

ulat

ion

Expr

essiv

enes

s

SMTLIB

Z3

HTMLJavaScript

CSS

Interaction, Integration

An Architecture For Smart Contracts

Did I program/specify the right behaviors?

Will the infrastructure execute the behaviors faithfully?

Page 42: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Wrap Up

Page 43: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

Further Reading

Blockchains

Mutable State in KernelFhttps://medium.com/@markusvoelter/dealing-with-mutable-state-in-kernelf-e0fdec8a489b

A Smart Contract Development Stackhttps://languageengineering.io/a-smart-contract-development-stack-54533a3a503a

A Smart Contract Development Stack, Pt. 2https://languageengineering.io/a-smart-contract-development-stack-part-ii-game-theoretical-aspects-ca7a9d2e548d

KernelF Referencehttp://voelter.de/data/pub/kernelf-reference.pdf

DSLs in Safety-Critical Developmenthttp://voelter.de/data/pub/MPS-in-Safety-1.0.pdf

Page 44: Declarative - Java Forum Stuttgart · Declarative Smart Contracts. Context 1. An actual contract, executed automatically. Any Turing Complete Program ... Verifying Blockchain Infrastructure

We need better languages

Integration of verification tools

Simulation, Experimentation and Test

to describe contracts in a meaningful way

can be an important step to assure correctness

should be available in an interactive, local environment

Contracts must be functionally correctin order for stakeholders to trust them.

Deployment to Blockchain is non-func,it provides guarantees beyond functionality

Other deployments are useful,that provide other trade-offs (secure , fast )