Security Principles for Designing Cross-Chain Messaging Protocols
DeFi Security Summit 2023 · 16 Jul 2023 · 13:14
Irene Wu, head of strategy at LayerZero Labs, presents the security principles behind LayerZero's cross-chain messaging protocol: immutability, permissionlessness and censorship resistance. She argues that upgradable bridge contracts reset accumulated security and put every integrated application at risk, and says most bridge hacks in the previous two years came from contract upgrades. LayerZero instead deploys immutable endpoints and lets applications opt in to new validation libraries, and adds Pre-Crime, which forks each message and checks it against application-defined invariants before it executes.
Speakers
Topics
From DeFi Security Summit 2023, hosted by DeFi Security Summit.
Transcript
um I'm gonna run through this really quick uh we'll be talking through security principles for Designing cross-trained messaging protocol so we often see multi-chain cross-train Omni chain what are the differences between those three oftentimes when we're saying multi-chain we're thinking about isolated instances of your protocol deployed to multiple chains for cross train it's actual uh value transfer between different chains so that could be through a wrapped asset Bridge it could be through arbitrary message passing many different implementations and then Omni chain is the sort of concept of mesh Network and actually enabling seamless movements of assets and information essentially arbitrary contract contract invocation
between chains and why is this important I think everyone in this room understands the security risks and we'll run through that in a second but also the user experience and developer experience involved for me when I first got into the space I started as a developer at layer zero and thought about different chains like different programming languages you would never think to yourself what can I build with C plus plus you would think I have this problem that I want to solve and here's the product I'm going to build what are the tools at my disposal to build that and so with the piping underneath the hood which is a cross-chain messaging protocol you can now Leverage The Best of ZK sync or Linea or polygon ZK VM and then also file a coin VM for storage pull in liquidity from ethereum and
maybe launch your own app chain for sovereignty and to avoid gas congestion for maybe the game that you're building in that subnet or supernet what is layer zero I'm head of strategy at layer zero Labs we are the creator of layer zero the protocol and omni-chain interoperability protocol and Stargate Finance which is the most widely used Native asset Bridge it's arbitrary contract invocation and our protocol architecture and design is is very particular to these three principles I'll walk through and also the concept of evolving with research so these three principles are immutability permissionlessness and censorship resistance
this right here is the the architecture of layer zero which may be useful later but I think it also might be hard for you guys to see it so I'll dive right into the first principle which is immutability when I say mutable what I mean is the contracts are they upgradable or non-upgradable and the issues with mutability or upgradable smart contracts are that when you push code to let's say the core contracts for your Bridge you want are actually resetting the security that has been locked and secured all over time but also pushing existential risk for all of the projects that have built on top of your your Bridge integrated it and all the the users who might hold assets from that as well in the same way that uh and
I was speaking on a Bridges panel earlier today and use this metaphor if your treasure or Ledger were to push an upgrade and you saw that you would likely reject it or give you a lot of pause why would you accept the same for your D5 protocol and for many cross-train messaging protocols the they do use upgradable Smart contracts and so even if the developer is introducing a benign patch or is trying to introduce a new feature with good intentions the chances that there's a smart contract bugging that which all the applications built on top did not opt into is incredibly high in fact the majority of bridge hacks over the last two years were because of smart contract upgrades not because of architectural flaws so you know even great and well-meaning
developers make mistakes we all know this this is a graph that demonstrates what I meant by resetting security when you upgrade the protocol it resets the perceived security over time which is measured by value secured in time and where you see that blue bar is the upgrade to the smart contract how can you design a protocol that enables applications to opt in to the smart contracts that they've vetted and have seen secure value over time but also have optionality because let's say the validation techniques we use today will not and likely should not be the ones that we use five to ten years from now how can you offer that without doing a complete overhaul of your protocol and that's exactly what the architecture I
may have time to walk you through achieves and here it is a solution Library upgrades so how we design layers here the protocol was by deploying uh endpoints on each of the chains which we support and these endpoints are entirely comprised of immutable smart contracts however we can always launch new endpoints and applications can point their contracts towards those that means we could launch a smart contract Library which are the endpoints that leverages ZK technology or some new validation technique in the future in between all of these endpoints are the off-chain entities that are involved in validating separate components of the state data and as you can see here it doesn't reset the security clock there is no Force to upgrade it's always opt-in for
applications and it allows for time and money secured to reach a threshold that is acceptable before applications opt in the second principle is permissionlessness we talk about this a lot in many different contexts in the context of cross-chain messaging what I'm referring to is the ability for a developer to leverage your protocol in whichever way they'd like and in the case of layer zero we are open and permissionless and application devs can use it to create something that we might not align with from an ethos perspective but there's nothing we can do as layer 0 labs to interfere it also means that participation in the validation and and network is also open permissionless so if you'd like to run one of those components yourself the Oracle the
relayer multiple oracles multiple relayers you can and it doesn't require any coordination with layer 0 labs this also enables and encourages client diversity since maybe you have a set of 20 validators and you're requiring 13 of them to agree but all of those validators use the same code ultimately that client diversity is is one by leveraging different Oracles and relayers provided and run by say like chain link blocked image gelato layer zero Labs your your own team you have that client diversity the optionality but also the backstop if your team were to run one of those yourself without unilateral control or centralization and this also leans into the uh dichotomy between protocol and service so when I
say service I mean a product which requires the Creator company to maintain its integrity and liveness and the actual uh like value it's meant to provide a protocol is something that is Evergreen It's A Primitive it's immutable you can use it as you like and when you're choosing these really important parts of your infrastructure stack you don't want to be one adding more code exposure but two relying on a founding team that might get arrested which happened recently with multi-chain or a team that may run out of Runway and actually just shut operations down or a team that needs to constantly be patching code so without immutability permissionlessness is never guaranteed
and the final principle is censorship resistance we talk about this a lot in different contexts but in the case of bridging and cross-stream messaging it's actually even more important in my opinion if you have the ability to reorder messages as they're submitted that means that a high frequency trading firm could extract more mov for example by rearing messages and front running it means that if a nation-state were to leverage cross-stream messaging or just blockchain technology for voting it would be possible to possibly censor a tranche of those votes layer 0 is designed to be non-sword or enforced and so every message must pass across the protocol if validated properly in the order in which they were submitted and
so I like I said cannot reorder delivery of messages or censor individual messages and applications can also always choose different off-chain infrastructure by swapping in and out and again without immutability censorship resistance is not guaranteed I have about two minutes left these two graphs just show the growth of contracts that are building cross chain omnichain multi-chain these specifically are contracts that have integrated layer zero in some capacity so on the left hand side's test net right hand is mainnet this is back from April and it has continued to to steep up and to the right so it's actually just really exciting to see what's going
to be coming out over the next few months we're seeing uh and I personally have been involved in in traveling the world to be in person with teams building omnichane stable coins tokenized t-bills for example that will be native on multiple chains and seamless transfer between them leveraging layer zero games that under the hood are leveraging ZK sync and a polygon supernet and ethereum but abstracted away so the end user is just playing a game there is no tribalistic Affinity of it's a Solana game or a polygon game and they use one gas token and do one click in order to move their in-game assets between chains we're seeing nft projects moving between
chains as well Trad five leveraging cross-chain messaging to communicate from permission chain to public chain and then of course across all of D5 there are so many interesting things happening with lsds and also lending and borrowing from one chain to another land in one chain borrow across five different ones collapse it into one click and use one gas token so it makes me incredibly excited for the the next year the next five years since some of these projects take a really long time to develop and security really is at the Forefront of this it's unfortunate that nearly every single month there's some sort of hack but it comes down to the violation of these three principles and
something that I encourage all the developers in the room to think about so I have 20 seconds left I want to thank you all for helping me with my Wi-Fi and being super patient really nice meeting you all and Happy to answer a question Irene there's one question we have time for a question God I hope it's not a dumb question um hi I was wondering if you could explain a little bit more about pre-crime because that sounded technically really interesting um and yeah I know there's quite a few experiments going up um around in the ecosystem with local folks simulations Etc and so this is really cool because it sounds like it's something that's actually used in prod
stage uh yeah so pre-crime is a proprietary security module that we created actually prior to the launch of Stargate which is the native asset bridge that came out about a month after layers of the protocol went live last March and what pre-crime does is it Forks every message that goes across the protocol and tests it locally against a set of invariants that are defined by the application and so that could be a formula that helps prevent the double spend issue it could be a set of whitelisted addresses for an nft migration it can be quite literally anything the application developer wants it to be and only then will the message be pushed back to mainnet and run across
the protocol and the idea of it is stop a hack before it happens and the efficacy of monitoring once that hack is actually happening is as uh ineffective as a Twitter thread saying a million 100 million dollars has been withdrawn from this bridge the auditor sitting to my right on the panel earlier today was was talking about that and uh pre-crime is is meant to solve that issue no but actually interestingly right now pre-crime is only opt-in uh and it was used to protect Stargate like I said two weeks after Stargate launched it reached 4.4 billion in organic tvl which was
astounding it was the fastest growing D5 protocol of all time in that respect since then we have made the protocol so much more efficient and we haven't actually even reached Peak efficiency which would involve I think around 200 million of protocol owned liquidity instead of needing external LPS but I remember you know all of our devs were at the time in the Bahamas and just saw every single black hat attacker try and break Stargate and we built pre-crime just for it what we're doing right now and we'll launch in Q4 uh hopefully sooner rather than later is we're scaling pre-crime as we say like to Infinity so every project all of those 6 000 contracts on mainnet can leverage pre-crime right now it's not at scale to be both fast enough and to uh well yeah
to be fast enough and support all of these contracts [Applause]