SlideShare a Scribd company logo
1 of 37
Download to read offline
Atomic Swaps
Johannes ZwengBCHGraz - Meetup #22, 25.06.2018
What is a “Swap”?
Example:



Alice has BTC
Bob has LTC
They negotiate with each other and
both agree to exchange:

Alice wants to give Bob 1 BTC in
return for 10 LTC
Other word for “Exchange”:
1 BTC 10 LTC
Alice Bob
What is a “Swap”?
But how to make this secure?
If Alice sends her 1 BTC,
how can she be sure, that
she gets the 10 LTC from
Bob?
Bob could just run away…
1 BTC 10 LTC
Alice Bob
What is a “Swap”?
Current Situation:
• Need for trusted 3rd parties

—> Centralized Exchanges
1 BTC 10 LTC
Alice Bob• What if… 



they somehow could exchange

“exactly at the same time” ?
Exchange
Atomic Swap
“An atomic transaction is an indivisible […]
series of […] operations such that either all occur,
or nothing occurs.”
Atomicity:
Atomic Swap
• Basic Idea:

Create transactions, on both chains
• Add a spending condition, which only can get
true on both chains simultaneously (even if chains
are totally unrelated)

Atomic Swap
• Already in 2011 Mike Hearn proposed an idea to
achieve this (see Bitcoin Wiki, Article “Contract”,
Example 5):“Trading across chains”
•
Atomic Swap
The basic idea is the following:
• Initiator (i.e. Alice) thinks of a random secret (“S”)

example: 



“correct horse battery staple”
• She calculates the hash (“H”) of the secret “S”:



“2259cd5b42ae4d70deaa3d8d2ead2bb32ed3677b”
Atomic Swap
• Then Alice sends her funds (1 BTC) into a
“Contract TX” (or “Funding” TX) on the BTC chain,
locking the output like this:
Alice’s BTC Funding TX
“Funding” TX
This is 1 output, with 

2 alternative

spending conditions:
signature Alice



(possible after some

time in future)
signature Bob

+

secret “S” (“correct horse bat…”)

(possible immediately)
1 BTC
failsafe “refund” for
Alice
Going back to Alice
(after some time)
Going to Bob if he knows “S”
OR
• script:
IF
<Key_Bob> CHECKSIGVERIFY
HASH160 <H> EQUALVERIFY
ELSE
<Key_Alice> CHECKSIGVERIFY
<Alice_Timeout> CHECKLOCKTIMEVERIFY
ENDIF

1 Output (ie. 1 BTC)
Can be spent EITHER:
by Bob (Key_Bob) if he knows
the secret “S” which will hash
to the value “H”
OR:
by Alice (Key_Alice) at
some time in future
(failsafe refund)
Alice’s BTC Funding TX
• script:
IF
<Key_Bob> CHECKSIGVERIFY
HASH160 <H> EQUALVERIFY
ELSE
<Key_Alice> CHECKSIGVERIFY
<Alice_Timeout> CHECKLOCKTIMEVERIFY
ENDIF

1 Output (ie. 1 BTC)
Can be spent EITHER:
by Bob (Key_Bob) if he knows
the secret “S” which will hash
to the value “H”
OR:
by Alice (Key_Alice) at
some time in future
(failsafe refund)
0 <sig Alice> (after some time)
1 <sig Bob> <secret S>
• spending input data: OR:
Alice’s BTC Funding TX
This type of Tx are called “HTLC”:

“Hash-time-locked contract”
• script:
IF
<Key_Alice> CHECKSIGVERIFY
HASH160 <H> EQUALVERIFY
ELSE
<Key_Bob> CHECKSIGVERIFY
<Bob_Timeout> CHECKLOCKTIMEVERIFY
ENDIF

1 single Output (ie. 10 LTC)
Can be spent EITHER:
by Alice (Key_Alice) if she
knows (and provides) the
secret “S” which will hash to
the value “H”
OR:
by Bob (Key_Bob) at
some time in future
(failsafe refund)
0 <sig Bob> (after some time)
1 <sig Alice> <secret S>
• spending input data: OR:
Bob’s LTC Funding TX
Source:

https://github.com/decred/atomicswap/blob/master/workflow.svg
Time
Failsafe Timeout Alice
Failsafe Timeout Bob
What do the 2 chains need?
• possibility to somehow time-lock funds (CLTV or
CSV on Bitcoin-like chains)
• support the same hashing algorithm in the
evaluating script
• branching support in scripts (if / else) to realize
failsafe path
• ability to check hashes and signatures in
evaluating script
What do the 2 chains need?
• this is true for most Bitcoin-like chains
• also for smart contract chains (which allow to
program conditions totally free), i.e. Ethereum..



• not possible on chains which don’t allow to
express spending conditions based on hash pre-
image
Secret size attack
Remember, our secret:
• “correct horse battery staple”

which hashes to:
“2259cd5b42ae4d70deaa3d8d2ead2bb32ed3677b”
• Is there a limit for the maximum possible length 

of a secret?
• For Bitcoin: Yes! 520 Bytes (source)
• What if this limit is different between two chains?
source: https://gist.github.com/markblundeberg/7a932c98179de2190049f5823907c016, Dr. Mark B. Lundeberg, Feb 15, 2018
Secret size attack
Example:
• Imagine evil attacker “Eve” 😈 owns FantasyCoin “FC” which allows max. 300
bytes-sized script elements
• Eve and Alice agree to trade 10000 FC against 10 BTC
• Eve creates a secret which is >300 bytes but <520 bytes long and hashes it into
160 bytes
• Eve proceeds as discussed before (locks her FC into the Funding TX, informs Alice)
• As soon as Alice has locked her 10 Bitcoin in her Funding TX, Eve can claim them
(as planned, because she as initiator knows the secret)
• But when Alice now wants to claim her 10000 FC in return, she cannot: although
she now knows the secret, she cannot use it, as it’s too large to be used in a FC
coin script.
Secret size attack
Fortunately, there is an easy solution:
• Add conditon into the script which commits to the
length of the secret
• For Bitcoin Script:

add “OP_SIZE xx 

OP_EQUALVERIFY” 

commands. This way the 

size will be public beforehand:
IF
<Key_Eve> CHECKSIGVERIFY
SIZE 28 EQUALVERIFY 

HASH160 <H> EQUALVERIFY
ELSE
<Key_Alice> CHECKSIGVERIFY
<Bob_Timeout> CHECKLOCKTIMEVERIFY
ENDIF
Tools for on-chain swaps
• “decred”: https://github.com/decred/atomicswap/

• Commanline tools (for each supported chain) to create onchain atomic
swap transactions and perform all steps in the protocol:

• 









• support several chains: BTC, BCH, LTC, Monacoin, Particl, Polis,
Vertcoin, Viacoin, Zcoin (Ethereum contract currently WIP: AtomicSwap.sol)
• BarterDEX by jl777 (used in the Komodo platform): https://
komodoplatform.com/decentralized-exchange/
• Realizes atomic swaps with key pairs chosen using the “Cut and choose”
principle, as proposed by TierNolan in bitcointalk forum in 2016: https://
bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271 and
https://bitcointalk.org/index.php?topic=1364951
• Whitepaper: https://github.com/KomodoPlatform/KomodoPlatform/wiki/
barterDEX-Whitepaper-v2
• More complex, takes 7 steps, needs deposits as incentive, needs percental
fees to mitigate incentive to exploit the cut-and-choose process, …). But
works also if one of the 2 chains has no support for CHECKLOCKTIMEVERIFY
• https://dexstats.info/
Alternative protocol
Same-chain token swaps
For the sake of completeness:

Not cross-chain, but these are also examples of
atomic swaps:
• many ICO contracts on the Ethereum blockchain
(atomically exchange ETH against tokens)
• Onchain ERC-20 Exchanges (like EtherDelta,
IDEX, 0x, etc..) atomically exchange ERC-20
Tokens
Recap onchain swap
• Needs an out-of-band communication channel (i.e.
Alice and Bob need to communicate outside the
protocol (to find each other, for negotiation, updates,
etc…)
• All transactions happen on-chain (and need time for
confirmation)
• Need to pay appropriate fees on both chains, and set
reasonable refund timeouts
• Needs 2 TX (on both chains)
Lightning
• Now, we have lightning.. Yay! 😃 ⚡⚡⚡
• A lightning payment consists of a series of TXs
happening atomically over a route of channels
• Very similar type of transactions (also HTLCs,
slightly different for channel maintenance, but
same base principle)
Recap: One-hop-Lightning
payment example
Alice
Bob
Carol
RH
HTLC
1-day

locktime
H
HTLC
2-day

locktime
H
R
R
The same but adapted for Swap
(Alice is both, sender and receiver)
Alice Bob
RH
BTC
LTC
bitcoind
bitcoind
litecoind
litecoind
HTLC 2-day

lock time
HTLC 1-day

lock time
H R
Status Lightning swaps
• the Lightning Paper mentions “Cross-Chain Payments” as a
further possible use case for the Lightning Network, but no
further details yet
• The lightning protocol specifications (BOLTs) also don’t mention
swap related messages (yet)
• Conner Fromknecht from Lightning Labs did a proof-of-
concept and performed a BTC/LTC swap on testnet using a
modified “lnd” lightning daemon
• See blog article: https://blog.lightning.engineering/
announcement/2017/11/16/ln-swap.html (proof-of-concept
branch on GitHub and a howto, howto2 to recreate his demo)
Details proof of concept
modified “lnd” daemon (lnd already supports Bitcoin and Litecoin, but not
simultaneously yet)
• added new custom cli-commands / parameters:
• --ticker (to specify currency)
• queryswaproutes (outputs a cross-chain route, used as input for sendtoroute,
to explicitly send the payment over this route)Exchange rate statically configured
• exchange rate statically configured
• Basically, swap works like this:



lncli … queryswaproutes --in_amt=100000 --in_ticker=LTC --out_ticker=BTC

lncli … addinvoice --value=100000 --ticker=LTC —> payment_hash

lncli queryswaproutes … | lncli sendtoroute --payment_hash <hash from
invoice>

Summary
• on-chain swaps already possible (and tooling
getting better)
• Lightning supports cross-chain swaps perfectly
by principle, it also seems like a natural fit for
lightning. But not fully there yet. 



There still is the need for concrete specifications to be defined
(gossip protocol, exchange rate publishing, advertising of
supported currency swaps, etc..)
• “Example 5: Trading across chains”, 2011,

https://en.bitcoin.it/wiki/Contract#Example_5:_Trading_across_chains
• “Alt chains and atomic transfers”, 2013,

https://bitcointalk.org/index.php?topic=193281.msg2003765#msg2003765
• “Malleability, deposits and atomic cross chain transfers”, 2014, https://bitcointalk.org/index.php?
topic=515370.0
• “ACCT using CLTV - More Effective than a sleeping pill!”, 2016 https://bitcointalk.org/index.php?
topic=1340621.0
• BIP 0199: “Hashed Time-Locked Contract transactions”
• “BarterDEX – A Practical Native DEX”, 2016, https://github.com/KomodoPlatform/KomodoPlatform/
wiki/BarterDEX-%E2%80%93-A-Practical-Native-DEX
• “Advisory: secret size attack on cross-chain hash lock smart contracts”, Dr. Mark B. Lundeburg,
2018, https://gist.github.com/markblundeberg/7a932c98179de2190049f5823907c016
• “Connecting Blockchains: Instant Cross-Chain Transactions On Lightning”, 2017, https://
blog.lightning.engineering/announcement/2017/11/16/ln-swap.html
References
Thank you for your time!
https://johannes.zweng.at/presentations/2018/atomic_swaps_BCHGraz/
Find the slides here:
Additional ref slides…
Bitcoin supported 

hashing OP_CODES
• OP_RIPEMD160
• OP_SHA1
• OP_SHA256
• OP_HASH160 (SHA-256 + RIPEMD-160)
• OP_SHA256 (double SHA-256)
Online Hash Function Demo
• SHA256: https://anders.com/blockchain/hash.html
• Multiple: https://www.fileformat.info/tool/hash.htm
Atomic Swap (2011 Hearn)
He proposed the following tx scheme

(before there was CLTV or CSV available)
• script:
IF
2 <key A> <key B> 2 CHECKMULTISIGVERIFY
ELSE
<key B> CHECKSIGVERIFY SHA256 <hash of secret A>
EQUALVERIFY <hash of secret B> EQUALVERIFY
ENDIF
• spending data:
1 <sig A> <sig B>
or:
0 <sig B> <secret A> <secret B>
•
Funding TX, before CLTV
“Funding” TX
This is 1 output, with 

2 alternative

spending conditions:
signature Alice

+

signature Bob
signature Bob

+

secret A + secret B
1 BTC
OR“refund Alice”
(nLocktime in future)
Going to Alice
Bob can spend this 

output anywhere he wants 

as soon he

knows secret A



(he knows already secret B as 

secret B is his own)
3) when Bob has signed

the refund TX Alice broadcasts
the locking TX and both wait until it
confirms
2) Alice creates this tx
and let sign it
by Bob, too
1) Alice creates the Funding

TX but does NOT broadcast it
nLocktime vs. CLTV/CSV 

OP codes
nLockTime:
https://en.bitcoin.it/wiki/Protocol_documentation#tx and https://en.bitcoin.it/wiki/NLockTime
nLockTime is a field in the tx Header, tx cannot be included in a block before nLockTime hasn’t been reached
If all inputs in a transaction have nSequence equal to UINT_MAX, then nLockTime is ignored
Locktime-Checking in Script:
BIP 65 - OP_CHECKLOCKTIMEVERIFY (allows a transaction output to be made unspendable until some
point in the future - absolute time, in blocks or timestamp), 2014 (see using CTLV)
BIP 68 (Relative lock-time using consensus-enforced sequence numbers - 2015), 
nSequence Number (32 bits field, Bit (1 << 22) defines type (time vs block), bit (1 << 31) is disable flag (if
set, nSequence has no consensus-related meaning). Time is 512sec units, only 16 bits
Output cannot be used as inout in any tx until output has reached the defined age
BIP 112 later added OP_Code CHECKSEQUENCEVERIFY, to use nSequence as condition in script

More Related Content

Similar to BlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes Zweng

J.burke HackMiami6
J.burke HackMiami6J.burke HackMiami6
J.burke HackMiami6Jesse Burke
 
Towards a Generalised Blockchain Fabric @ CodeBlock 2018
Towards a Generalised Blockchain Fabric @ CodeBlock 2018Towards a Generalised Blockchain Fabric @ CodeBlock 2018
Towards a Generalised Blockchain Fabric @ CodeBlock 2018Alexei Zamyatin
 
Technology of Lightning Network in Tel Aviv, Israel
Technology of Lightning Network in Tel Aviv, IsraelTechnology of Lightning Network in Tel Aviv, Israel
Technology of Lightning Network in Tel Aviv, Israeltakayaimai
 
20190606 blockchain101
20190606 blockchain10120190606 blockchain101
20190606 blockchain101Hu Kenneth
 
The Bitcoin blockchain (en)
The Bitcoin blockchain (en)The Bitcoin blockchain (en)
The Bitcoin blockchain (en)Davide Carboni
 
Blockchain overview, use cases, implementations and challenges
Blockchain overview, use cases, implementations and challengesBlockchain overview, use cases, implementations and challenges
Blockchain overview, use cases, implementations and challengesSébastien Tandel
 
Bitcoin : A fierce decentralized crypto currency - Report
Bitcoin : A fierce decentralized crypto currency - ReportBitcoin : A fierce decentralized crypto currency - Report
Bitcoin : A fierce decentralized crypto currency - ReportShivek Khurana
 
Blockchain. A Guide For Beginners
Blockchain. A Guide For BeginnersBlockchain. A Guide For Beginners
Blockchain. A Guide For BeginnersElifTech
 
The bitcoin blockchain
The bitcoin blockchainThe bitcoin blockchain
The bitcoin blockchainSalah Hawila
 
BlockchainConf.tech - Build a private blockchain workshop
BlockchainConf.tech - Build a private blockchain workshopBlockchainConf.tech - Build a private blockchain workshop
BlockchainConf.tech - Build a private blockchain workshopPad Kankipati
 
Replay Protection - Bitcoin Devs HK 2017-11-01
Replay Protection - Bitcoin Devs HK 2017-11-01Replay Protection - Bitcoin Devs HK 2017-11-01
Replay Protection - Bitcoin Devs HK 2017-11-01Sjors Provoost
 
Bitcoin and the Rise of the Block Chains
Bitcoin and the Rise of the Block ChainsBitcoin and the Rise of the Block Chains
Bitcoin and the Rise of the Block ChainsDallas Kennedy
 
Flaying the Blockchain Ledger for Fun, Profit, and Hip Hop
Flaying the Blockchain Ledger for Fun, Profit, and Hip HopFlaying the Blockchain Ledger for Fun, Profit, and Hip Hop
Flaying the Blockchain Ledger for Fun, Profit, and Hip HopAndrew Morris
 
Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)
Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)
Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)Zvi Avraham
 
Introduction to Blockchain Web3 Session
Introduction to Blockchain Web3 SessionIntroduction to Blockchain Web3 Session
Introduction to Blockchain Web3 SessionDSCIITPatna
 
The Bitcoin Rocketship @ BTC Miami 2015
The Bitcoin Rocketship @ BTC Miami 2015The Bitcoin Rocketship @ BTC Miami 2015
The Bitcoin Rocketship @ BTC Miami 2015Jeff Garzik
 
Cryptocurrency-Bitcoin
Cryptocurrency-BitcoinCryptocurrency-Bitcoin
Cryptocurrency-BitcoinSatwikaHotwani
 
Libbitcoin slides
Libbitcoin slidesLibbitcoin slides
Libbitcoin slidesswansontec
 

Similar to BlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes Zweng (20)

J.burke HackMiami6
J.burke HackMiami6J.burke HackMiami6
J.burke HackMiami6
 
Towards a Generalised Blockchain Fabric @ CodeBlock 2018
Towards a Generalised Blockchain Fabric @ CodeBlock 2018Towards a Generalised Blockchain Fabric @ CodeBlock 2018
Towards a Generalised Blockchain Fabric @ CodeBlock 2018
 
Technology of Lightning Network in Tel Aviv, Israel
Technology of Lightning Network in Tel Aviv, IsraelTechnology of Lightning Network in Tel Aviv, Israel
Technology of Lightning Network in Tel Aviv, Israel
 
20190606 blockchain101
20190606 blockchain10120190606 blockchain101
20190606 blockchain101
 
The Bitcoin blockchain (en)
The Bitcoin blockchain (en)The Bitcoin blockchain (en)
The Bitcoin blockchain (en)
 
Blockchain overview, use cases, implementations and challenges
Blockchain overview, use cases, implementations and challengesBlockchain overview, use cases, implementations and challenges
Blockchain overview, use cases, implementations and challenges
 
Cryptocurrencies
CryptocurrenciesCryptocurrencies
Cryptocurrencies
 
Bitcoin : A fierce decentralized crypto currency - Report
Bitcoin : A fierce decentralized crypto currency - ReportBitcoin : A fierce decentralized crypto currency - Report
Bitcoin : A fierce decentralized crypto currency - Report
 
Blockchain. A Guide For Beginners
Blockchain. A Guide For BeginnersBlockchain. A Guide For Beginners
Blockchain. A Guide For Beginners
 
The bitcoin blockchain
The bitcoin blockchainThe bitcoin blockchain
The bitcoin blockchain
 
BlockchainConf.tech - Build a private blockchain workshop
BlockchainConf.tech - Build a private blockchain workshopBlockchainConf.tech - Build a private blockchain workshop
BlockchainConf.tech - Build a private blockchain workshop
 
Replay Protection - Bitcoin Devs HK 2017-11-01
Replay Protection - Bitcoin Devs HK 2017-11-01Replay Protection - Bitcoin Devs HK 2017-11-01
Replay Protection - Bitcoin Devs HK 2017-11-01
 
Bitcoin and the Rise of the Block Chains
Bitcoin and the Rise of the Block ChainsBitcoin and the Rise of the Block Chains
Bitcoin and the Rise of the Block Chains
 
Flaying the Blockchain Ledger for Fun, Profit, and Hip Hop
Flaying the Blockchain Ledger for Fun, Profit, and Hip HopFlaying the Blockchain Ledger for Fun, Profit, and Hip Hop
Flaying the Blockchain Ledger for Fun, Profit, and Hip Hop
 
Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)
Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)
Ethereum VM and DSLs for Smart Contracts (updated on May 12th 2015)
 
Introduction to Blockchain Web3 Session
Introduction to Blockchain Web3 SessionIntroduction to Blockchain Web3 Session
Introduction to Blockchain Web3 Session
 
The Bitcoin Rocketship @ BTC Miami 2015
The Bitcoin Rocketship @ BTC Miami 2015The Bitcoin Rocketship @ BTC Miami 2015
The Bitcoin Rocketship @ BTC Miami 2015
 
Study on Bitcoin
Study on Bitcoin Study on Bitcoin
Study on Bitcoin
 
Cryptocurrency-Bitcoin
Cryptocurrency-BitcoinCryptocurrency-Bitcoin
Cryptocurrency-Bitcoin
 
Libbitcoin slides
Libbitcoin slidesLibbitcoin slides
Libbitcoin slides
 

More from BlockchainHub Graz

BlockchainHub Graz Meetup #27 - Krypto-Assets & Steuern - Natalie Enzinger
BlockchainHub Graz Meetup #27 - Krypto-Assets & Steuern - Natalie EnzingerBlockchainHub Graz Meetup #27 - Krypto-Assets & Steuern - Natalie Enzinger
BlockchainHub Graz Meetup #27 - Krypto-Assets & Steuern - Natalie EnzingerBlockchainHub Graz
 
BlockchainHub Graz Meetup #25 - ELASTOS - Semir Ramovic
BlockchainHub Graz Meetup #25 - ELASTOS - Semir RamovicBlockchainHub Graz Meetup #25 - ELASTOS - Semir Ramovic
BlockchainHub Graz Meetup #25 - ELASTOS - Semir RamovicBlockchainHub Graz
 
BlockchainHub Graz Meetup #24 - Self-Sovereign Identity - Andreas Abraham
BlockchainHub Graz Meetup #24 - Self-Sovereign Identity - Andreas AbrahamBlockchainHub Graz Meetup #24 - Self-Sovereign Identity - Andreas Abraham
BlockchainHub Graz Meetup #24 - Self-Sovereign Identity - Andreas AbrahamBlockchainHub Graz
 
BlockchainHub Graz Meetup #23 - State Channels - Ralph Pichler
BlockchainHub Graz Meetup #23 - State Channels - Ralph PichlerBlockchainHub Graz Meetup #23 - State Channels - Ralph Pichler
BlockchainHub Graz Meetup #23 - State Channels - Ralph PichlerBlockchainHub Graz
 
BCHGraz - Meetup #16 - Blockchain Real Life Usecases - Dr. Peter Teufl
BCHGraz - Meetup #16 - Blockchain Real Life Usecases - Dr. Peter TeuflBCHGraz - Meetup #16 - Blockchain Real Life Usecases - Dr. Peter Teufl
BCHGraz - Meetup #16 - Blockchain Real Life Usecases - Dr. Peter TeuflBlockchainHub Graz
 
BCHGraz - Meetup #15 - Blockchain in Real Estate - Walter Strametz
BCHGraz - Meetup #15 - Blockchain in Real Estate - Walter StrametzBCHGraz - Meetup #15 - Blockchain in Real Estate - Walter Strametz
BCHGraz - Meetup #15 - Blockchain in Real Estate - Walter StrametzBlockchainHub Graz
 
BCHGraz - Meetup #14 - Seratio Token - Prof. Olinga Ta'eed
BCHGraz - Meetup #14 - Seratio Token - Prof. Olinga Ta'eedBCHGraz - Meetup #14 - Seratio Token - Prof. Olinga Ta'eed
BCHGraz - Meetup #14 - Seratio Token - Prof. Olinga Ta'eedBlockchainHub Graz
 
BCHGraz - Meetup #12 - ICO Rechtliche Grundlagen - Oliver Völkel
BCHGraz - Meetup #12 - ICO Rechtliche Grundlagen - Oliver VölkelBCHGraz - Meetup #12 - ICO Rechtliche Grundlagen - Oliver Völkel
BCHGraz - Meetup #12 - ICO Rechtliche Grundlagen - Oliver VölkelBlockchainHub Graz
 
BCHGraz - Meetup #12 - ICO Basics
BCHGraz - Meetup #12 - ICO BasicsBCHGraz - Meetup #12 - ICO Basics
BCHGraz - Meetup #12 - ICO BasicsBlockchainHub Graz
 
BCHGraz - Meetup #11 - Bitsquare DAO by Manfred Karrer
BCHGraz - Meetup #11 - Bitsquare DAO by Manfred KarrerBCHGraz - Meetup #11 - Bitsquare DAO by Manfred Karrer
BCHGraz - Meetup #11 - Bitsquare DAO by Manfred KarrerBlockchainHub Graz
 
BCHGraz - Meetup #10 - DASH (digital cash) by Valentin Kalinov
BCHGraz - Meetup #10 - DASH (digital cash) by Valentin KalinovBCHGraz - Meetup #10 - DASH (digital cash) by Valentin Kalinov
BCHGraz - Meetup #10 - DASH (digital cash) by Valentin KalinovBlockchainHub Graz
 
BCHGraz - Meetup #9 - Monero by Justin Ehrenhofer
BCHGraz - Meetup #9 - Monero by Justin EhrenhoferBCHGraz - Meetup #9 - Monero by Justin Ehrenhofer
BCHGraz - Meetup #9 - Monero by Justin EhrenhoferBlockchainHub Graz
 
BCHGraz - Meetup #8 - Intro & Ethereum
 BCHGraz - Meetup #8 - Intro & Ethereum BCHGraz - Meetup #8 - Intro & Ethereum
BCHGraz - Meetup #8 - Intro & EthereumBlockchainHub Graz
 
Blockchain Coding Dojo - BlockchainHub Graz
Blockchain Coding Dojo - BlockchainHub GrazBlockchain Coding Dojo - BlockchainHub Graz
Blockchain Coding Dojo - BlockchainHub GrazBlockchainHub Graz
 
Ripple - the good, the bad and the ugly
Ripple - the good, the bad and the uglyRipple - the good, the bad and the ugly
Ripple - the good, the bad and the uglyBlockchainHub Graz
 
BCHGraz - NEM Blockchain Tech - Intro
BCHGraz - NEM Blockchain Tech - IntroBCHGraz - NEM Blockchain Tech - Intro
BCHGraz - NEM Blockchain Tech - IntroBlockchainHub Graz
 
BCHGraz - Apostille - NEM Blockchain Tech
BCHGraz - Apostille - NEM Blockchain Tech BCHGraz - Apostille - NEM Blockchain Tech
BCHGraz - Apostille - NEM Blockchain Tech BlockchainHub Graz
 
IOTA Presentation - BlockchainHub Graz Meetup #5
IOTA Presentation - BlockchainHub Graz Meetup #5 IOTA Presentation - BlockchainHub Graz Meetup #5
IOTA Presentation - BlockchainHub Graz Meetup #5 BlockchainHub Graz
 
RSK (Rootstock) - Smarter Bitcoin
RSK (Rootstock) - Smarter BitcoinRSK (Rootstock) - Smarter Bitcoin
RSK (Rootstock) - Smarter BitcoinBlockchainHub Graz
 

More from BlockchainHub Graz (20)

BlockchainHub Graz Meetup #27 - Krypto-Assets & Steuern - Natalie Enzinger
BlockchainHub Graz Meetup #27 - Krypto-Assets & Steuern - Natalie EnzingerBlockchainHub Graz Meetup #27 - Krypto-Assets & Steuern - Natalie Enzinger
BlockchainHub Graz Meetup #27 - Krypto-Assets & Steuern - Natalie Enzinger
 
BlockchainHub Graz Meetup #25 - ELASTOS - Semir Ramovic
BlockchainHub Graz Meetup #25 - ELASTOS - Semir RamovicBlockchainHub Graz Meetup #25 - ELASTOS - Semir Ramovic
BlockchainHub Graz Meetup #25 - ELASTOS - Semir Ramovic
 
BlockchainHub Graz Meetup #24 - Self-Sovereign Identity - Andreas Abraham
BlockchainHub Graz Meetup #24 - Self-Sovereign Identity - Andreas AbrahamBlockchainHub Graz Meetup #24 - Self-Sovereign Identity - Andreas Abraham
BlockchainHub Graz Meetup #24 - Self-Sovereign Identity - Andreas Abraham
 
BlockchainHub Graz Meetup #23 - State Channels - Ralph Pichler
BlockchainHub Graz Meetup #23 - State Channels - Ralph PichlerBlockchainHub Graz Meetup #23 - State Channels - Ralph Pichler
BlockchainHub Graz Meetup #23 - State Channels - Ralph Pichler
 
BCHGraz - Meetup #16 - Blockchain Real Life Usecases - Dr. Peter Teufl
BCHGraz - Meetup #16 - Blockchain Real Life Usecases - Dr. Peter TeuflBCHGraz - Meetup #16 - Blockchain Real Life Usecases - Dr. Peter Teufl
BCHGraz - Meetup #16 - Blockchain Real Life Usecases - Dr. Peter Teufl
 
BCHGraz - Meetup #15 - Blockchain in Real Estate - Walter Strametz
BCHGraz - Meetup #15 - Blockchain in Real Estate - Walter StrametzBCHGraz - Meetup #15 - Blockchain in Real Estate - Walter Strametz
BCHGraz - Meetup #15 - Blockchain in Real Estate - Walter Strametz
 
BCHGraz - Meetup #14 - Seratio Token - Prof. Olinga Ta'eed
BCHGraz - Meetup #14 - Seratio Token - Prof. Olinga Ta'eedBCHGraz - Meetup #14 - Seratio Token - Prof. Olinga Ta'eed
BCHGraz - Meetup #14 - Seratio Token - Prof. Olinga Ta'eed
 
BCHGraz - Meetup #12 - ICO Rechtliche Grundlagen - Oliver Völkel
BCHGraz - Meetup #12 - ICO Rechtliche Grundlagen - Oliver VölkelBCHGraz - Meetup #12 - ICO Rechtliche Grundlagen - Oliver Völkel
BCHGraz - Meetup #12 - ICO Rechtliche Grundlagen - Oliver Völkel
 
BCHGraz - Meetup #12 - ICO Basics
BCHGraz - Meetup #12 - ICO BasicsBCHGraz - Meetup #12 - ICO Basics
BCHGraz - Meetup #12 - ICO Basics
 
BCHGraz - Meetup #11 - Bitsquare DAO by Manfred Karrer
BCHGraz - Meetup #11 - Bitsquare DAO by Manfred KarrerBCHGraz - Meetup #11 - Bitsquare DAO by Manfred Karrer
BCHGraz - Meetup #11 - Bitsquare DAO by Manfred Karrer
 
BCHGraz - Meetup #10 - DASH (digital cash) by Valentin Kalinov
BCHGraz - Meetup #10 - DASH (digital cash) by Valentin KalinovBCHGraz - Meetup #10 - DASH (digital cash) by Valentin Kalinov
BCHGraz - Meetup #10 - DASH (digital cash) by Valentin Kalinov
 
BCHGraz - Meetup #9 - Monero by Justin Ehrenhofer
BCHGraz - Meetup #9 - Monero by Justin EhrenhoferBCHGraz - Meetup #9 - Monero by Justin Ehrenhofer
BCHGraz - Meetup #9 - Monero by Justin Ehrenhofer
 
BCHGraz - Meetup #8 - Intro & Ethereum
 BCHGraz - Meetup #8 - Intro & Ethereum BCHGraz - Meetup #8 - Intro & Ethereum
BCHGraz - Meetup #8 - Intro & Ethereum
 
Blockchain Coding Dojo - BlockchainHub Graz
Blockchain Coding Dojo - BlockchainHub GrazBlockchain Coding Dojo - BlockchainHub Graz
Blockchain Coding Dojo - BlockchainHub Graz
 
BCHGraz - Meetup #7 - Intro
BCHGraz - Meetup #7 - IntroBCHGraz - Meetup #7 - Intro
BCHGraz - Meetup #7 - Intro
 
Ripple - the good, the bad and the ugly
Ripple - the good, the bad and the uglyRipple - the good, the bad and the ugly
Ripple - the good, the bad and the ugly
 
BCHGraz - NEM Blockchain Tech - Intro
BCHGraz - NEM Blockchain Tech - IntroBCHGraz - NEM Blockchain Tech - Intro
BCHGraz - NEM Blockchain Tech - Intro
 
BCHGraz - Apostille - NEM Blockchain Tech
BCHGraz - Apostille - NEM Blockchain Tech BCHGraz - Apostille - NEM Blockchain Tech
BCHGraz - Apostille - NEM Blockchain Tech
 
IOTA Presentation - BlockchainHub Graz Meetup #5
IOTA Presentation - BlockchainHub Graz Meetup #5 IOTA Presentation - BlockchainHub Graz Meetup #5
IOTA Presentation - BlockchainHub Graz Meetup #5
 
RSK (Rootstock) - Smarter Bitcoin
RSK (Rootstock) - Smarter BitcoinRSK (Rootstock) - Smarter Bitcoin
RSK (Rootstock) - Smarter Bitcoin
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 

Recently uploaded (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 

BlockchainHub Graz Meetup #22 - Atomic Swaps - Johannes Zweng

  • 1. Atomic Swaps Johannes ZwengBCHGraz - Meetup #22, 25.06.2018
  • 2. What is a “Swap”? Example:
 
 Alice has BTC Bob has LTC They negotiate with each other and both agree to exchange:
 Alice wants to give Bob 1 BTC in return for 10 LTC Other word for “Exchange”: 1 BTC 10 LTC Alice Bob
  • 3. What is a “Swap”? But how to make this secure? If Alice sends her 1 BTC, how can she be sure, that she gets the 10 LTC from Bob? Bob could just run away… 1 BTC 10 LTC Alice Bob
  • 4. What is a “Swap”? Current Situation: • Need for trusted 3rd parties
 —> Centralized Exchanges 1 BTC 10 LTC Alice Bob• What if… 
 
 they somehow could exchange
 “exactly at the same time” ? Exchange
  • 5. Atomic Swap “An atomic transaction is an indivisible […] series of […] operations such that either all occur, or nothing occurs.” Atomicity:
  • 6. Atomic Swap • Basic Idea:
 Create transactions, on both chains • Add a spending condition, which only can get true on both chains simultaneously (even if chains are totally unrelated)

  • 7. Atomic Swap • Already in 2011 Mike Hearn proposed an idea to achieve this (see Bitcoin Wiki, Article “Contract”, Example 5):“Trading across chains” •
  • 8. Atomic Swap The basic idea is the following: • Initiator (i.e. Alice) thinks of a random secret (“S”)
 example: 
 
 “correct horse battery staple” • She calculates the hash (“H”) of the secret “S”:
 
 “2259cd5b42ae4d70deaa3d8d2ead2bb32ed3677b”
  • 9. Atomic Swap • Then Alice sends her funds (1 BTC) into a “Contract TX” (or “Funding” TX) on the BTC chain, locking the output like this:
  • 10. Alice’s BTC Funding TX “Funding” TX This is 1 output, with 
 2 alternative
 spending conditions: signature Alice
 
 (possible after some
 time in future) signature Bob
 +
 secret “S” (“correct horse bat…”)
 (possible immediately) 1 BTC failsafe “refund” for Alice Going back to Alice (after some time) Going to Bob if he knows “S” OR
  • 11. • script: IF <Key_Bob> CHECKSIGVERIFY HASH160 <H> EQUALVERIFY ELSE <Key_Alice> CHECKSIGVERIFY <Alice_Timeout> CHECKLOCKTIMEVERIFY ENDIF
 1 Output (ie. 1 BTC) Can be spent EITHER: by Bob (Key_Bob) if he knows the secret “S” which will hash to the value “H” OR: by Alice (Key_Alice) at some time in future (failsafe refund) Alice’s BTC Funding TX
  • 12. • script: IF <Key_Bob> CHECKSIGVERIFY HASH160 <H> EQUALVERIFY ELSE <Key_Alice> CHECKSIGVERIFY <Alice_Timeout> CHECKLOCKTIMEVERIFY ENDIF
 1 Output (ie. 1 BTC) Can be spent EITHER: by Bob (Key_Bob) if he knows the secret “S” which will hash to the value “H” OR: by Alice (Key_Alice) at some time in future (failsafe refund) 0 <sig Alice> (after some time) 1 <sig Bob> <secret S> • spending input data: OR: Alice’s BTC Funding TX This type of Tx are called “HTLC”:
 “Hash-time-locked contract”
  • 13. • script: IF <Key_Alice> CHECKSIGVERIFY HASH160 <H> EQUALVERIFY ELSE <Key_Bob> CHECKSIGVERIFY <Bob_Timeout> CHECKLOCKTIMEVERIFY ENDIF
 1 single Output (ie. 10 LTC) Can be spent EITHER: by Alice (Key_Alice) if she knows (and provides) the secret “S” which will hash to the value “H” OR: by Bob (Key_Bob) at some time in future (failsafe refund) 0 <sig Bob> (after some time) 1 <sig Alice> <secret S> • spending input data: OR: Bob’s LTC Funding TX
  • 15. What do the 2 chains need? • possibility to somehow time-lock funds (CLTV or CSV on Bitcoin-like chains) • support the same hashing algorithm in the evaluating script • branching support in scripts (if / else) to realize failsafe path • ability to check hashes and signatures in evaluating script
  • 16. What do the 2 chains need? • this is true for most Bitcoin-like chains • also for smart contract chains (which allow to program conditions totally free), i.e. Ethereum..
 
 • not possible on chains which don’t allow to express spending conditions based on hash pre- image
  • 17. Secret size attack Remember, our secret: • “correct horse battery staple”
 which hashes to: “2259cd5b42ae4d70deaa3d8d2ead2bb32ed3677b” • Is there a limit for the maximum possible length 
 of a secret? • For Bitcoin: Yes! 520 Bytes (source) • What if this limit is different between two chains? source: https://gist.github.com/markblundeberg/7a932c98179de2190049f5823907c016, Dr. Mark B. Lundeberg, Feb 15, 2018
  • 18. Secret size attack Example: • Imagine evil attacker “Eve” 😈 owns FantasyCoin “FC” which allows max. 300 bytes-sized script elements • Eve and Alice agree to trade 10000 FC against 10 BTC • Eve creates a secret which is >300 bytes but <520 bytes long and hashes it into 160 bytes • Eve proceeds as discussed before (locks her FC into the Funding TX, informs Alice) • As soon as Alice has locked her 10 Bitcoin in her Funding TX, Eve can claim them (as planned, because she as initiator knows the secret) • But when Alice now wants to claim her 10000 FC in return, she cannot: although she now knows the secret, she cannot use it, as it’s too large to be used in a FC coin script.
  • 19. Secret size attack Fortunately, there is an easy solution: • Add conditon into the script which commits to the length of the secret • For Bitcoin Script:
 add “OP_SIZE xx 
 OP_EQUALVERIFY” 
 commands. This way the 
 size will be public beforehand: IF <Key_Eve> CHECKSIGVERIFY SIZE 28 EQUALVERIFY 
 HASH160 <H> EQUALVERIFY ELSE <Key_Alice> CHECKSIGVERIFY <Bob_Timeout> CHECKLOCKTIMEVERIFY ENDIF
  • 20. Tools for on-chain swaps • “decred”: https://github.com/decred/atomicswap/
 • Commanline tools (for each supported chain) to create onchain atomic swap transactions and perform all steps in the protocol:
 • 
 
 
 
 
 • support several chains: BTC, BCH, LTC, Monacoin, Particl, Polis, Vertcoin, Viacoin, Zcoin (Ethereum contract currently WIP: AtomicSwap.sol)
  • 21. • BarterDEX by jl777 (used in the Komodo platform): https:// komodoplatform.com/decentralized-exchange/ • Realizes atomic swaps with key pairs chosen using the “Cut and choose” principle, as proposed by TierNolan in bitcointalk forum in 2016: https:// bitcointalk.org/index.php?topic=1340621.msg13828271#msg13828271 and https://bitcointalk.org/index.php?topic=1364951 • Whitepaper: https://github.com/KomodoPlatform/KomodoPlatform/wiki/ barterDEX-Whitepaper-v2 • More complex, takes 7 steps, needs deposits as incentive, needs percental fees to mitigate incentive to exploit the cut-and-choose process, …). But works also if one of the 2 chains has no support for CHECKLOCKTIMEVERIFY • https://dexstats.info/ Alternative protocol
  • 22. Same-chain token swaps For the sake of completeness:
 Not cross-chain, but these are also examples of atomic swaps: • many ICO contracts on the Ethereum blockchain (atomically exchange ETH against tokens) • Onchain ERC-20 Exchanges (like EtherDelta, IDEX, 0x, etc..) atomically exchange ERC-20 Tokens
  • 23. Recap onchain swap • Needs an out-of-band communication channel (i.e. Alice and Bob need to communicate outside the protocol (to find each other, for negotiation, updates, etc…) • All transactions happen on-chain (and need time for confirmation) • Need to pay appropriate fees on both chains, and set reasonable refund timeouts • Needs 2 TX (on both chains)
  • 24. Lightning • Now, we have lightning.. Yay! 😃 ⚡⚡⚡ • A lightning payment consists of a series of TXs happening atomically over a route of channels • Very similar type of transactions (also HTLCs, slightly different for channel maintenance, but same base principle)
  • 26. The same but adapted for Swap (Alice is both, sender and receiver) Alice Bob RH BTC LTC bitcoind bitcoind litecoind litecoind HTLC 2-day
 lock time HTLC 1-day
 lock time H R
  • 27. Status Lightning swaps • the Lightning Paper mentions “Cross-Chain Payments” as a further possible use case for the Lightning Network, but no further details yet • The lightning protocol specifications (BOLTs) also don’t mention swap related messages (yet) • Conner Fromknecht from Lightning Labs did a proof-of- concept and performed a BTC/LTC swap on testnet using a modified “lnd” lightning daemon • See blog article: https://blog.lightning.engineering/ announcement/2017/11/16/ln-swap.html (proof-of-concept branch on GitHub and a howto, howto2 to recreate his demo)
  • 28. Details proof of concept modified “lnd” daemon (lnd already supports Bitcoin and Litecoin, but not simultaneously yet) • added new custom cli-commands / parameters: • --ticker (to specify currency) • queryswaproutes (outputs a cross-chain route, used as input for sendtoroute, to explicitly send the payment over this route)Exchange rate statically configured • exchange rate statically configured • Basically, swap works like this:
 
 lncli … queryswaproutes --in_amt=100000 --in_ticker=LTC --out_ticker=BTC
 lncli … addinvoice --value=100000 --ticker=LTC —> payment_hash
 lncli queryswaproutes … | lncli sendtoroute --payment_hash <hash from invoice>

  • 29. Summary • on-chain swaps already possible (and tooling getting better) • Lightning supports cross-chain swaps perfectly by principle, it also seems like a natural fit for lightning. But not fully there yet. 
 
 There still is the need for concrete specifications to be defined (gossip protocol, exchange rate publishing, advertising of supported currency swaps, etc..)
  • 30. • “Example 5: Trading across chains”, 2011,
 https://en.bitcoin.it/wiki/Contract#Example_5:_Trading_across_chains • “Alt chains and atomic transfers”, 2013,
 https://bitcointalk.org/index.php?topic=193281.msg2003765#msg2003765 • “Malleability, deposits and atomic cross chain transfers”, 2014, https://bitcointalk.org/index.php? topic=515370.0 • “ACCT using CLTV - More Effective than a sleeping pill!”, 2016 https://bitcointalk.org/index.php? topic=1340621.0 • BIP 0199: “Hashed Time-Locked Contract transactions” • “BarterDEX – A Practical Native DEX”, 2016, https://github.com/KomodoPlatform/KomodoPlatform/ wiki/BarterDEX-%E2%80%93-A-Practical-Native-DEX • “Advisory: secret size attack on cross-chain hash lock smart contracts”, Dr. Mark B. Lundeburg, 2018, https://gist.github.com/markblundeberg/7a932c98179de2190049f5823907c016 • “Connecting Blockchains: Instant Cross-Chain Transactions On Lightning”, 2017, https:// blog.lightning.engineering/announcement/2017/11/16/ln-swap.html References
  • 31. Thank you for your time! https://johannes.zweng.at/presentations/2018/atomic_swaps_BCHGraz/ Find the slides here:
  • 33. Bitcoin supported 
 hashing OP_CODES • OP_RIPEMD160 • OP_SHA1 • OP_SHA256 • OP_HASH160 (SHA-256 + RIPEMD-160) • OP_SHA256 (double SHA-256)
  • 34. Online Hash Function Demo • SHA256: https://anders.com/blockchain/hash.html • Multiple: https://www.fileformat.info/tool/hash.htm
  • 35. Atomic Swap (2011 Hearn) He proposed the following tx scheme
 (before there was CLTV or CSV available) • script: IF 2 <key A> <key B> 2 CHECKMULTISIGVERIFY ELSE <key B> CHECKSIGVERIFY SHA256 <hash of secret A> EQUALVERIFY <hash of secret B> EQUALVERIFY ENDIF • spending data: 1 <sig A> <sig B> or: 0 <sig B> <secret A> <secret B> •
  • 36. Funding TX, before CLTV “Funding” TX This is 1 output, with 
 2 alternative
 spending conditions: signature Alice
 +
 signature Bob signature Bob
 +
 secret A + secret B 1 BTC OR“refund Alice” (nLocktime in future) Going to Alice Bob can spend this 
 output anywhere he wants 
 as soon he
 knows secret A
 
 (he knows already secret B as 
 secret B is his own) 3) when Bob has signed
 the refund TX Alice broadcasts the locking TX and both wait until it confirms 2) Alice creates this tx and let sign it by Bob, too 1) Alice creates the Funding
 TX but does NOT broadcast it
  • 37. nLocktime vs. CLTV/CSV 
 OP codes nLockTime: https://en.bitcoin.it/wiki/Protocol_documentation#tx and https://en.bitcoin.it/wiki/NLockTime nLockTime is a field in the tx Header, tx cannot be included in a block before nLockTime hasn’t been reached If all inputs in a transaction have nSequence equal to UINT_MAX, then nLockTime is ignored Locktime-Checking in Script: BIP 65 - OP_CHECKLOCKTIMEVERIFY (allows a transaction output to be made unspendable until some point in the future - absolute time, in blocks or timestamp), 2014 (see using CTLV) BIP 68 (Relative lock-time using consensus-enforced sequence numbers - 2015),  nSequence Number (32 bits field, Bit (1 << 22) defines type (time vs block), bit (1 << 31) is disable flag (if set, nSequence has no consensus-related meaning). Time is 512sec units, only 16 bits Output cannot be used as inout in any tx until output has reached the defined age BIP 112 later added OP_Code CHECKSEQUENCEVERIFY, to use nSequence as condition in script