Lufy / DCxPrague
DCxPrague 2023 · November 2023 · 30:23
Lufy, a developer at Sushi, explains how cross-chain bridges work, from the lock-and-mint, burn-and-mint and liquidity-pool models to cross-chain messaging that carries arbitrary payloads for contract execution. Lufy covers the trade-offs in speed, trust and security, including fragmented bridged tokens and opaque multisig bridges, and why native rollup bridges remain the safest choice despite slow withdrawals. The talk refers to SushiXSwap, whose code is open source.
Speakers
Topics
From DCxPrague 2023, hosted by DCxPrague 2023.
Transcript
all right uh so once again uh hey everyone uh I'm Luffy from Sushi um I'm a developer and um this is my presentation um I've been trying to come up with a good topic to talk about for for a while now and well here we are uh this is something that I think that might might be finally interesting for you guys and I hope that you you find it as interesting as as uh as I do um so I'm sure that many of you are aware of bridges and uh you guys know how they
work but uh there might be a lot uh of stuff you might not have heard about yet um in this space the the thing that everyone knows right is that you can transfer assets across Bri bries but with let's say recent not so recent in in this space but recent Improvement you can do much more than that uh but uh not everyone knows all that much about bridges which I made sure of by bringing a couple of friends here um so I'll just start with the
basics um so as I said uh like the the classic thing uh that everyone knows uh is uh the transfer of assets across across chains that was the initial initial Focus that was the initial point of bridges but uh yeah again lately lately uh it's become much more than that but let's just let's just go through through uh the the classic the classic uh stuff first before before moving on um there are three basic uh models for for Bridges the oldest one is lo and
mint uh it works by locking uh the native asset on the native Source chain and then minting a backed token on uh the destination chain a good example of this is rep Bitcoin or wbtc where a trusted custodian uh receives and uh locks probably in a spreadsheet but locks a Bitcoin on bitcoin and then proceeds to Mint uh wbtc on ethereum and uh they send it to whoever send them the Bitcoin on on on
the Bitcoin blockchain um a very similar but kind of different model is burn and mint um it still works by somehow kind of locking uh the token on on the Chain you're transferring from but instead of actually locking it's it's being burned and then minted on the new chain uh the difference here is that uh the token stop exist stops existing on the source chain um but it's still that same token and it's still backed because if you
burn it um and you me the same amount somewhere else uh and if the token supports it that's very important uh then you you pretty much have the same result uh if you try doing this without explicit support from the token um you would be burning something you can't get back anymore I remember there was uh was called tbtc uh and they tried uh introducing a new let's say bridging mechanism for Bitcoin by straight up burning the Bitcoin on the Bitcoin blockchain and then uh minting
tbtc on ethereum uh but as you might imagine uh something like that this is just not going to work because uh the value of the Bitcoin is kind of lost because you can't uh then uh get it back uh by by bridging back and actually selling it as Bitcoin so that was a very much failed experiment and if I think they don't exist anymore they like failed couple months after launching um so yeah it has to be supported by by the token um and it has to be expected that this is going to be the case that the source token is going to be burned and the new one is going to be
minted um the third model is deposit and withdraw it's probably the most widely used uh one nowadays um and it uh I call I call it deposit and withdraw uh because because uh it uses liquidity pools it uses a liquidity pool on the source chain and it uh uses a liquidity pool on the destination chain um and it allows for usually much much faster bridging than uh Native Bridges um because the assets don't actually move from one chain to another
but uh they are deposited on the source chain uh and then a different but essentially the same token uh is sent to you on the destination chain uh this is very useful for things like stable coins uh because you might have like native uh stable coins issued on both chains uh by Circle for example or tea uh and uh while it is the same Tok uh the native uh the native Bridge usually or any bridge for for that matter might not be able to to replicate this uh so if usdc is native on both the
source chain and the destination chain um the only way to actually transfer tokens across uh the chains is uh by the use of liquidity pools um all right so that's that um of course nowadays uh most bridges are not as simple as the rap Bitcoin one because that's like pretty much the the simplest the simplest solution for for the problem um nowadays you've got bridges that are faster uh that are kind of more secure uh and trustless like red Bitcoin is pretty much none of
this because uh again it's it's managed by a couple a couple of custodians who theoretically can be compromised you have to trust them to actually have the Bitcoin and to not do anything with it to keep it locked um and the process itself of course involves humans so it's just going to be slow um of course all of these improvements uh introduce a lot of complexity into into bridgings uh so um complexity also of course brings security implications with it so it's kind of a piure poison thing but uh there was another
Improvement uh another layer of complexity let's say uh which was the introduction of uh messaging cross chain messaging it's kind of a generalization of the process where uh before it was uh the information that was passed from one chain to another was uh sent x amount of tokens here and here pretty much uh with messaging you can send arbitrary information uh across chains uh which means that uh in uh said message you can include for example a payload for a contract for
for a contract execution which means that you can do much more with it than uh just straight up simple simple token transfers so uh a couple couple of examples um cross tokens um with uh something like deposit uh not deposit uh lock and uh lock and mint uh you'll lock the tokens on the source chain right and then you'll mint that brid specific token on uh the destination chain now this is of course an issue because if you have fre
Bridges uh you'll have three resulting token versions uh which is pretty bad for um liquidity fragmentation um it's bad for I guess Landing protocols because they then have to choose which uh which one they actually want to use which uh kind of become becomes the the Canon canonical uh bridged version of the token this is uh I've noticed an issue with uh any swap because they just have random random uh tokens everywhere and uh it kind of becomes becomes a mess uh what's nice about cross chain tokens is that uh you can you they operate under
the under the burn and mint model uh where the tokens are destroyed in one place and created in another um which uh avoids liquidity pools and the fees associated with them because you don't have to pay the liquidity provid this um and they also don't look you into the uh into a specific Bridge because the tokens owner can specify a list of bridges which can uh mint and burn the token so you can choose a wide range of bridges uh and you unlocked into specific one which uh I consider quite a problem because in this space uh
everything move so quickly like Bridges get hacked uh protocols shut down so if you use something like layer Zero's Omni chain token standard uh and layer Z zero shuts down your token just gets stuck wherever it is and there's nothing you can do with it anymore with the uh with this standard withc 7281 uh you can just pick a new bridge and and you can continue you can continue all right um and that's cross train Landing um it's a pretty complex uh solution
but uh it's still quite interesting I think um you can very often uh see uh vidly vidly different rates across chains like uh somewh you could borrow uh usdc for for 5% and then on another chain it's going to be 20 um so being able to utilize uh the B array is of course beneficial for you and uh for everyone uh else as well um uh the other thing is uh different change uh chains usually offer uh different protocols and even if you've
got one protocol across a couple chains uh the parameters for collateral uh also vary like uh for example those are not these are not like uh accurate numbers probably but you could have a on polygon uh where it would offer 80% uh 80% uh loan to value yeah uh something like that and then you could could have the same thing on on ethereum uh where this percentage could be uh something completely different so you really would prefer to have the the higher loan to value and you can do this
very easily uh with cross chain Ling you can uh how it works is you could uh have a transaction uh that Bridges your collateral uh to the chain with better parameters um there you have a contract which deposits uh your collateral uh it borrows whatever you want to borrow and what you want to borrow is bridged back uh to whatever chain Ur on so it's like this nice uh nice easy experience for for you right uh and then uh governance uh it's probably not like as fun or as interesting as as the others but uh
cross chain governance um with the rise of uh DS uh and Community [Music] involvement um this is like the cross chain the cross chain life is uh quite annoying for for those people who want to actually participate in uh in the D uh uh voting processes because if you had uh if you had your tokens for example sushi on polygon you wouldn't be able to actually vote on on Snapshot because that's kind of loged into into ethereum a has already kind of solved this
exactly where with with uh crossin messaging um and they now allow you to uh vote both from ethereum and uh and polygon which means that you can you can have your tokens on a on a cheap chain you can use it uh as collateral whatever you want pretty much if it supports it properly and uh you can still participate in uh in uh the governance process which I think is is uh quite important for for for uh the health of of the ecosystem all right and then uh there's cross change of
swaps um they uh those work uh with uh with liquidity pools um the problem with uh like straight up bridging through the use of liquidity pools is that you have to have liquidity on both sides or well at least the destination side which if you're bridging a stable coin or a major token like Eve uh it's not really an issue because there's going to be a lot of people who are who are bridging this specific token which means there's going to be quite a lot of uh quite a lot of liquidity however uh if you're trying to
trying to brid something less popular let's say I don't know the arbitrum token nobody really does that straight up so liquidity providers just won't care uh to provide liquidity for it um so the way to fix that is to uh before you actually do the bridge itself you could swap to a token that is actually supported uh by by a liquidity pool usually against stable coins um you then Bridge those stable coins and uh on the other side you swap back to whatever token you
might want of course this uh brings with with it uh trade fees but uh it's pretty much the the only fast way to move tokens that are not really popular or at least less popular across across chains um yeah so that's kind of what I'm going to be talking about uh for the rest because Sushi has a cross chain swap product uh it's called X swap um it's pretty simple I would think you just select your your Source chain your sour token and then you select the destination chain and the destination
token as you can see uh you can choose pretty much any token you might want uh and any token that uh has liquidity uh on on both chains so you could swap from uh I don't know maker on ethereum uh into let's say AR on arbitrium um which is a pretty seamless experience I would think uh compared to having to do the swap yourself then bridging and then uh doing another swap on the other side uh what's also nice is that uh X
swap offers aggregation um we've decided to implement that because Sushi doesn't have liquidity like across all tokens and being able to to capture trades that might uh at least partially go to through Sushi and then possibly through for example uni or curve uh is more beneficial to us than uh leaving the whole trade to to UNI so it's kind of a optimization for for users uh and an optimization for us because uh again if if uh we we didn't have the full liquidity that the user uh
requires they're just not going to swap with us at all so they so we'll just uh pull some liquidity from other sources and ideally keep a part of of uh of the trade on on the sushi side um and what what's cool again about X swap is that this aggregation happens both on the source chain um and on the destination chain um I think it currently like supports Bridge aggregation as well um basically it'll just it'll try to pick the best Bridge um that it can um
including like uh including the swap as well so if that was like a good deal for for an eve Bridge uh it would it would uh see if it makes sense to swap into Eve instead of like a stable coin uh and then it would use use usdc as as the the bridging token but I think we actually don't currently uh use Bridge aggregation because it doesn't really make sense because ler zero offers the best rates at the moment if I understood it correctly um and how it works is we've got a um let say data cache um it's
called extractor uh it find and uh keeps an upto-date record of all the pools that we might be wanting to swap through um it listens for events and every time a swap uh happens somewhere it updates updates the data uh locally if we tried to fetch all this data on demand when someone tries uh to swap it would just take too long uh to fetch everything that might possibly be relevant so we just uh keep uh keep a keep a record at all times um this data is then fed into uh an engine uh we call titins um titins
actually handles the the routing itself it uh finds the best path uh for the tokens uh well finds the best path uh through the liquidity pools um it's a a bunch of math that I totally understand uh but yeah it's cool it's cool uh that's for sure um anyway T spits out a a root that that's fed into root processor which is what we call our uh our rout RoR um I would say it's uh named quite creatively because it processes Roots uh so I think
it's a good name for for a root I guess anyway um so what happens is you get a root it's F into root processor uh you get uh it swaps the token to whatever you uh you are bridging um then it goes through the bridge and then when uh you get all the confirmations you need uh from the bridge the tokens are received by uh by a contract that calls your processor on the destination chain and uh sends the the tokens you requested to your wallet
yeah I had a ending ending uh slide there anyway uh that's it for me do you guys have any questions noad Bridge there's been so many hacks that it's kind of hard to keep track of them
yeah I think that's that's going to be that that model yeah yeah yeah that's usually what like uh those bridges use um like Wormhole which got hacked also used exactly this this model I think grown in uh from what are they called the roning bridge it's it's a game I I don't really I can't remember now well it depends because uh you can have like different um implementations let's say if you have like the arbitrium bridge uh
which runs pretty much straight on straight up on ethereum even though it's a uh lock and mint Bridge it's very secure because it's uh onchain straight up on chain straight up on etherium so it's secured by ethereum uh but if you have the same model for something like I don't know uh so if you're into salana um which is Wormhole right and it's again as well the the lock and mint uh model uh since it's not uh not secured by ethereum I think Wormhole is a multi
Bridge uh the security implications are totally different and much worse as we've seen so it it really depends what you are actually doing uh so I would say if it's a native Bridge uh ideally from uh ethereum to a rollup then the safest one is going to be the native one uh whatever is offered by the rollup um and otherwise I would probably go with uh the withdrawing deposit uh deposit and withdrawal model anything else
well yeah that's that's going to be the issue with decentralization it's just inherently slower than a centralized approach so like while they could have implemented something like a flag that uh a centralized entity controls that would just say something's wrong check out Twitter it's just uh it's a tradeoff you know like either either it's like fully decentralized or uh uh it's not uh and it offers these these uh Comfort uh but yeah the the multichain situation was really not handled properly I would
say and if it was due to La of forite that something like this might happen or anything else that's hard to say but yeah bridges are honestly kind of scary in this regard you just uh it's usually just a black box that you can't see into um if it's a multi you don't know who these people are uh you don't know if uh even if you know who the people are if they don't actually like share the keys or something it's you just don't know so like if if I had to recommend something it it it's just native bridges yeah like like the one from ethereum to arbitrum but of course
that's annoying because when you try to withdraw from arbitrum back to ethereum it's going to take a week which is terrible experience well uh thanks for listening uh I wanted to mention all of the X swap uh stuff is open source so if you want to check it out uh you can have a look uh the agregation everything yeah I'm actually not sure what NPC
is actually haven't heard about that I'll have a look I'm sorry can't answer the question though right yeah I I haven't heard about that but I'll have a look yeah thanks all right uh yeah that's it thank you