Three way atomic cross chain swap

ETHCC 3 · March 2020 · 26:01

Léonard Lys examines three-way atomic swaps across chains.

Speakers

Topics

From ETHCC 3, hosted by Ethereum France.

Transcript

okay that's the prison tomorrow so hi

everyone I'm Leon Arliss I'm a researcher at La boîte on automatic devices which is under district computer just a few blocks away and I'm also a consultant at variety so today I will present you my work on atomic credit crunch science labs and how to enhance them with relays and adapters it's kind of funny that I'm doing my talk right after Alexey because is stating that you can't do hdl-c without TTP and I'm stating that maybe you could so few words about my company we are an international consultancy company based

in Paris but we operate in seven countries and we have 400 experts ranging from developers to Pio and designers one year ago we found it with my colleague after a blockchain unit inside our company and we have two main focus which are interoperability and uux in depth because in our point of view to start the two main pain points for blockchain mass adoption so yeah as I said our skills range from research to

development as I'm a researcher and a PhD candidate but we also have developers and the partnership with the laboratory and finally we are the proud asked of the g5 meetup which is in our office in Paris every second Thursday of the month so yeah please come by it's it's very fun okay so let's dive in an atomic christian swap is basically a trustless transaction between two parties ex swapping assets on two different different chains like trading Bitcoin for eaters there are three main some

atomic substrate strategies you have centralized multi signature regimes do somewhat centralized exchanges are doing well you need a trusted third party you have side chains and relays and as time locking so I will be talking about side chains relay and hash time locking so what are some like contracts basically it's a simple commit reveal protocol you lock a coin inside a contract and this coin can be unlocked by the initiator but only after a certain amount of time

or by the participant but only if he is able to provide a secret s that has been generated by the initiator so I'll just what how does the protocol looks like in general so you have Alice Bob your blockchain alpha blockchain beta and the first step is that Alice generator secrets s and computes its its H then she sets up an agency contract on the blockchain alpha the transaction goes from Alice to Bob Jumanji Swan the secret is the one she computed and the lock time is

tomorrow at 6:30 so as you can see the this they have to settle a price of chain they have to to to meet off chain and to do lots of processes of chain then once Alice has set hdl-c she will send Bob the ID of the transaction and Bob will parse the Alice's transaction to verify the lock time the amount and the secret the hashed secret so we will copy the ash secret and setup itself in

hdl-c on blockchain and blockchain beta so transaction goes from Bob to Alice the amount is 1 the secret is the ash secret is the one it just copied and the lock time is tomorrow at 5:30 as you can see the lock time of the second contract is inferior to the one on the first contract that's to prevent a list to do a kind of double span attack on Bob I will I'll come back later to this Delta of time between both lock times at this point both contracts have been set up and it's time for them to redeem the contract so Bob will tell to Alice of

chain that the contract is ready so Alice will sign the transaction and provide the secret by doing so she will unlock the coin and receive it but she will also reveal the secret Bob now that bob has the secret you can go to Alice's hdl-c sign it provide the secret and redeemed a coin so that's how the scenario looks like when everything is okay but if at any point of the protocol any of the participants stops acting because

do not crash because they don't want to swap anymore any anything well they won't unlock the coin and to to be refunded they just have to wait for the time lock to expire and sign the transaction and be refunded okay so to sum up an atomic swap is a particular that guarantees that any honest participant that complies to the protocol will not end up worse off but the problem is that a node crash happen network overload happen so you also you also depends on the livability of your

client and this cannot be ensured that's why some are stating that you need a trusted third party to to do an atomic cross chain swap with hdl-c then another problem is that hdl-c atomic crushing swap as slow as the slowest blockchain involved in the trade meaning that I told you about this Delta of time the second hdl-c lock time has to be inferior to the first hdl-c lock time and the Delta between those two lock time has to be significant compared to the block time of the slowest blockchain so for example

for Bitcoin it's reasonable to assume that you need at least six confirmation six confirmation meaning about an hour the Delta of time has to be significant - like compared to when I was so maybe like two hours meaning the scale of time of an atomic crush and swap is huge then another trade-off is that it requires the participants to be on line and to execute a lot of lots of tasks well if a client's crashes the the participant will end up worse off so

that's a secondary trade-off then because of the high numbers of transactions you have to do at least two times two means for transactions so you have to pay for four transactions fees it's not competitive compared to the exchanges fields and finally the participants blockchain node is a single point of failure so why am i doing a still atomic swaps because hdl-c atomic swap can be combined with other technologies such as relays and external adapters and I'm not the one saying it it's a quote from God himself

it states in a paper that Ash locking can be combined with relays so on the right this is a very naive sequence diagram of an atomic swap and what we do want to improve is allow for decentralized order matching because on this diagram you can see that both parties agreed on the price of chain prior to initiating this web so first thing we want to do is allow for decentralized order matching and decentralized other book

second thing we want to do is automate editing because auditing a contract is a pain in the ass and it's it's it requires some technical skills the a naive user as do not have the skills to do that and finally we want to reduce the amount of user actions to only one we want to be competitive compared to centralized exchange platforms so in a centralization platform you just place your order and wait for it to be completed so we want the the the user experience to be as good as in a centralized exchange

platform so first how do we do to allow for decentralized order matching well on this screen you have two hdl-c in interface the first one is the HT HT LC interface of the knife protocol of this this sequence diagram it does not allows for decentralized or on chain order matching because you have to set up the participant address when you initiate this one but with this this the second interface with this enhanced interface you set you initiate the swap so you

lock the coin before setting the participant so it's trivial to say that you could make an order matching contract that will parse the HDL C contract for operant rate you can make an interface and then people will just have to call this this or this transaction in order to to initiate this one okay then the two other thing we want to improve is automate editing's and reduce the amount of user acts of user actions so to automate auditing we will make use of relays and regiment of user actions we will use what we call

adapters so I will tell you what's my definition of relays and and adapters so to me a bit easier relay is as as explained alexei earlier is a smart contract that as light client capabilities so for example a Bitcoin relay on the ATM blockchain is as a contract that allows you to read the state of the big conduction from the ATM blockchain it works by publishing a blog headers of the Bitcoin blockchain sandy theorem

block chains and then you have a smart contract that does the cryptography of verifying transaction and it's totally feasible to to implement an interface for developers to I'd the complexity of the cryptographic functions then adaptors is a service mounted on a blockchain note that lets you access to off chain data and to access of chains api here is a little scheme of the architecture of chain link external adapters so the red arrow here means

that this connection is attenti fide so the data that is here can be sensitive data for example you could totally imagine putting the secret and the ash of the secret inside of this external adapter you could also put your Bitcoin and ether own private key in order to be able to sign at broadcast transaction from the adapter etc etc so it is the the sequence diagram of my proposal the real sequence diagram is more complex because you have several adapters and

several relays actually you have two adapters and two relays so to simplify it I do as if there was only one one one of each but this side is blockchain ad other side is blockchain be okay so remember the relay is able to read the state of the other blockchain and the adapter is is able to sign generate and broadcast transaction to both both blockchains the relay is a smart contract and both hdl-c Austin and chain a H and B are also smart contract

so they can totally communicate and call each other last thing the adapter is is a part that is off chain so you can totally make cron jobs a triggering transaction this this is totally feasible and the adapter also has access to a node because it's mounted onto a node so it can broadcast transactions so how does it work Alice if she wants to initiate a transaction instead of calling directly to hdl-c that is a state on chain a she will call the adapter the adapter will generate

the secret compute the eyes of the secret and stir it inside some protected data store and the adapter will call the hdl-c with the the generated parameters and the the open transaction the open swap will appear on a decentralized auto key Bob has access to this other book and can totally cool for this for this trade and then the adapter when Bob calls will verify that Alice's transaction is correct so it verifies the parameters of

alice of Alice's transaction it verifies the lock time the amount etcetera etc the relay sends back to the adapter the transaction parameters and it triggers and if the transaction parameters has okayed the adapter triggers the hdl-c on the other sign and initiate the swap then when the swap has been initiated the hdl-c on the blockchain B will return the transaction parameter and at this point the swap has been initiated popcorn our unlocked on on on on each block chain but the participant have not

been set yet so the adapter will call a request set participant to the hdl-c on blockchain a the hdl-c will call the relay the relay will verify the parameters and if Bob's hdl-c has been correctly set up then it will actually set the participant on the other hdl-c then you have exactly the same procedure for for for Bob's contract so requested participant we verify in the relays that the transaction is okay and if the transaction is okay he actually set the

participant saying that alice is the participant finally last last last stage everything is setup the participant has set up the coins are locked everything's okay so the adapter will send to the hdl-c on blockchain a request regime to request alice's contract to unlock bob's coins and doing so revealing to Bob the secret well - Bob's adapters and same process with the regime it sends back the secret right error and Bob's

adapters we'll withdraw the coin so with this protocol by combining relays adapters and as time-locked contract you can totally do an atomic swap with only one user action but well there are quite a few limitations and cons of this protocol well for the moment it will require you to run a node and an adapter that's quite a V in terms of infrastructure but I've been discussing with some chain

link guys and they are working on a trusted and environment trusted execution environment that could allow you to mount your adapter on someone's else's node without fearing that you could see your Bitcoin key or your secret second problem is that it's still as slow as the slowest blockchain you are using but it could totally be plugged to any lay off to scalability blockchain and last last thing is it still vulnerable

to the ghost attack it's when a participant considered that the swap is not profitable to him anymore so it stops the protocol but you could prevent that by making a little fee when you initiate a transaction that is refunded if you go to the end of the protocol but that is burned if you don't finish the protocol okay so well that's it feel free to reach out if you have any questions oh you have anyone has any questions wait anyone have any questions I guess

so basically the idea is to create an order book where you can execute cross-chain atomic swap transactions let's say yeah and okay so I didn't really get how do you set the receiver after you already created hqc isn't this some point of failure because you said that this is the upgrade you don't put the receiver in the initial creation of the swap yeah but you added after that who is adding it and can this be corrupted no well if you think about a solidity like environment it's well you

can say you can give okay each swap is a structure and it's shop as parameters and each swap as a state okay you can tell that if the swap state is called initiated and not open then the coin can move I can't move like you you you put modifiers you you put a modifier that states only only initiated swap or only open swaps that's totally totally feasible okay but it should be two parties or one party third party which is verifying the parameters on Bitcoin site on the theory on site and

yet if everything is fine then it is using this modifier to set the receiver on the theorem side yes that's a but which is the third party I mean no I think the third party you of thinking about is the relay the relay is like a lightweight client a street on blockchain be that as lightweight client capabilities on blockchain a it works by publishing blocks of blockchain be inside blockchain a then you can make a smart contract that as the same cryptographic capabilities

than the the blockchain a and you can verify and decode the transaction that's induction B from blockchain a sieve I mean maybe we can do with a relay you can read the state of another block chain from one blockchain okay so you can submit to the relay a transaction from another blockchain and also the relay is this transaction a real transaction and what are the parameters of this transaction so you can verify that the lock time is okay that the amount is okay you can verify that you can do the auditing of the transaction

directly on chain okay that's super cool and one last thing you can modify the swap structure on the solidity side but how can you do it on the Bitcoin side because bitcoin script is a little bit limited and I'm not sure if you can do this you can do this I will send you my github does an implementation of any money on anyone else all right another clap I guess thank you all right cool Alex I guess that's a 12:30 though yeah

here yes the next week is 12:30 Soria