BITCOIN TRANSACTION MALLEABILITY THEORY IN PRACTICE
Daniel Chechik, Rami Kogan Security Researchers
THEORY IN PRACTICE Daniel Chechik, Rami Kogan Security Researchers - - PowerPoint PPT Presentation
BITCOIN TRANSACTION MALLEABILITY THEORY IN PRACTICE Daniel Chechik, Rami Kogan Security Researchers Agenda What is Bitcoin Bitcoin Transactions Transaction Malleability Vulnerability What Happened in MT.Gox Live Demo WHAT IS
BITCOIN TRANSACTION MALLEABILITY THEORY IN PRACTICE
Daniel Chechik, Rami Kogan Security Researchers
Agenda
WHAT IS BITCOIN?
What is Bitcoin?
software in 2009 by a developer known as Satoshi Nakamoto
money/coins.
What is a Block?
Block Chain
PreviousBlockHash
PreviousBlockHash
PreviousBlockHash
What is a Block?
Wh What at is a a Bl Block ck?
Field Description Size
Blocksize Number of bytes following up to end of block 4 bytes Transaction counter Positive integer VI = VarInt 1 - 9 bytes Blockheader Consists of 6 items 80 bytes Transactions The (non empty) list of <Transaction counter>-many transactions transactions Magic No Value Always 0xD9B4BEF9 4 bytes
Bl Block ck Hea eader der Str truct cture ure
Field Purpose Updated when... Size (Bytes) Version Block version number You upgrade the software and it specifies a new version 4 hashMerkleRoot 256-bit hash based on all of the transactions in the block A transaction is accepted 32 Time Current timestamp as seconds since 1970-01- 01T00:00 UTC Every few seconds 4 Bits Current target in compact format The difficulty is adjusted 4 Nonce e 32-bit number (starts at 0) A hash is tried 4 hashPre revB vBloc lock 256-bit hash of the previous A new block comes in 32
Wh What at Is Is Min inin ing?
What is Mining?
Memory
Pending Pending Pending
Transaction Transaction Transaction … … Transaction
What is Mining?
What is Mining?
What is Mining?
LET’S SIMULATE MINING RIGHT NOW!
Keep a steady network Record all coin data
Additional Mining Goals
Bitcoin – what we’ve learned so far …
steady and to generate blocks.
TRANSACTIONS
Transactions
Alice Bob
Broadcasted to network Collected by miners Confirmed (Block Solved)
100 BTC
Alice Bob
Bob’s Wallet 100 MYC
Transactions
Broadcasted to network
Alice Bob
100 MYC
Transactions
Collected by miners Broadcasted to network
Alice Bob
100 MYC
Transactions
Confirmed (Block Solved) Collected by miners
100 MYC
Broadcasted to network
Alice Bob
Transactions
Transactions
Transactions are built from two main components
(Ref to Txout in block chain)
Inputs
Outputs
Transactions
Transactions
TRANSACTION MALLEABILITY
P2P Lottery
MessageID (sha256) From: Lottery Prize: You won a Car! To: “Rami” Length … Signature (DER) Length …
Life supply of
Vegemite
P2P Lottery
MessageID (sha256) From: Lottery Prize: You won a Car! To: “Rami” Length … Signature (DER) …
ID CAR SUPPLIED f5d8ee...
✓
Length
5e67s… ✓
P2P Lottery
P2P Lottery
Standard Transaction
ScriptSig Input
Signature Public Key
Output
Source of Coins
ScriptSig
TxId (sha256*2)
Amount of Coins
ScriptPubKey (Redeemer’s address)
Standard Transaction
ScriptSig Input
Signature Public Key
Output
Source of Coins
Redeemer + Amount of Coins
1 byt e
Length
TxId (sha256*2)
Amount of Coins
ScriptPubKey (Redeemer’s address)
Standard Transaction
ScriptSig Input
Signature Public Key
Output
Source of Coins
Redeemer + Amount of Coins
2 byt e
Length
TxId (sha256*2)
Amount of Coins
ScriptPubKey (Redeemer’s address)
Standard Transaction
ScriptSig Input
Signature Public Key
Output
Source of Coins
Redeemer + Amount of Coins
2 byte pushdata2
(1 byte)
TxId (sha256*2)
Amount of Coins
ScriptPubKey (Redeemer’s address)
Standard Transaction
ScriptSig Input
Signature Public Key
Output
Source of Coins
Redeemer + Amount of Coins
0x3
Length
TxId (sha256*2)
Amount of Coins
ScriptPubKey (Redeemers address)
Standard Transaction
ScriptSig Input
Signature Public Key
Output
Source of Coins
Redeemer + Amount of Coins
0x3
pushdata2 TxId (sha256*2)
Amount of Coins
ScriptPubKey (Redeemers address)
0x4D
Standard Transaction
ScriptSig Input
Signature Public Key
Output
Source of Coins
Redeemer + Amount of Coins
0x3
pushdata2 TxId (sha256*2)
Amount of Coins
ScriptPubKey (Redeemers address)
0x4D 0x00
Standard Transaction
ScriptSig Input
Signature Public Key
Output
Source of Coins
Redeemer + Amount of Coins
pushdata2 TxId (sha256*2)
Amount of Coins
ScriptPubKey (Redeemers address)
0x4D 0x3000
Lit ittle e Endi dian: 0x3000 3000 0x0030 0030 0x003 0030 0 == == 0x30 30
Standard Transaction
ScriptSig Input
Signature Public Key
Output
Source of Coins
Redeemer + Amount of Coins
pushdata2 TxId (sha256*2)
Amount of Coins
ScriptPubKey (Redeemers address)
0x4D 0x3000
Standard Vs Mutated
Mutated TxId = dc34efd49ed738bf4500db367292164166989cb1577302 6e9e185b78292bbc89 TxId = c6cfe6e4f129a34671d10c1bbe158eff05197d388 727e331951b0ec2637c194e
Transaction Malleability
Rejected Transactions
WHAT HAPPENED IN MT.GOX?
MT.Gox Announcement
P2P Bitcoin Mt.Gox
30BTC -> Attacker’s Wallet
B330….…5088
Attacker Attacker’s Wallet
30BTC -> Attacker’s Wallet
B330….…5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet
ScriptSig ScriptPubkey
B330….…5088
0x19 0x30 …
30BTC
…
30BTC -> Attacker’s Wallet
B330….…5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet
ScriptSig ScriptPubkey
B330….…5088
0x19 0x30 …
30BTC
…
30 30BTC -> > Attacker’s Wallet
B330 330….…5088 5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet
ScriptSig ScriptPubkey
B330 330….…5088 5088
0x19 0x30 …
30BT C
…
Mut utated ed Transa nsacti ction
Valid Signature
0x30
…
C3a8…….03 03f8 8
30BTC -> Attacker’s Wallet
B330….…5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet
Mutated Transaction
Valid Signature
0x30
…
C3a8…….03f8
30BTC -> Attacker’s Wallet
C3a8…….03f8
30BTC -> Attacker’s Wallet
B330….…5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet W
30BTC -> Attacker’s Wallet
C3a8…….03f8
30BTC -> Attacker’s Wallet
B330….…5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet W
ScriptSig ScriptPubkey B330…….5088
0x19 0x30 …
30BTC
…
Unconfirmed Tx
30BTC -> Attacker’s Wallet
B330….…5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet W
Transaction (B330….…5088) Failed?!?
Unconfirmed
30BTC -> Attacker’s Wallet
C3a8…….03f8
30BTC -> Attacker’s Wallet
C3a8…….03f8
30BTC -> Attacker’s Wallet
B330….…5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet W
Transaction (B330….…5088) Failed?!?
Generate Another Transaction!
Unconfirmed
30BTC -> Attacker’s Wallet
C3a8…….03f8
30BTC -> Attacker’s Wallet
B330….…5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet W
Transaction (B330….…5088) Failed?!?
Unconfirmed
Generate Another Transaction!
30BTC -> Attacker’s Wallet
C3a8…….03f8
30BTC -> Attacker’s Wallet
B330….…5088
P2P Bitcoin Mt.Gox Attacker Attacker’s Wallet W
Transaction (B330….…5088) Failed?!?
Unconfirmed
Generate Another Transaction!
DEMO
BLOCKCHAIN OPINION
PUSHDATA Mutated Transaction
1000 2000 3000 4000 5000 6000 Dec-12 Jan-13 Feb-13 Mar-13 Apr-13 May-13 Jun-13 Jul-13 Aug-13 Sep-13 Oct-13 Nov-13 Dec-13 Jan-14 Feb-14 Mar-14 Apr-14 May-14 Jun-14 Jul-14 Aug-14 Malleable Transaction
PUSHDATA Mutated Transaction
79 79 1900 1900 3569 3569 2 2 11 11 22 22 Malleable Transaction
Mt.Go .Gox announ uncem cemen ent
Who was The Target?!
MALLEABILITY FIX
Transaction Malleability Fix
Transaction Malleability Fix
Daniel Chechik – daniel.chechik@gmail.com (@danielchechik) Rami Kogan – ramikogan@yahoo.com Ben Hayak – ben.hayak@gmail.com (@benhayak)
Thank You!
BTC: 12qPtFhw9UPL8HvfSsSjvqxeFXp4hRiWym
References
Github - https://github.com/sipa/bitcoin/commit/87fe71e1fc810ee120a10063fdd26c3245686d54 Spiderlabs – http://www.spiderlabs.com Bitcoin official document - https://bitcoin.org/bitcoin.pdf Bitcoin Wiki - https://en.bitcoin.it/wiki Bitcoin Transaction Malleability Wiki - https://en.bitcoin.it/wiki/Transaction_Malleability Ken Shirriff - http://www.righto.com/2014/02/bitcoin-transaction-malleability.html