SlideShare a Scribd company logo
Qtum
How Qtum Makes EVM Run on the UTXO Model
Patrick Dai (Cofounder of Qtum)
18th
Feb 2017@EDCON Paris
UTXO (Unspent Transaction Outputs)
1) The basis of bitcoin transaction
2) Stateless
3) Parallelism
4) SPV
Build smart contract base on stateless UTXO
sets?
New Opcodes
Qtum Account Abstraction Layer
Three New Opcodes
1.OP_EXEC - This opcode will trigger special processing of a
transaction and will execute the EVM bytecode passed to it.
OP_EXEC is primarily used to deploy new smart contracts.
2.OP_EXEC_ASSIGN - This opcode will also trigger special
processing like OP_EXEC. This opcode is passed a contract address
and data to give the contract. It will then execute the contract’s
bytecode while passing in the given data (given as CALLERDATA in
EVM). This opcode is also used for sending money to a smart
contract.
3.OP_TXHASH - Spend the OP_EXEC_ASSIGN’s Vouts after
checking they belong to the contract trying to spend them.
<sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash?> OP_EQUALVERIFY OP_CHECKSIG
<sig>
✓<pubKey>
<pubKey>
<pubKeyHash?>
<pubKeyHash>
true
Figure 1 - Bitcoin script execution
Alan Turing
23 June 1912 – 7 June 1954
I am not impressed
How to execute smart contract immediately when
merged into the blockchain?
1) Special processing of transaction output scripts (ScriptPubKey) which contains either OP_EXEC
or OP_EXEC_ASSIGN
2) When one of these opcodes are detected in a script, it is executed by all nodes of the network
after the transaction is placed into a block as output.
3) When Qtum encounters OP_EXEC or OP_EXEC_ASSIGN it runs some initial checks, then feeds
the code and gas values to the EVM
4) Executes the code and applies changes to its state and returns execution results to Qtum core
including the regular EVM results such as gas used…
Qtum Account Abstraction Layer
Account Abstraction Layer which translates
the UTXO-based model to an account-based
interface for the EVM to use
How to Deploy and Call a Contract in
Qtum?
1) Create a new zero balance contract using OP_EXEC
2) Call the contract using OP_EXEC_ASSIGN opcode
The output script (scriptPubkey) which sends money to the contract syntax
; ( )1 the version of the VM EVM is 1
;10000 gas limit for the transaction
;100 gas price in Qtum satoshis
;0xF012 data to send the contract
;0x1452b22265803b201ac1f8bb25840cb70afe3303 address of
the contract
OP_EXEC_ASSIGN
The value to send to the contract is passed using the
Assign Funds and/or Message contract TX
Figure 2 - Assign Funds
and/or Message contract TX
Contract to Contract or to Public Key Hash Address
payment
Expected Contract Transactions List: Contract spend transactions generated by the
miner and added to a block
1) Contract spends one or more of its owned output
2) These transactions must be include in a block to be considered
valid
3) Generated by miners while verifying and executing transactions,
rather than being generated by consumers
4) No need to broadcast contract transactions on the P2P network.
Spend contract OP_EXEC_ASSIGN
transaction
Figure 3 - Spend contract OP_EXEC_ASSIGN transac
Consensus-critical Coin Picking Algorithm
• To avoid nodes picking different outputs to spend contract funds,We
designed a strict and simple consensus-critical coin picking algorithm.
• First In First Out
• Any miner/node who picks different outputs will be rejected, because
it will fail at the block verification.
Figure 4 - Qtum Block Validation
showing Expected Contract
Transaction List
Standard transaction types: Bitcoin Script
templates
Deploying a new contract to the blockchain should use an output script which looks like so:
1; the version of the VM
[Gas limit]
[Gas price]
[Contract EVM bytecode]
OP_EXEC
Sending Funds and Message to an already deployed contract on the blockchain:
1; the version of the VM
[Gas limit]
[Gas price]
[Data to send to the contract]
[contract address]
OP_EXEC_ASSIGN
Note : there are no standard transaction type which can spend either of these. This is because they can
only be spent by using the Expected Contract Transaction List, and thus these spending transactions
would not be broadcast nor valid on the P2P network.
Gas model
•gas_fee = gas_limit * gas_price
•Txfee = vin - vout
•tx_relay_fee = txfee - gas_fee
•refund = gas_fee - used_gas
Gas refund model
Figure 5 - Gas refund model
Qtum General Architecture
Figure 6 - Qtum General Architecture
SPV : Simple Payment Verification
Figure 7 - testnet and mobile smartcontract Figure 8 - Apple
Watch Wallet

More Related Content

PPTX
Advanced smart contract
PPTX
Solidity
PPTX
Hands on with smart contracts
PPTX
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
PDF
Blockchain Coding Dojo - BlockchainHub Graz
PDF
Implement ERC20 on TestRPC
PPTX
Dex and Uniswap
PPTX
Smart Contracts with Solidity hands-on training session
Advanced smart contract
Solidity
Hands on with smart contracts
Hands on with smart contracts 2. Presentation for the Blockchain Applications...
Blockchain Coding Dojo - BlockchainHub Graz
Implement ERC20 on TestRPC
Dex and Uniswap
Smart Contracts with Solidity hands-on training session

Viewers also liked (19)

PPTX
Integração das tecnologias móveis nas sala de aula através do eTwinning
PPT
5º mandamento (2)
PDF
Sem3 nivel1 gomez cruz
PDF
Você sabe para que serve a etiqueta têxtil? (cartilha)
PDF
Unionsic apres oficial 07-2016 kevinmtsen@yahoo.com.br
PDF
Preguntas 3-encu-clau
PDF
July, 2014 Vol. 18 No.3
PPTX
Infokvällen 2014 power point4 feb med skolstartsdatum
PPSX
Apresentacion libertagia-beta-1.9
PDF
XMPP Hands-On
DOCX
Deliverable Master Copy
PDF
More Licenses, More Problems
DOCX
saskia_koerner_resume_2015_photo
PDF
Marçojardim
PDF
Outline Thesis
PDF
July, 2014 Vol. 18 No.3
PPTX
CRISPRfrancesca
PDF
Fendall porta stream_i
PDF
Creative Teams
Integração das tecnologias móveis nas sala de aula através do eTwinning
5º mandamento (2)
Sem3 nivel1 gomez cruz
Você sabe para que serve a etiqueta têxtil? (cartilha)
Unionsic apres oficial 07-2016 kevinmtsen@yahoo.com.br
Preguntas 3-encu-clau
July, 2014 Vol. 18 No.3
Infokvällen 2014 power point4 feb med skolstartsdatum
Apresentacion libertagia-beta-1.9
XMPP Hands-On
Deliverable Master Copy
More Licenses, More Problems
saskia_koerner_resume_2015_photo
Marçojardim
Outline Thesis
July, 2014 Vol. 18 No.3
CRISPRfrancesca
Fendall porta stream_i
Creative Teams
Ad

Similar to Qtum How To Make EVM Run On UTXO Model - Patrick Dai (6)

PDF
"Programming Smart Contracts on Ethereum" by Anatoly Ressin from AssistUnion ...
PPTX
EVM - The Heart of Ethereum
PPTX
Qtum
PDF
Encode Club: Nethermind Workshop EVM Bootcamp
PPTX
Smart contract
PPTX
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
"Programming Smart Contracts on Ethereum" by Anatoly Ressin from AssistUnion ...
EVM - The Heart of Ethereum
Qtum
Encode Club: Nethermind Workshop EVM Bootcamp
Smart contract
Eclipsecon Europe: Blockchain, Ethereum and Business Applications
Ad

Recently uploaded (20)

PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Hybrid model detection and classification of lung cancer
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Approach and Philosophy of On baking technology
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Getting Started with Data Integration: FME Form 101
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
project resource management chapter-09.pdf
A novel scalable deep ensemble learning framework for big data classification...
Group 1 Presentation -Planning and Decision Making .pptx
Hybrid model detection and classification of lung cancer
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
1. Introduction to Computer Programming.pptx
Enhancing emotion recognition model for a student engagement use case through...
Approach and Philosophy of On baking technology
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Digital-Transformation-Roadmap-for-Companies.pptx
DP Operators-handbook-extract for the Mautical Institute
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Hindi spoken digit analysis for native and non-native speakers
Programs and apps: productivity, graphics, security and other tools
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Getting Started with Data Integration: FME Form 101
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A comparative study of natural language inference in Swahili using monolingua...
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
project resource management chapter-09.pdf

Qtum How To Make EVM Run On UTXO Model - Patrick Dai

  • 1. Qtum How Qtum Makes EVM Run on the UTXO Model Patrick Dai (Cofounder of Qtum) 18th Feb 2017@EDCON Paris
  • 2. UTXO (Unspent Transaction Outputs) 1) The basis of bitcoin transaction 2) Stateless 3) Parallelism 4) SPV
  • 3. Build smart contract base on stateless UTXO sets?
  • 4. New Opcodes Qtum Account Abstraction Layer
  • 5. Three New Opcodes 1.OP_EXEC - This opcode will trigger special processing of a transaction and will execute the EVM bytecode passed to it. OP_EXEC is primarily used to deploy new smart contracts. 2.OP_EXEC_ASSIGN - This opcode will also trigger special processing like OP_EXEC. This opcode is passed a contract address and data to give the contract. It will then execute the contract’s bytecode while passing in the given data (given as CALLERDATA in EVM). This opcode is also used for sending money to a smart contract. 3.OP_TXHASH - Spend the OP_EXEC_ASSIGN’s Vouts after checking they belong to the contract trying to spend them.
  • 6. <sig> <pubKey> OP_DUP OP_HASH160 <pubKeyHash?> OP_EQUALVERIFY OP_CHECKSIG <sig> ✓<pubKey> <pubKey> <pubKeyHash?> <pubKeyHash> true Figure 1 - Bitcoin script execution Alan Turing 23 June 1912 – 7 June 1954 I am not impressed
  • 7. How to execute smart contract immediately when merged into the blockchain? 1) Special processing of transaction output scripts (ScriptPubKey) which contains either OP_EXEC or OP_EXEC_ASSIGN 2) When one of these opcodes are detected in a script, it is executed by all nodes of the network after the transaction is placed into a block as output. 3) When Qtum encounters OP_EXEC or OP_EXEC_ASSIGN it runs some initial checks, then feeds the code and gas values to the EVM 4) Executes the code and applies changes to its state and returns execution results to Qtum core including the regular EVM results such as gas used…
  • 8. Qtum Account Abstraction Layer Account Abstraction Layer which translates the UTXO-based model to an account-based interface for the EVM to use
  • 9. How to Deploy and Call a Contract in Qtum? 1) Create a new zero balance contract using OP_EXEC 2) Call the contract using OP_EXEC_ASSIGN opcode The output script (scriptPubkey) which sends money to the contract syntax ; ( )1 the version of the VM EVM is 1 ;10000 gas limit for the transaction ;100 gas price in Qtum satoshis ;0xF012 data to send the contract ;0x1452b22265803b201ac1f8bb25840cb70afe3303 address of the contract OP_EXEC_ASSIGN The value to send to the contract is passed using the
  • 10. Assign Funds and/or Message contract TX Figure 2 - Assign Funds and/or Message contract TX
  • 11. Contract to Contract or to Public Key Hash Address payment Expected Contract Transactions List: Contract spend transactions generated by the miner and added to a block 1) Contract spends one or more of its owned output 2) These transactions must be include in a block to be considered valid 3) Generated by miners while verifying and executing transactions, rather than being generated by consumers 4) No need to broadcast contract transactions on the P2P network.
  • 12. Spend contract OP_EXEC_ASSIGN transaction Figure 3 - Spend contract OP_EXEC_ASSIGN transac
  • 13. Consensus-critical Coin Picking Algorithm • To avoid nodes picking different outputs to spend contract funds,We designed a strict and simple consensus-critical coin picking algorithm. • First In First Out • Any miner/node who picks different outputs will be rejected, because it will fail at the block verification.
  • 14. Figure 4 - Qtum Block Validation showing Expected Contract Transaction List
  • 15. Standard transaction types: Bitcoin Script templates Deploying a new contract to the blockchain should use an output script which looks like so: 1; the version of the VM [Gas limit] [Gas price] [Contract EVM bytecode] OP_EXEC Sending Funds and Message to an already deployed contract on the blockchain: 1; the version of the VM [Gas limit] [Gas price] [Data to send to the contract] [contract address] OP_EXEC_ASSIGN Note : there are no standard transaction type which can spend either of these. This is because they can only be spent by using the Expected Contract Transaction List, and thus these spending transactions would not be broadcast nor valid on the P2P network.
  • 16. Gas model •gas_fee = gas_limit * gas_price •Txfee = vin - vout •tx_relay_fee = txfee - gas_fee •refund = gas_fee - used_gas
  • 17. Gas refund model Figure 5 - Gas refund model
  • 18. Qtum General Architecture Figure 6 - Qtum General Architecture
  • 19. SPV : Simple Payment Verification Figure 7 - testnet and mobile smartcontract Figure 8 - Apple Watch Wallet