Building xChain Applications with Connext with Rahul Sethuram

ETH Seoul 2022 · August 2022 · 23:39

Rahul Sethuram, co-founder and CTO of Connext, explains how to build cross-chain applications. The talk maps the multi-chain landscape of separate clusters and compares natively, externally, locally and optimistically verified bridges against the interoperability trilemma of extensibility, generalizability and trust minimization. It describes how fraud-proof watchers, circuit breakers and liquidity providers improve security and speed, then shows xcall, a Solidity-style primitive for cross-chain calls and callbacks, with projects such as Superfluid and Fuji DAO building on it.

Speakers

Topics

From ETH Seoul 2022, hosted by Kryptoplanet.

Transcript

hello hey everyone uh thanks for joining my talk is about building x-chain cross-chain applications with connex oh sorry okay so just as an intro my name is rahul i'm the co-founder and cto of connext uh i've been in the space since about 2017. we started connects in 2017 so we've been around for a long time been doing a lot of different things in the space like state channels fiat on-ramps dows and now we've actually moved into interoperability which we think is is a really cool space

um so just to give some background this is how the old world you know like back in the day in 2016 2017 etc used to look you had eth you had bitcoin you have these very like kind of distinct and separate ecosystems where there was no real way to link between them like if you have funds on ethereum and you want to get to bitcoin really the only thing you could do pretty much is go through a centralized exchange and now what we're seeing come together is a multi-chain world so you have these distinct clusters of different chains that are popping up all over and they have these very distinct ecosystems between them so you have eat plus the roll-ups they're sort of forming this own little cluster

and then you have cosmos which has its own little cluster as well you also have polka dot and now you have even things like polygon is launching like these things called supernet avalanche has subnet bnb has these app specific chains so you're really kind of starting to see multi-chain as in a multi-cluster ecosystem and with that we get to what bridging means in this new multi-chain world so the first type of bridging is intra cluster bridging so that means you have like these little connections within these little clusters and uh some of these ecosystems have done this really well like for example cosmos has built ibc's so from the get-go they wanted this thing called inter-plus

intra-cluster communication so they built uh inter-blockchain communication as ibc protocol also polka dot has xcm so these uh in between these little clusters you have this communication that's a very powerful communication tool uh polygon avalanche all these other cluster-based ecosystems are all building bridges in between like this but then you get to this harder problem where you have like this problem of how do you get from roll up on ethereum to this chain on cosmos then to polka dot then back to some other rollup so that's where you have like kind of like a harder problem that is not solved by these intracluster bridges now like what exactly is a bridge so

let's back up and figure that out so bridge is you have alice who's on origin chain a wants to send a message to a destination chain so she will say something on an origin chain then something happens some kind of magic process then you get something to happen on a destination chain and then this can either be this can be like sending tokens this can be sending messages this could be like sending data this could be a smart contract call it doesn't matter what it is but something has to happen so let's dive in and figure out what is this magic so there's a few different ways that you can bridge and i'll try to talk about some of the main ways that we've thought about bridging so far so natively verified bridges that means a chain's own validators verify the tx's

so this if we go back to this sorry here i'm going to back up a little bit but this intra cluster bridging is built using native natively verified bridges so in practice a natively verified bridge means that a chain's nodes are running light clients of all the other uh chains within this cluster like if you go to roll-up bridges all the the ethereum nodes are actually verifying the transactions that are going on in rollups if you go to cosmos ibc every cosmos node that has a ibc connection to another cosmos node is running a light client validator of that other chain so this is the probably the most secure and best way to bridge

but the problem is it's not generalizable like you can't have ethereum validators validating transactions on cosmos that's just never gonna happen so this this the problem with this the trade-off that you get with this type of bridge is that it's not generalizable if you want to solve that trade-off you can do this other kind of type of bridge which is called an externally verified bridge this means you have a third party of validators so you have this set of validators that uses proof-of-stake multi-sigs other things like that to validate a transaction from one chain to another chain and this solves the generalizability problem but now you get into an issue where this is not trust minimized you have to actually trust the validators of this bridge and then you have another way you can do

it which is a locally verified system so this means you have an off-chain counterparty that verifies from one of the others so if you want to bridge from let's say chain a to chain b you will run some kind of off chain client that verifies that the transaction was done on chain a and can be done on chain b so an example of this is like an atomic lock or a hash lock based bridge so these are these have been pretty popular in the past they're really good for like just transferring funds but the trade-off here is that they're not extensible so basically the bottom line is each of these kinds of bridges comes with their own different sets of trade-offs uh that brings us to this thing called the interoperability trilemma as you know we're all in the blockchain space

so we love trilemmas so this is this is the trilemma that comes with interoperability you have on one side you have extensibility which means i i want to be able to compose my bridge with other smart contracts essentially make it like a d5 building block you have generalizability which means i want to be able to paste this bridge and connect to every single chain in the world and then you have trust minimization which obviously you want to be able to not have to trust some like some set of parties that you know doesn't have your best interests at heart so you can see the different kinds of bridges that we've we've outlined before you have the mpc oracle validator bridge on one side you have the atomic lock base bridge which is the locally

verified system on the other side and then you have light client relays which is the natively verified system so all of these different bridges unfortunately have trade-offs um so how do we solve this trilemma well there's a new kind of bridge design that has kind of become popular fairly recently and connects has kind of like written a lot about this so i'd really encourage you guys to look into some of the writing that we've done about this so this is an optimistically verified bridge so this system is slightly different because you have a message that's going from chain a to chain b and then this is not like an instant system so before the message on chain b is determined valid you have a set of actors in the middle

one of n that can prove fraud so they're not in charge of like holding funds or like you know they don't have any control over funds what they can do is they can basically pause the bridge if anything goes wrong and then this brings its own trade-off where it's not instant so now we go from a trilemma to a quadrilema which you know that that's annoying because you know you're just adding a new trade-off here but there is a solution for this as well so this is kind of like the the holy grail type solution so you have an optimistically verified bridge but in the middle you have this little pink thing which is a liquidity provider so the liquidity provider can come in

during the fraud period and basically like front run the fraud period to actually send the funds to the user on behalf of this optimistically verified bridge and so essentially the liquidity provider takes the lock up period but the user does not have to to experience any type of lock up so with fast liquidity and optimistic bridging we can basically solve this quadrilema um okay so this brings us to like hacks you know bridge hacks are kind of like the flavor of the month or the flavor of the past few months everyone is aware that bridges have been getting hacked left and right i think what this shows mainly about our space is that bridges are a huge weak

link in the system they're pretty new technology so they're like a huge honey pot of attacks um you know what i what i think is that like this is just new technology that is being experimented with still and it is a huge uh basically target and it's kind of going through a trial by fire process where blockchains themselves have been through this trial by fire process they're battle tested technology now bridges are kind of going through this trial by fire but with that said i think this optimistic version gives us a very good uh way to sort of like mitigate the effects of hacks and security because of this fraud proof window so like i said you know you're going to have some time between message a and message b to actually do some kind of checks so

these watchers in this fraud proof based system are looking for fraud but they can also look for other things like if you say some stable coin got d-pegged and you want to immediately like stop the bridge you can do that with this kind of like fraud period so the the watchers can check for more than just fraud they can check for suspicious activity and bring us to this thing called a circuit breaker so basically you can just like stop the bridge and stop the process and you can basically mitigate the risk of users losing funds liquidity providers losing funds and kind of this this whole like uh crazy consequences of these bridges being hacked uh now we're gonna get into developing zaps which is uh cross-chain apps uh this you know going on this this

whole x motif uh connects we have developed this new interface and this new paradigm called x-call so this is a low-level primitive to facilitate asset and or data transfer across arbitrary chains it's designed to mimic solidity's built-in call method the way we're approaching the developer experience for cross-chain applications is that we want it to be as easy as possible for developers to pick up and learn the process of cross chain it's like it's you know what we've seen when we've gone to hackathons and we've interviewed developers is like a lot of them are interested in the idea of cross chain but they find it really hard to wrap their head around what it means to actually develop a cross-chain system

so we're trying to make that as easy as possible by uh creating this new primitive that matches basically the built-in version of solidity so developers don't really have to learn anything new they can just kind of like augment what they already know in terms of like how to develop uh decentralized applications um okay if we wanna look at a little bit of code i apologize if this is uh small but this is basically the x call a primitive in action so as you can see what we're trying to show here is that this is a very simple function signature it has a bunch of params in it and there's a single call so all you do is you initialize your connex handle or contract and you call xcall and the args in here are quite

straightforward so i'll just go through some of them the two addresses who is going to receive the funds on the destination side call data this is something that's very important so um what you can do is here is you can pass data through so if you say i want to call a contract on the destination side what you would do is you would encode the data so you can see we're just calling encode with selector then we're hashing the name of the function so this is the function signature hash so this is exactly what gets called in solidity on the destination side so we're calling a function called update value it takes a u n 256 and is calling it with some number we want to update it to

then you have origin destination domain so this is just uh encoding of what the chain you want to go to and from uh agent recovery so this is kind of just some uh fallback parameters so in case the transaction fails on the receiver side then you have a way to like get the funds back uh for slow receive local these are kind of like not very important parameters that are kind of like advanced configuration parameters callback callback fee we'll get into this a little bit later this is also important and transacting asset id and amount so basically what we've done is we've made it really easy to send funds across chain and also send data if you want so transacting asset id and amount are

basically the token that you want to send so if you're saying you want to send like dd token on gorilla chain to mumbai chain which is what the origin destination domain r this is basically the signature you have here so what this is going to do is it's going to send this amount of this asset to the destination domain and as well as call this function so when we get into call data what i talk about data passing you have distinctive flavors of data so it's important to know that there's like two different types of data when you're passing data there's a type of data that's called authenticated data this means the destination target needs to verify the origin source domain and

address so you need to be able to verify on the destination chain that this came from a specific address on the origin chain for example if you're voting in a dow on chain b from chain a you need to know that the person on chain a actually voted in that dow so that's very important to verify that this came from the bridge so in this case that needs to come through this fraud proof window so you can't bypass the fraud proof window in this case however there's another type of data called unauthenticated data this means this is like a meta transaction so the destination target does not need to verify the origin source

domain or address so for example like and these these use cases are actually more than you might think so a swap a swap can be done by anyone it doesn't check message.sender if i want to deposit into ave i can say i want to deposit on behalf of somebody else so that doesn't check message.sender if i even want to like check that an eoa on chain a signed a message i don't need a message.sender i can just check a signature so this is an example these are all examples of things that can actually be done very quickly through a liquidity provider so the whole key to this is that you don't know who is going to fulfill this transaction on the receiver side it's not going to be done through a bridge contract it's going to

be done through an external actor who is a liquidity provider so because the data is not authenticated this could be done fast and you can see this little like pink guy there can instantly do this so if you want to essentially do like a cross chain swap where you swap usdc for like ethereum you can do that by doing this fast pad so it'll send the usdc through the bridge and then they'll swap it immediately through the liquidity provider calling a uniswap contract or something on the destination side then you get into the thing about gas so how are you going to pay for gas like we want essentially we want the system to be sustainable so we don't want to be doing gas subsidies a lot of other

bridges do things like gas subsidies and things like that but this is not sustainable we want all the gas fees everything that everyone who is a relayer in the system or liquidity provider all their gas should basically be reimbursed by the user so that's one of the desired properties is that the user pays for all the gas fees another desired property is that the user does not need gas on the destination chain this is super important because we want this ux to be extremely abstracted basically our end goal at connext is that you don't even need to think about what chain you're using like x apps dapps should be building cross chain systems that basically abstract the entire process of chain so you should say like i want to deposit from any

chain do something on any other chain get the funds back on any other chain and like all that process should be handled by the bridge itself so the main point is that users don't need to have gas on any of these destination chains but at the same time we want to make sure that real layers are properly incentivized to submit these tx's so we don't like i said we don't want any kind of don't want any kind of subsidies or things that are not going to be really sustainable long term so this is kind of a complicated diagram here but we can walk through pretty easily so on the origin side alice is going to pay for the gas fee on the origin chain in the native asset so for example this if the destin if the origin chain is

polygon alice is going to add some extra polygon like in addition to what the transaction fee is for this transaction which is going to basically be locked on the side on the origin site as a claimable relayer fee then we go through the bridge the relayer uh who is the one who who does the fast liquidity stuff on the destination side will uh basically complete this transaction send it to the user on the end the end user on the destination side then once they do that they will actually submit this proof back through the bridge so it goes back and then they are able to claim the real air funds so they prove that they send the transaction on the destination side and

then they're ready to claim the funds on the sender side this brings us to asynchronity so when you're doing cross-chain app development uh you can't assume synchronity anymore so what then what does that mean so blockchains are synchronous that means everything happens in one transaction it's an atomic transaction so either the entire transaction goes through or it doesn't so you don't have to like worry about anything and this gives us basically all the properties of blockchains that we like like you can do uniswap swaps the reason uniswap works is because it's synchronous the reason flash loans work is because it's synchronous so when you're doing cross chain stuff you actually lose that synchrony and you have to kind of think about how you

you're programming stuff very differently but the interesting part is that like we already do asynchronous programming everywhere so you know if you're a developer you're developing javascript you're developing anything on the internet with distributed systems you don't have synchronous environments you have basically you send a call somewhere you do some work with the with the callback essentially so you just send your call out and then it processes something later so this is a very common pattern in functions like java or in languages like javascript for example you have this dot then called so you do some work which is an asynchronous process you have a callback that you attach to this function so now this dot then function

gets called sometime in the future you don't know when but you you have some handler function written that can handle it when that happens okay so now if you want to do the same thing in a cross chain world it looks a little different so you have your origin chain you do some work on the origin chain then on the destination chain you will do some work back on the origin chain once that process actually happens on the destination chain so basically you're gonna like tell tell something to happen on the destination chain and then you're going to get the result of that back on the origin chain and that's basically how a cross-chain callback works so how does this work in connext

like i mentioned before there was this callback parameter let me see if i can go back to this slide sorry i'm going to go back here i just want to make sure so we have these parameters called callback and callback fee so this callback if you set this you can set this to address this if you want this address to actually implement the callback sorry i should have included that in the parameters but there's a very simple way to basically set it so that you're going to get the result of the call that you make on the origin side from the destination side so for example we're calling this function called update value if update value returned a result basically like a true or false or something whether or not it was updated then you would get the result of that on the callback address

if you specify something other than address zero so in theory you would specify address this so let's go back here um so then we have our xcall function which does some stuff and then we have callback so we just all we have to do is specify a function called callback and then we specify only promise router which means we're going to verify that this data is only going to come from the bridge and then we have some handler which call which you know in this contrived example all it does is update the data on one smart contract with the result of the callback value so this is a very simple interface for implementing asynchronous solidity essentially

and what are people building so you know i think this this kind of unlocks a really cool set of use cases for cross-chain apps and we're starting to see now that there are more and more things that are being built with cross chain applications uh for example superfluid is a company that's building on connects they're building cross-chain money streams uh we have keeper which is building cross-chain uniswap t-waps this is really important this is going to be like a d5 building block so essentially you have a uniswap t-wap which hap which has liquidity on one chain but you want this price to be carried to other chains as well but you can't guarantee you have liquidity on these other chains you can only guarantee you have liquidity on the chain where you have liquidity so instead of

you know fragmenting the liquidity and making the whole t-wap more unsafe you can just move the tiwa price from chain to chain fuji jaw is another project we're working with they're doing cross chain lending aggregators so like i said you know we want to be able to make the cross chain process kind of completely abstracted from the user so that means users should be able to get yield from any chain they want without even thinking about what chain they're getting so fuji dao is helping make this happen nft hoshi is another project we'll be collaborating with they do multi-chain nfts so nfts are something that should be able to be on any chain without really worrying about you know which chain

they're minted on so they're making this happen and dow govern is a really important thing so you want to be able to vote from one chain to down on another chain this is just something that should be there and should exist so why not um and then this brings us to like you know what we want to see next so we want to see builders taking this to the next level and really figuring out what the next applications of cross chain are so you know the world is basically the oyster at this point there's a lot of things we haven't even thought about here so cool thanks for listening everyone uh you know these are the links here if you want to get more involved with k'nex please reach out to me if you have cross chain app ideas we'd love to talk about it

and yeah if anybody has any questions happy to stick around answer or can find me later