SlideShare a Scribd company logo
1 of 32
Download to read offline
Blockchain Safety
and
Smart Contract Simulation
Tezos Japan, DaiLambda, Inc.
Jun FURUSE/古瀬淳, Singapore, NUS, 2019-10-31ASIASIM 2019
What is Blockchain?
Blockchain is DB
It is a hard computer science!
Ledger style
Distributed
Open/permissionless network
Ledger Style DB
DB by modification history accumulation:
Block consists of basic write operations :
. .S0 →
B1
S1 →
B2
S2 →
B3
S3 →
B4
= ∅S0
= ( )S1 B1 S0
= ( ) = ( (. . ( ). . ))Sn Bn Sn−1 Bn Bn−1 B1 S0
B o
= [ , . . , ]Bn on1
onm
= ( ) = (. . ( ( )). . )Sn Bn Sn−1 onm
on1
Sn−1
Distributed DB
Multiple nodes, each carries a replica of the DB:
Fault tolerance
Load balancing
Distributed DB: conflicts
How to resolve conflicts?
B
→→
A
x = A
x = A
x = A →→x = B
x = B
x = A
x = B
or
?
? ?
Consensus Algorithm
Algorithm to resolve conflicts between nodes:
Termination
All non-faulty nodes eventurally decide on a value.
Agreement
All nodes decided do so on the same value.
Validity
The decided value must be proposed by somee. node.
Bad news: no such algorithm exists [FLP85].
Good news: Paxos
Concensus algorithm which may not terminate
but practically OK.
Voting between nodes to an agreement:
Safe
Agreement and validity are always assured.
Not always Live
Termination is not assured. It may repeat votes infinitely.
Only for closed network with fixed participants.
Closed Network DB
If you are happy with closed world,
normal distributed DB with Paxos is your friend.
No need of “Blockchain”.
Open Network DB
Permissionless public network,
where anyone can join by running a node:
Decentralized: no central servers, therefore neutral.
Distributed with redundancy: almost impossible to hack.
Low cost, compared to the existing social infrastructure.
Problem of Open Network Consensus
Consensus control and inhibition
by Sybil attack: produces fake
identities to dominate the network.
Satoshi Nakamoto and Bitcoin
Prevent Sybil attack, infinite identity forgery:
Requirement of real world resource:
computation power (PoW)
Rewards: incentive to provide the
resource and behave honestly.
The rewards are recorded as tokens
in the DB.
Birth of cryptocurrency.
Smart Contracts
DB can carry not only account balance,
but also any data, even program code.
Code attached to an account is executed when it
receives a transaction.
Automatic execution of financial/non-financial contracts
Distributed application framework towards neutral and
public infrastructrure, without any central authority.
Safety Requirements of Blockchain
Consequence of introduction of token rewards
for open distributed DB:
Speculative money flows in.
System must be open source.
Security holes are immediate targets for theft.
Blockchain must have very high level of security.
Safety of Smart Contracts
Bugs turns smart contracts into automatic stealing
machines:
Past incidents around smart contracts:
The DAO (3.6M ETH, 15% of circulation, 50M USD stolen)
Parity vulnerability#1 (150K ETH, 32M USD stolen)
Parity vulnerability#2 (513K ETH, 160M USD frozen)
High level of security is required here too.
Tezos Blockchain
3rd generation blockchain tech.
LPoS
Eco friendly robust Sybil attack prevention
On chain governance
Protocol upgrades by on-chain proposals and voting
Safety first design
Proving safety properties by formal verification
Formal Verification
Mathematically prove good/bad software properties.
Properties are correct for all the cases, if proven.
Methods: Type systems, model checking, theorem provers.
Tests are important, but not fully trustable:
only few corner cases can be verified.
No guarantee for the untested cases.
Tezos and Formal Verification
Protocol
Written in OCaml, good match with FV
Smart contract VM
Statically typed, purely functional stack VM,
with structured data such as pairs, lists, map, etc.
Smart contract safety
Modeling of smart contract interpreter using Coq,
and correctness proofs of smart contracts using it.
Cryptographic primitives
Correctness proof by F* language.
Ledger file system
With correctness proofs.
Blockchain and Simulation
Safety can be proven, but how safe is not always
provable. Simulation is also important:
Concensus
P2P network
Smart contract
etc.
Writing to the DB
Sending operation to a node:
Transactions
Account creations, etc
Operations spread into the P2P network.
→
→
O1
O1
O1
O1
O1
O1
O2
O2
O2
O2
O2
O2
O2
O2
o
Block creation
Block proposer chooses operations found in his node
and form a block of them.
The proposer releases to the network.
O1
O1
O2
O2
O2
O2
B = [ O1, O2 ]
→
B
O1
⇨ B1 = [ O1, O2 ]
→
B
B
B
B
B
B
B
B
= [ , . . , ]Bn on1
onm
B
Smart Contract Simulation
Contract is a function:
Emulate contract execution of
by applying a block only with the call:
c : param → operation
c(p)
Bn−1
= [c(p)]Bn
= ( ) = c(p)( )Sn Bn Sn−1 Sn−1
Simulation can Differ from the Reality
In reality, the call can be interrupted by other ops:
Simulation:
The call may not be taken into but :
Malicious block proposer can insert his op before
your call in to change its behaviour:
= [c(p)]Bn
= c(p)( )Sn Sn−1
Bn Bn+1
= c(p)( )  where   = ( ) ≠Sn+1 Sn Sn Bn Sn−1 Sn−1
o
′
Bn
= [ , c(p)]( ) = c(p)( ( ))Sn o
′
Sn−1 o
′
Sn−1
Mitigations
Fail the call when the simulation and real thing differ?
Failing in general does not scale the blockchain.
For specific contracts, this behaviour can be useful and
implementable with a counter.
Or prove contracts are immune to operation
permutations: ex. voting.
Or repeat simulations over variations of states:
Lattice model
Monte Carlo
Gas cost
Contracts are executed on each node.
Unrestricted execution such as infinite loops easily
results into DDoS attacks.
To prevent DDoS, smart contract executions must pay
fee proportional to the amount of calculation, gas.
VM for Smart Contracts
Nodes and smart contracts run in various conditions
(CPU architecture, CPU model, memory, etc.).
To define and count gas, smart contracts are modeled
over a stack VM and interpreted:
PUSH, ADD, SUB, IF, ..
The gas cost is defined for each VM opcode.
How to Decide Gas Cost?
Hard to deduce. Too many variables:
CPU characteristics
Interpreter performance
GC timing
Argument sizes and structures
Simulations come in. (by Ilias Garnier)
Gas Cost Simulation in Tezos #1
Guess a formula of gas cost of each opcode with
several unknown parameters:
ADD for arbitrary precision ints
Complexitiy:
Formula:
GET for map (by balanced tree)
Complexitiy:
Formula:
O(max(size(arg1), size(arg2)))
x + y ∗ max(size(arg1), size(arg2))
O(size(key) ∗ log(size(tree)))
x + y ∗ size(key) ∗ log(size(set))
Gas Cost Simulation in Tezos #2-1
Run each opcode under various conditions to get
good approximations of the parameters:
Add for arbitrary precision ints
Formula:
Cost function:
x + y ∗ max(size(arg1), size(arg2))
300 + 0.07 ∗ max(size(arg1), size(arg2))
Gas Cost Simulation in Tezos #2-2
Run each opcode under various conditions to get
good approximations of the parameters:
GET for map (by balanced tree)
Formula:
Defined cost:
x + y ∗ size(key) ∗ log(size(map))
1000 + 0.07 ∗ size(key) ∗ log(size(map))
Gas Cost Simulation in Tezos #3
Boil down to Gas code in the VM interpreter:
let add i1 i2 =  
  atomic_step_cost  
    (51 + (Compare.Int.max (int_bytes i1) (int_bytes i2) / 62))
let map_access key (module Box) = 
  let map_card  = snd Box.boxed in 
  let key_bytes = size_of_comparable Box.key_ty key in 
  atomic_step_cost ((1 + (key_bytes / 70)) * log2 map_card)
Conclusion
Blockchain: open distributed ledger DB.
Rewards are required to drive concensus.
Safety. Tezos pushes formal verification.
Simulations play important roles in many places.

More Related Content

What's hot

Simple regenerating codes: Network Coding for Cloud Storage
Simple regenerating codes: Network Coding for Cloud StorageSimple regenerating codes: Network Coding for Cloud Storage
Simple regenerating codes: Network Coding for Cloud StorageKevin Tong
 
Image encryption using elliptical curve cryptosytem with hill cipher
Image encryption using elliptical curve cryptosytem with hill cipherImage encryption using elliptical curve cryptosytem with hill cipher
Image encryption using elliptical curve cryptosytem with hill cipherkarthik kedarisetti
 
Design and Simulation Triple-DES
Design and Simulation Triple-DESDesign and Simulation Triple-DES
Design and Simulation Triple-DESchatsiri
 
Homomorphic encryption in_cloud
Homomorphic encryption in_cloudHomomorphic encryption in_cloud
Homomorphic encryption in_cloudShivam Singh
 
Cloud computing and security 03
Cloud computing and security 03Cloud computing and security 03
Cloud computing and security 03Akash Kamble
 
Substitution techniques
Substitution techniquesSubstitution techniques
Substitution techniquesvinitha96
 
Topic2 caser hill_cripto
Topic2 caser hill_criptoTopic2 caser hill_cripto
Topic2 caser hill_criptoMdFazleRabbi18
 
Blockchain and Smart Contracts
Blockchain and Smart ContractsBlockchain and Smart Contracts
Blockchain and Smart ContractsGene Leybzon
 
Secrecy and Authenticity Properties of the Lightning Network Protocol
Secrecy and Authenticity Properties of the Lightning Network ProtocolSecrecy and Authenticity Properties of the Lightning Network Protocol
Secrecy and Authenticity Properties of the Lightning Network ProtocolHans Hyttel
 
Data Protection Techniques and Cryptography
Data Protection Techniques and CryptographyData Protection Techniques and Cryptography
Data Protection Techniques and CryptographyTalha SAVAS
 
A survey on Fully Homomorphic Encryption
A survey on Fully Homomorphic EncryptionA survey on Fully Homomorphic Encryption
A survey on Fully Homomorphic Encryptioniosrjce
 
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...David Wood
 
Cryptography (Revised Edition)
Cryptography (Revised Edition)Cryptography (Revised Edition)
Cryptography (Revised Edition)Somaditya Basak
 
Ethereum Blockchain and DApps - Workshop at Software University
Ethereum Blockchain and DApps  - Workshop at Software UniversityEthereum Blockchain and DApps  - Workshop at Software University
Ethereum Blockchain and DApps - Workshop at Software UniversityOpen Source University
 
Digital Signatures: Reassessing security of randomizable signatures
Digital Signatures: Reassessing security of randomizable signaturesDigital Signatures: Reassessing security of randomizable signatures
Digital Signatures: Reassessing security of randomizable signaturesPriyanka Aash
 

What's hot (19)

Simple regenerating codes: Network Coding for Cloud Storage
Simple regenerating codes: Network Coding for Cloud StorageSimple regenerating codes: Network Coding for Cloud Storage
Simple regenerating codes: Network Coding for Cloud Storage
 
Image encryption using elliptical curve cryptosytem with hill cipher
Image encryption using elliptical curve cryptosytem with hill cipherImage encryption using elliptical curve cryptosytem with hill cipher
Image encryption using elliptical curve cryptosytem with hill cipher
 
Design and Simulation Triple-DES
Design and Simulation Triple-DESDesign and Simulation Triple-DES
Design and Simulation Triple-DES
 
Homomorphic encryption in_cloud
Homomorphic encryption in_cloudHomomorphic encryption in_cloud
Homomorphic encryption in_cloud
 
Cn tutorial (6 cs119)
Cn tutorial (6 cs119)Cn tutorial (6 cs119)
Cn tutorial (6 cs119)
 
Cloud computing and security 03
Cloud computing and security 03Cloud computing and security 03
Cloud computing and security 03
 
3 des
3 des3 des
3 des
 
Substitution techniques
Substitution techniquesSubstitution techniques
Substitution techniques
 
Coding
CodingCoding
Coding
 
Topic2 caser hill_cripto
Topic2 caser hill_criptoTopic2 caser hill_cripto
Topic2 caser hill_cripto
 
Blockchain and Smart Contracts
Blockchain and Smart ContractsBlockchain and Smart Contracts
Blockchain and Smart Contracts
 
Secrecy and Authenticity Properties of the Lightning Network Protocol
Secrecy and Authenticity Properties of the Lightning Network ProtocolSecrecy and Authenticity Properties of the Lightning Network Protocol
Secrecy and Authenticity Properties of the Lightning Network Protocol
 
Crypto
CryptoCrypto
Crypto
 
Data Protection Techniques and Cryptography
Data Protection Techniques and CryptographyData Protection Techniques and Cryptography
Data Protection Techniques and Cryptography
 
A survey on Fully Homomorphic Encryption
A survey on Fully Homomorphic EncryptionA survey on Fully Homomorphic Encryption
A survey on Fully Homomorphic Encryption
 
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
 
Cryptography (Revised Edition)
Cryptography (Revised Edition)Cryptography (Revised Edition)
Cryptography (Revised Edition)
 
Ethereum Blockchain and DApps - Workshop at Software University
Ethereum Blockchain and DApps  - Workshop at Software UniversityEthereum Blockchain and DApps  - Workshop at Software University
Ethereum Blockchain and DApps - Workshop at Software University
 
Digital Signatures: Reassessing security of randomizable signatures
Digital Signatures: Reassessing security of randomizable signaturesDigital Signatures: Reassessing security of randomizable signatures
Digital Signatures: Reassessing security of randomizable signatures
 

Similar to Blockchain and Smart Contract Simulation

Eclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business ApplicationsEclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business ApplicationsMatthias Zimmermann
 
Security in the blockchain
Security in the blockchainSecurity in the blockchain
Security in the blockchainBellaj Badr
 
EthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptxEthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptxWijdenBenothmen1
 
Blockchain and Formal verification (English)
Blockchain and Formal verification (English)Blockchain and Formal verification (English)
Blockchain and Formal verification (English)Jun Furuse
 
Best practices to build secure smart contracts
Best practices to build secure smart contractsBest practices to build secure smart contracts
Best practices to build secure smart contractsGautam Anand
 
Keynote (Mike Muller) - Is There Anything New in Heterogeneous Computing - by...
Keynote (Mike Muller) - Is There Anything New in Heterogeneous Computing - by...Keynote (Mike Muller) - Is There Anything New in Heterogeneous Computing - by...
Keynote (Mike Muller) - Is There Anything New in Heterogeneous Computing - by...AMD Developer Central
 
BlockChain for the Banker
BlockChain for the BankerBlockChain for the Banker
BlockChain for the BankerBohdan Szymanik
 
Blockchain, Ethereum and Business Applications
Blockchain, Ethereum and Business ApplicationsBlockchain, Ethereum and Business Applications
Blockchain, Ethereum and Business ApplicationsMatthias Zimmermann
 
2019 blockchain economy
2019 blockchain economy2019 blockchain economy
2019 blockchain economyHeung-No Lee
 
IWCI21: Distributed Ledgers for Distributed Edge
IWCI21: Distributed Ledgers for Distributed EdgeIWCI21: Distributed Ledgers for Distributed Edge
IWCI21: Distributed Ledgers for Distributed Edgeeichhorl
 
Building a blockchain on tendermint
Building a blockchain on tendermintBuilding a blockchain on tendermint
Building a blockchain on tendermintLviv Startup Club
 
Block chain 101 what it is, why it matters
Block chain 101  what it is, why it mattersBlock chain 101  what it is, why it matters
Block chain 101 what it is, why it mattersPaul Brody
 
Lightweight cryptography
Lightweight cryptographyLightweight cryptography
Lightweight cryptographyShivam Singh
 
Blockchain an introduction_n_li
Blockchain an introduction_n_liBlockchain an introduction_n_li
Blockchain an introduction_n_linikinew1
 
Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)Tomoaki Sato
 
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profitWeb3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profitTal Be'ery
 
Blockchain Development
Blockchain DevelopmentBlockchain Development
Blockchain Developmentpreetikumara
 

Similar to Blockchain and Smart Contract Simulation (20)

Eclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business ApplicationsEclipsecon Europe: Blockchain, Ethereum and Business Applications
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
 
Security in the blockchain
Security in the blockchainSecurity in the blockchain
Security in the blockchain
 
EthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptxEthereumBlockchainMarch3 (1).pptx
EthereumBlockchainMarch3 (1).pptx
 
Blockchain and Formal verification (English)
Blockchain and Formal verification (English)Blockchain and Formal verification (English)
Blockchain and Formal verification (English)
 
Best practices to build secure smart contracts
Best practices to build secure smart contractsBest practices to build secure smart contracts
Best practices to build secure smart contracts
 
Keynote (Mike Muller) - Is There Anything New in Heterogeneous Computing - by...
Keynote (Mike Muller) - Is There Anything New in Heterogeneous Computing - by...Keynote (Mike Muller) - Is There Anything New in Heterogeneous Computing - by...
Keynote (Mike Muller) - Is There Anything New in Heterogeneous Computing - by...
 
BlockChain for the Banker
BlockChain for the BankerBlockChain for the Banker
BlockChain for the Banker
 
SIGFOX Makers Tour - Porto
SIGFOX Makers Tour - PortoSIGFOX Makers Tour - Porto
SIGFOX Makers Tour - Porto
 
Blockchain, Ethereum and Business Applications
Blockchain, Ethereum and Business ApplicationsBlockchain, Ethereum and Business Applications
Blockchain, Ethereum and Business Applications
 
2019 blockchain economy
2019 blockchain economy2019 blockchain economy
2019 blockchain economy
 
IWCI21: Distributed Ledgers for Distributed Edge
IWCI21: Distributed Ledgers for Distributed EdgeIWCI21: Distributed Ledgers for Distributed Edge
IWCI21: Distributed Ledgers for Distributed Edge
 
Building a blockchain on tendermint
Building a blockchain on tendermintBuilding a blockchain on tendermint
Building a blockchain on tendermint
 
Block chain 101 what it is, why it matters
Block chain 101  what it is, why it mattersBlock chain 101  what it is, why it matters
Block chain 101 what it is, why it matters
 
Lightweight cryptography
Lightweight cryptographyLightweight cryptography
Lightweight cryptography
 
Blockchain an introduction_n_li
Blockchain an introduction_n_liBlockchain an introduction_n_li
Blockchain an introduction_n_li
 
An Introduction to Blockchains
An Introduction to BlockchainsAn Introduction to Blockchains
An Introduction to Blockchains
 
Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)Ethereum Devcon1 Report (summary writing)
Ethereum Devcon1 Report (summary writing)
 
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profitWeb3’s red pill: Smashing Web3 transaction simulations for fun and profit
Web3’s red pill: Smashing Web3 transaction simulations for fun and profit
 
Blockchain Development
Blockchain DevelopmentBlockchain Development
Blockchain Development
 
Lightweight Address Hopping forDefending the IPv6 IoT
Lightweight Address Hopping forDefending the IPv6 IoTLightweight Address Hopping forDefending the IPv6 IoT
Lightweight Address Hopping forDefending the IPv6 IoT
 

More from Jun Furuse

Tezos 008 Edo protocol
Tezos 008 Edo protocolTezos 008 Edo protocol
Tezos 008 Edo protocolJun Furuse
 
Plebeia, a new storage for Tezos blockchain state
Plebeia, a new storage for Tezos blockchain statePlebeia, a new storage for Tezos blockchain state
Plebeia, a new storage for Tezos blockchain stateJun Furuse
 
SCaml update 2020-06
SCaml update 2020-06SCaml update 2020-06
SCaml update 2020-06Jun Furuse
 
Tezso and on-chain governanace: towards "Kyoto amendment"
Tezso  and on-chain governanace: towards "Kyoto amendment"Tezso  and on-chain governanace: towards "Kyoto amendment"
Tezso and on-chain governanace: towards "Kyoto amendment"Jun Furuse
 
Comparison of Proof of Stakes
Comparison of Proof of StakesComparison of Proof of Stakes
Comparison of Proof of StakesJun Furuse
 
SCaml compiler
SCaml compilerSCaml compiler
SCaml compilerJun Furuse
 
SCaml compiler
SCaml compilerSCaml compiler
SCaml compilerJun Furuse
 
Blockchain and formal verification (Japanese)
Blockchain and formal verification (Japanese)Blockchain and formal verification (Japanese)
Blockchain and formal verification (Japanese)Jun Furuse
 
Tezos Hands on 2019-06-15 Exercise (Japanese)
Tezos Hands on 2019-06-15 Exercise (Japanese)Tezos Hands on 2019-06-15 Exercise (Japanese)
Tezos Hands on 2019-06-15 Exercise (Japanese)Jun Furuse
 
Tezos Hands on 2019-06-15 (Japanese)
Tezos Hands on 2019-06-15 (Japanese)Tezos Hands on 2019-06-15 (Japanese)
Tezos Hands on 2019-06-15 (Japanese)Jun Furuse
 
Tezos and its formal verification (Japanese)
Tezos and its formal verification (Japanese)Tezos and its formal verification (Japanese)
Tezos and its formal verification (Japanese)Jun Furuse
 
Tezos hands-on : Tezos exercise
Tezos hands-on : Tezos exerciseTezos hands-on : Tezos exercise
Tezos hands-on : Tezos exerciseJun Furuse
 
Tezos hands-on : Tezos overview
Tezos hands-on : Tezos overviewTezos hands-on : Tezos overview
Tezos hands-on : Tezos overviewJun Furuse
 
Tezos: Self-amending crypt ledger (Japanese)
Tezos: Self-amending crypt ledger (Japanese)Tezos: Self-amending crypt ledger (Japanese)
Tezos: Self-amending crypt ledger (Japanese)Jun Furuse
 
ブロックチェーンと形式検証
ブロックチェーンと形式検証ブロックチェーンと形式検証
ブロックチェーンと形式検証Jun Furuse
 
Recent tezos core developments
Recent tezos core developmentsRecent tezos core developments
Recent tezos core developmentsJun Furuse
 
Challenges in blockchain certification (Nov 19, 2018 for TPP2018)
Challenges in blockchain certification (Nov 19, 2018 for TPP2018)Challenges in blockchain certification (Nov 19, 2018 for TPP2018)
Challenges in blockchain certification (Nov 19, 2018 for TPP2018)Jun Furuse
 
OCamlOScope: a New OCaml API Search
OCamlOScope: a New OCaml API SearchOCamlOScope: a New OCaml API Search
OCamlOScope: a New OCaml API SearchJun Furuse
 

More from Jun Furuse (19)

Tezos 008 Edo protocol
Tezos 008 Edo protocolTezos 008 Edo protocol
Tezos 008 Edo protocol
 
Plebeia, a new storage for Tezos blockchain state
Plebeia, a new storage for Tezos blockchain statePlebeia, a new storage for Tezos blockchain state
Plebeia, a new storage for Tezos blockchain state
 
SCaml update 2020-06
SCaml update 2020-06SCaml update 2020-06
SCaml update 2020-06
 
Tezso and on-chain governanace: towards "Kyoto amendment"
Tezso  and on-chain governanace: towards "Kyoto amendment"Tezso  and on-chain governanace: towards "Kyoto amendment"
Tezso and on-chain governanace: towards "Kyoto amendment"
 
Comparison of Proof of Stakes
Comparison of Proof of StakesComparison of Proof of Stakes
Comparison of Proof of Stakes
 
SCaml compiler
SCaml compilerSCaml compiler
SCaml compiler
 
SCaml compiler
SCaml compilerSCaml compiler
SCaml compiler
 
Blockchain and formal verification (Japanese)
Blockchain and formal verification (Japanese)Blockchain and formal verification (Japanese)
Blockchain and formal verification (Japanese)
 
Tezos Hands on 2019-06-15 Exercise (Japanese)
Tezos Hands on 2019-06-15 Exercise (Japanese)Tezos Hands on 2019-06-15 Exercise (Japanese)
Tezos Hands on 2019-06-15 Exercise (Japanese)
 
Tezos Hands on 2019-06-15 (Japanese)
Tezos Hands on 2019-06-15 (Japanese)Tezos Hands on 2019-06-15 (Japanese)
Tezos Hands on 2019-06-15 (Japanese)
 
Tezos and its formal verification (Japanese)
Tezos and its formal verification (Japanese)Tezos and its formal verification (Japanese)
Tezos and its formal verification (Japanese)
 
Tezos hands-on : Tezos exercise
Tezos hands-on : Tezos exerciseTezos hands-on : Tezos exercise
Tezos hands-on : Tezos exercise
 
Tezos hands-on : Tezos overview
Tezos hands-on : Tezos overviewTezos hands-on : Tezos overview
Tezos hands-on : Tezos overview
 
Tezos: Self-amending crypt ledger (Japanese)
Tezos: Self-amending crypt ledger (Japanese)Tezos: Self-amending crypt ledger (Japanese)
Tezos: Self-amending crypt ledger (Japanese)
 
ブロックチェーンと形式検証
ブロックチェーンと形式検証ブロックチェーンと形式検証
ブロックチェーンと形式検証
 
Recent tezos core developments
Recent tezos core developmentsRecent tezos core developments
Recent tezos core developments
 
Challenges in blockchain certification (Nov 19, 2018 for TPP2018)
Challenges in blockchain certification (Nov 19, 2018 for TPP2018)Challenges in blockchain certification (Nov 19, 2018 for TPP2018)
Challenges in blockchain certification (Nov 19, 2018 for TPP2018)
 
OCamlOScope: a New OCaml API Search
OCamlOScope: a New OCaml API SearchOCamlOScope: a New OCaml API Search
OCamlOScope: a New OCaml API Search
 
Um2010
Um2010Um2010
Um2010
 

Recently uploaded

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 

Recently uploaded (20)

Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 

Blockchain and Smart Contract Simulation

  • 1. Blockchain Safety and Smart Contract Simulation Tezos Japan, DaiLambda, Inc. Jun FURUSE/古瀬淳, Singapore, NUS, 2019-10-31ASIASIM 2019
  • 3. Blockchain is DB It is a hard computer science! Ledger style Distributed Open/permissionless network
  • 4. Ledger Style DB DB by modification history accumulation: Block consists of basic write operations : . .S0 → B1 S1 → B2 S2 → B3 S3 → B4 = ∅S0 = ( )S1 B1 S0 = ( ) = ( (. . ( ). . ))Sn Bn Sn−1 Bn Bn−1 B1 S0 B o = [ , . . , ]Bn on1 onm = ( ) = (. . ( ( )). . )Sn Bn Sn−1 onm on1 Sn−1
  • 5. Distributed DB Multiple nodes, each carries a replica of the DB: Fault tolerance Load balancing
  • 6. Distributed DB: conflicts How to resolve conflicts? B →→ A x = A x = A x = A →→x = B x = B x = A x = B or ? ? ?
  • 7. Consensus Algorithm Algorithm to resolve conflicts between nodes: Termination All non-faulty nodes eventurally decide on a value. Agreement All nodes decided do so on the same value. Validity The decided value must be proposed by somee. node. Bad news: no such algorithm exists [FLP85].
  • 8. Good news: Paxos Concensus algorithm which may not terminate but practically OK. Voting between nodes to an agreement: Safe Agreement and validity are always assured. Not always Live Termination is not assured. It may repeat votes infinitely. Only for closed network with fixed participants.
  • 9. Closed Network DB If you are happy with closed world, normal distributed DB with Paxos is your friend. No need of “Blockchain”.
  • 10. Open Network DB Permissionless public network, where anyone can join by running a node: Decentralized: no central servers, therefore neutral. Distributed with redundancy: almost impossible to hack. Low cost, compared to the existing social infrastructure.
  • 11. Problem of Open Network Consensus Consensus control and inhibition by Sybil attack: produces fake identities to dominate the network.
  • 12. Satoshi Nakamoto and Bitcoin Prevent Sybil attack, infinite identity forgery: Requirement of real world resource: computation power (PoW) Rewards: incentive to provide the resource and behave honestly. The rewards are recorded as tokens in the DB. Birth of cryptocurrency.
  • 13. Smart Contracts DB can carry not only account balance, but also any data, even program code. Code attached to an account is executed when it receives a transaction. Automatic execution of financial/non-financial contracts Distributed application framework towards neutral and public infrastructrure, without any central authority.
  • 14. Safety Requirements of Blockchain Consequence of introduction of token rewards for open distributed DB: Speculative money flows in. System must be open source. Security holes are immediate targets for theft. Blockchain must have very high level of security.
  • 15. Safety of Smart Contracts Bugs turns smart contracts into automatic stealing machines: Past incidents around smart contracts: The DAO (3.6M ETH, 15% of circulation, 50M USD stolen) Parity vulnerability#1 (150K ETH, 32M USD stolen) Parity vulnerability#2 (513K ETH, 160M USD frozen) High level of security is required here too.
  • 16. Tezos Blockchain 3rd generation blockchain tech. LPoS Eco friendly robust Sybil attack prevention On chain governance Protocol upgrades by on-chain proposals and voting Safety first design Proving safety properties by formal verification
  • 17. Formal Verification Mathematically prove good/bad software properties. Properties are correct for all the cases, if proven. Methods: Type systems, model checking, theorem provers. Tests are important, but not fully trustable: only few corner cases can be verified. No guarantee for the untested cases.
  • 18. Tezos and Formal Verification Protocol Written in OCaml, good match with FV Smart contract VM Statically typed, purely functional stack VM, with structured data such as pairs, lists, map, etc. Smart contract safety Modeling of smart contract interpreter using Coq, and correctness proofs of smart contracts using it. Cryptographic primitives Correctness proof by F* language. Ledger file system With correctness proofs.
  • 19. Blockchain and Simulation Safety can be proven, but how safe is not always provable. Simulation is also important: Concensus P2P network Smart contract etc.
  • 20. Writing to the DB Sending operation to a node: Transactions Account creations, etc Operations spread into the P2P network. → → O1 O1 O1 O1 O1 O1 O2 O2 O2 O2 O2 O2 O2 O2 o
  • 21. Block creation Block proposer chooses operations found in his node and form a block of them. The proposer releases to the network. O1 O1 O2 O2 O2 O2 B = [ O1, O2 ] → B O1 ⇨ B1 = [ O1, O2 ] → B B B B B B B B = [ , . . , ]Bn on1 onm B
  • 22. Smart Contract Simulation Contract is a function: Emulate contract execution of by applying a block only with the call: c : param → operation c(p) Bn−1 = [c(p)]Bn = ( ) = c(p)( )Sn Bn Sn−1 Sn−1
  • 23. Simulation can Differ from the Reality In reality, the call can be interrupted by other ops: Simulation: The call may not be taken into but : Malicious block proposer can insert his op before your call in to change its behaviour: = [c(p)]Bn = c(p)( )Sn Sn−1 Bn Bn+1 = c(p)( )  where   = ( ) ≠Sn+1 Sn Sn Bn Sn−1 Sn−1 o ′ Bn = [ , c(p)]( ) = c(p)( ( ))Sn o ′ Sn−1 o ′ Sn−1
  • 24. Mitigations Fail the call when the simulation and real thing differ? Failing in general does not scale the blockchain. For specific contracts, this behaviour can be useful and implementable with a counter. Or prove contracts are immune to operation permutations: ex. voting. Or repeat simulations over variations of states: Lattice model Monte Carlo
  • 25. Gas cost Contracts are executed on each node. Unrestricted execution such as infinite loops easily results into DDoS attacks. To prevent DDoS, smart contract executions must pay fee proportional to the amount of calculation, gas.
  • 26. VM for Smart Contracts Nodes and smart contracts run in various conditions (CPU architecture, CPU model, memory, etc.). To define and count gas, smart contracts are modeled over a stack VM and interpreted: PUSH, ADD, SUB, IF, .. The gas cost is defined for each VM opcode.
  • 27. How to Decide Gas Cost? Hard to deduce. Too many variables: CPU characteristics Interpreter performance GC timing Argument sizes and structures Simulations come in. (by Ilias Garnier)
  • 28. Gas Cost Simulation in Tezos #1 Guess a formula of gas cost of each opcode with several unknown parameters: ADD for arbitrary precision ints Complexitiy: Formula: GET for map (by balanced tree) Complexitiy: Formula: O(max(size(arg1), size(arg2))) x + y ∗ max(size(arg1), size(arg2)) O(size(key) ∗ log(size(tree))) x + y ∗ size(key) ∗ log(size(set))
  • 29. Gas Cost Simulation in Tezos #2-1 Run each opcode under various conditions to get good approximations of the parameters: Add for arbitrary precision ints Formula: Cost function: x + y ∗ max(size(arg1), size(arg2)) 300 + 0.07 ∗ max(size(arg1), size(arg2))
  • 30. Gas Cost Simulation in Tezos #2-2 Run each opcode under various conditions to get good approximations of the parameters: GET for map (by balanced tree) Formula: Defined cost: x + y ∗ size(key) ∗ log(size(map)) 1000 + 0.07 ∗ size(key) ∗ log(size(map))
  • 31. Gas Cost Simulation in Tezos #3 Boil down to Gas code in the VM interpreter: let add i1 i2 =     atomic_step_cost       (51 + (Compare.Int.max (int_bytes i1) (int_bytes i2) / 62)) let map_access key (module Box) =    let map_card  = snd Box.boxed in    let key_bytes = size_of_comparable Box.key_ty key in    atomic_step_cost ((1 + (key_bytes / 70)) * log2 map_card)
  • 32. Conclusion Blockchain: open distributed ledger DB. Rewards are required to drive concensus. Safety. Tezos pushes formal verification. Simulations play important roles in many places.