Arjun Bhuptani - Building xChain Applications with Connext

ETH Latam Buenos Aires 2022 · 18 Aug 2022 · 23:14

Arjun Bhuptani, a founder of Connext, explains how bridges work and how to build cross-chain applications on them. He compares natively verified, externally verified, locally verified and optimistic bridges and their trade-offs in trust, generalizability and extensibility, looks at how bridge hacks happen, and introduces xcall, a primitive for asynchronous cross-chain calls. Examples include cross-chain governance, lending, TWAP oracles and money streaming.

Speakers

Topics

From ETH Latam Buenos Aires 2022, hosted by ETH Latam.

Transcript

[Music] i'm arjun i'm one of the founders of connext i wish i knew spanish well enough to give this talk in spanish next time um this talk is called building cross-chain applications uh it's about bridges uh which i know are kind of a scary topic right now but i'm hoping that over the course of this talk you'll get to learn a little bit more about the different kinds of bridge construction that are out there feel a little bit safer about them and also explore some of the different ways in which you can use bridges to build really really new and interesting kinds of applications so without further ado

background so i'm going to start by talking a little bit about bridges and about what you know what exactly they are and what makes them special and how they work so what is a bridge i don't know where to point this there we go is there a way to uh oh there we go um what is a bridge um a bridge is any mechanism where a single chain can communicate with another chain basically a way to think about it is you want to allow a chain to be able to read and understand the state of another chain

the most intuitive way to do this is natively verified bridges so basically you run a light client of one chain in another chain this is the most trustless mechanism to verify the state of another chain but it also requires doing a lot of additional work you need to verify consensus so that means for every new chain you add and you support you need to build a custom implementation of a light client on many chains this isn't even possible so for instance we still don't have ethereum like clients and the reason for that is that building like clients of ethereum is actually incredibly difficult so as a result of that people have moved to other kinds of bridge constructions lately one of the key ones that we've seen is externally verified bridges and this includes this is basically any mechanism

for relaying data across chains that relies on some external actor to actually supply the data to the destination chain so this could be something simple like coinbase right coinbase is an externally verified bridge because what they're doing is they're taking in transfers on one chain and then sending them on another chain and they are custodially responsible for doing that but it can also be more sophisticated constructions it could be a multi-sig as in the case of like things like poly network uh multi-chain et cetera or it could even be a pos chain of its own which as is the case with axillar now the difficulty with externally verified bridges is that you have this external factors so no matter what happens you're trusting that multi-sig or that chain or that entity to relay

data correctly and when they don't do that that leads to hacks or economic attacks that can cause widespread contagion as we've seen for a lot of the a lot of the bridges out there the last kind of bridge construction and i'll just touch on this one briefly is locally verified bridges and this includes things like atomic swaps in a locally verified bridge you have a counterparty that you're interacting with and you're swapping funds with in order to do a transaction now the difficulty with with locally verified bridges is that they're kind of a special case um you can atomic swap with somebody trustlessly but you can't really use that mechanism to read data on another chain and so we don't generally you know this is this kind of falls under the general construction of of what we consider bridges as a way to

get data or funds across chains but you're not really getting the funds or data across chains what you're doing is just swapping with somebody who's on the other side um i realized i jumped really really deeply into that but the reason for that is i wanted to show that there are there is a really interesting trade-off space around bridges and there's there tends to always be trade-offs associated with any kind of decentralized infrastructure and for bridges there's a trade-off around the three properties of generalizability which means can this bridge send arbitrary data between chains trust minimization so are you relying on an external multi-sig or external set of actors to make this transaction happen or extensibility can you take this bridge and copy pasta to every single chain

now about a year ago we created this mental model to explain the bridge trade-off space and about two months later it was completely ruined because someone created a new kind of bridge which is an optimistic bridge um optimistic bridges are a relatively newer construction where you use fraud proofs to relay data across genes they work similarly to optimistic roll-ups you take some data and you push push it like from an origin 10 to a destination chain and then similar to an optimistic roll-up you have a certain period of time within which that data is finalized so after within 30 minutes anyone can dispute the data and uh and prove that fraud occurred the really cool thing about this is that this is a relatively simple construction similar to an optimistic roll-up it can

be deployed anywhere it exists directly inside of the vm and and it has generally very good trust assumptions but like i mentioned earlier there are always trade-offs and the trade-off of optimistic bridges is latency so any any transaction that goes across chains takes 30 minutes to complete and so unfortunately we always end up in this kind of shitty situation where no matter what happens you're giving up something and if you ever get back to the bridge and they say they are the perfect solution chances are what they're doing is sacrificing trust is there a way out of this um well for ethereum scalability trilemma uh what we ended up realizing was that uh the way that you can beat trade-off spaces in decentralized systems is to

have modularity basically split out the different functions of of a bridge so in that way you can you can achieve the trust minimization properties that you're looking for while giving up the least amount of desirable properties so this is what connects does we are a modular stack for bridging we work with previously with nomad which is an optimistic bridging layer and and generally this is a model that can work with any kind of optimistic bridge where we have a network of off-chain actors called routers that fast execute transactions on top of systems that have latency a good way to think about this is to think about things like hop and across they have they have a similar mental model where you're sending a transaction

across a rollup bridge that transaction takes seven days to execute on ethereum but hop and across short-circuit this by providing fast liquidity for the exit before that seven day window is up and the reason that they're able to do this is because um off chain any off chain actor can know that that fraud has occurred right away right the the idea behind an optimistic delay window so the seven day window for an optimistic roll-up or the 30-minute window for for for an optimistic bridge is that you need to give time for some off-chain actor to prove fraud to the chain um but of course if you're an option actor yourself you can know right away that that's that's happened and provide liquidity quickly for for an exit what does this give us

um for connext this means two minutes of latency for normal calls that you would do as a user so that's unauthenticated calls which basically means a call to a public function so if you want to for instance call unit swap on on polygon from your wallet on arbitrom that can happen instantly on the other hand uh 30 minutes the full nomad or or other optimistic bridge latency window for authenticated calls so that means any any call that actually checks the origin of a transaction so a good example of that is updating the owner of a contract from a dow contract so you have your dow running on optimism and you need to update the owners of your of your contracts running on other

chains like polygon or gnosis chain so what about hacks one of the biggest things that i think people have seen over the course of the last year or so is that bridges are extremely extremely dangerous technology um and it's not because they are inherently flawed in any way in fact there's there's ultimately there is no way for us to scale this ecosystem without some kind of bridges and roll-ups kind of fall into this as well roll-ups are really a way to have bi-directional communication to something that kind of looks like a side chain but how do we actually build safe bridges and i think this is really where optimistic bridges shine the kinds of attacks that exist on bridges and the kinds of hacks that

we've seen have always falled into certain categories either either compromises of the root of trust so that's like an economic attack where you you compromise the keys of a of a bridge the ronin network uh ronin network bridge hack was is a good example of this um or they're implementation bugs um so the nomad hack that just recently happened is another good example of this and in in both of these cases um using optimistic bridges using the optimistic watchers that are actually like checking for fraud on each chain can help you catch some of these types of issues and shut bridges down before they actually completely depend the underlying assets and lead to widespread risk in these ecosystems um i could talk about red security for like two hours so i'm going to stop

there but if you have more questions i'll be happy to chat about it after this clock so that was a quick rough and ready background on bridges why are bridges important what do they actually let us do bridges let us build cross chain applications cross chain applications are applications that interact with state that lives on multiple chains at the same time and there's a big benefit to doing this you don't want to give users this like fragmented experience where they don't where they're interacting with like ave running on polygon and then they have to go switch networks and switch chains to go interact with ave running on optimism that's a really really shitty ux as a user what you actually want is you just want to get the best rate anywhere or you want to be able to select a target chain but be able to deposit into

it from any other chain so how do you do that what do what do bridges enable and how do how do they actually help us accomplish this so to start with i'd like to introduce a primitive that we've created which is called x-call call is a very very simple low-level solidity primitive that allows you to make asynchronous calls across chains a good way to think about it is to think of the solidity call method so for those of you that have written solidity and build contracts call is a a lower level function that allows you to pass data to another contract that exists on the same chain and execute whatever is happening on the other side it's a bit of an unsafe function because you don't really have full transparency into what's going on so most of the time people will not use

this low level function they'll use libraries instead but you can build on top of that function to do a lot like this that function ends up being the basis of composability on blockchains xcall does the same thing it allows you to call contracts on another chain asynchronously the same way that you call contracts on the same chain what's a good way to think about this so those of you that are javascript developers a good mental model for this is is how you make asynchronous calls in javascript when you execute something in javascript that is accessing a resource that is far away what you're effectively doing is calling asynchronously to that resource and then the process halts and waits for that

call to execute and come back and execute something else called a callback basically a function that you specify that does something after you get that data similarly xcall lets you do a remote call to another chain and halts the process or i guess it doesn't exactly halt but basically the function terminates on one chain in a single block calls a contract that lives on another chain asynchronously and just like javascript lets you come back and execute a callback at some point in the future now of course this is blockchains not javascript and so this process takes time and costs money right it's not it's not like traditional web development where you can make

asynchronous calls to a lot of different places all at once really cheaply and expect them to get back to you within like a couple of seconds on the other hand with blockchains this will typically take again at least a couple of minutes of latency and will cost gas but the core principles are very very similar and it even extends to the way that we think about things like gas so for instance when you're calling xcall you you pay gas on in on the origin chain in the origin chain native asset and similarly to any normal call that you would do on a on chain if there isn't enough gas to complete the execution and the execution halts you can simply bump gas to make sure that it goes through faster this also happens on the sending chain what does this look like in practice

what we're trying to do is find a way to emulate the like existing solidity development patterns as much as possible and just introduce only this one simple asynchrony primitive and so the way that this looks currently is to is to basically pass a bunch of data into xcall in the same way that you would pass data into call and then specify an a a callback that gets executed later but what we'd like to do is work towards a model where we build libraries you know similar to the for instance like the open zeppelin wrapper wrapper libraries that allow you to call common contracts like uniswop where instead of doing you know iunisportv2router.swap you would do xi uniswap v2 router instantiate by passing in a chain id of

the target chain and then dot swap and then dot callback now that we've gone over the kind of like the basics of this idea let's talk a little bit about like zap design how do we think about building applications in in this asynchronous world and what kinds of issues that do we run into building asynchronous applications is not like building synchronous ones it's actually a lot more similar to building in the traditional distributed systems world because you have to think about a lot of these really pesky issues that you wouldn't have thought about otherwise one of those issues is concurrency so imagine if we're building a cross-chain mm and that crosstown amm has a pool on a destination chain so you know a pool of usdc on optimism

and you want to allow people to transact from that pool on any other number of chains concurrently one of the risks that you run into here is that if you have calls x calls coming from multiple origin domains they may be trying to interact with the same liquid at the same time so that can lead to to either collisions where you uh you have deadlocks where multiple transactions are trying to send funds from the same like the basically the same funds at the same time effectively an attempted double spend or shitty ux where a user can basically just execute a transaction across chains but then never actually get their funds and this leads us to all sorts of weird things that we have to think about where we now have to think about concurrency

control which is not something that we've had to do typically in blockchains because or at least when building on top of blockchains because everything executes within a single block but now you have to think about okay well what happens to the system if you have multiple interactions happening to it at the same time so some of the strategies that people will end up using will be things like segmentation you know fragmenting the liquidity in a single pool optimistic locking which is basically serially ordering transactions pessimistic locking which is a high overhead communication mechanism where you like lock a part of the pool these are all like traditional distributed systems mechanisms for for handling concurrency now unfortunately in the in the amm case none of these options are really that

great and this is one of the challenges is like how will we actually be able to build some of the same user experiences and as it turns out we may not be able to do so without without sacrificing at least some capital efficiency or some additional gas overhead another really really common pitfall that i see people running into all the time is synchrony assumptions so a synchrony assumption is the idea that you cannot actually know the state of two chains on a single chain at any given time to think about this let's go back to our amm example again where we have a pool of usdc sitting on on optimism and a pool of usdc sitting on arbitrary and you want to send a transaction uh similar to any amm send a

transaction that inserts funds into pool of x and then outputs funds from pool of y how do you calculate the fees how do you calculate the swap rate for that transaction well if you're doing this on chain you know when you initiate the transaction to the the origin chain pool that that origin chain pool has a certain state so say it has you know 100 million usdc in it however by the time that that transaction actually goes across the bridge and this is regardless of whether that takes a couple of minutes 30 minutes 10 seconds even one second by the time that that transaction goes across the bridge the the pool state that you have on the destination chain is now different from the actual pool

state on the origin chain and that's because there is always a time window between these two things so uh if you think about the fundamental mathematics of why we you know of of like amms and and why we think about amms as this constant function um when you have a system where you have a like a synchrony assumption you now have a little bit of a weird situation where you don't actually have a constant product in your aim at all and this is obviously quite dangerous it means that miners can run your amm transactions it means it is possible for people to even rug all of the funds and so what that means is that this ultimately this

construction that we have for amms is actually vulnerable to huge problems when you when you try to build the the same kind of core amm like one pool on every chain construction in a multi-chain world tldr building crosschain applications is tough there's a lot of really really interesting things you can do but it's also kind of messy and i think a lot of the the reasons why it's tough is because not only are you dealing with these applications now as a distributed system um so as a system that has state on multiple chains that you have to manage and concurrency on those chains but you also have some of these trade-offs messaging overhead is costly so like when you are if you are a

developer building uh you know a traditional web application that is storing a bunch of data across a bunch of databases syncing those databases doesn't cost a lot of money whereas on ethereum syncing your state across multiple chains costs gas every single time authenticated calls also have latency so that means that it can take up to 30 minutes to actually do any any intensive call that requires like knowing where that call came from and most importantly state updating matters so mev is a thing that exists and it's only extremely magnified in a cross-chain world and as we've seen from as we've seen from this curve getting it wrong means there are now like massive

vulnerabilities that exist inside of your protocol but there are also a lot of really interesting things you can build and i think that this is really where we've seen a lot of books like starting to explore and play with these ideas and of course we're like people are running into some of the pitfalls of building crosstrain applications but there is also a bunch of completely innovative use cases that are coming out of this model that a lot of people haven't really thought of before so some good examples are superfluid um superfluid is building cross chain uh money streaming so at the simplest level that is setting up streams on superfluid on one chain that can then be like withdrawn another chain but even more complex you can do really interesting things like

you know cross-chain dow payouts so liquidity mining campaigns and things like that that happen across chains with a dow existing on one chain and the campaigns happening across multiple different ecosystems at once and of course a lot of other really really interesting use cases for money streaming that still have yet to be discovered um another good project uh that we've been working closely with is is keeper and and we've been working with the d5 wonderland team on helping take keeper multi-chain and a big piece of this is bringing uni v3 t-waps to every chain right so the big benefit of t-wap oracles is to not necessarily need an external oracle so you minimize the the external trust on something like chain link by using on-chain pricing data for whatever it is

that you're building but of course that doesn't mean anything if a way that you bring your t-waps across chains is using a multi-sig or an oracle to begin with so this is a way to access that data on any other chain without actually giving up the core properties the core benefits of the t-box to begin with fuji dao is building a lending aggregator so they're building on top of ave and other lending protocols and the core use case that they want to enable is lend on any chain bar on any other chain similarly nft hoshi bridging nfts across chains and gnosis zodiac cross chain dow governance and tooling there's one more really interesting use case that i'd like to touch on here which is like

one of the key things that this crosschain world creates is is building bridges building kind of connections to ecosystems and projects that are not necessarily like evm compatible or not necessarily even blockchains so for instance um you can build a bridge to rweave or filecoin and what that means is you can basically access storage directly from within a smart contract on ethereum the storage that exists is actually owned by that contract it's not being uh owned by somebody else with it's not like you know an ipfs hash where you have uh you post some data at ipfs and then store the hash in an nft contract instead that contract is natively able to store and access data

directly from within itself similarly you can do you can you know run compute from within a contract using nexus you could do video transcoding using live peer or even access video data from within a smart contract and and i think the the really important thing that this enables is that it allows ethereum to kind of act as a motherboard right you can plug into other kinds of of resources on other chains or other ecosystems that allow you to build more expressive applications applications that go beyond just like relatively simple defy apps or nfts or some of the some of the basic things that we've seen so far and go towards what basically looks more like generalized decentralized compute thank you for listening to my talk my

name is arjun if you'd like to learn more about conext these are a bunch of resources and if you'd like to contact me or learn more about me that's my handle it's the same handle everywhere i'm very doxxed cool thank you so much appreciate it [Music] [Applause] [Music] you