Pre-Crime and Library Upgrades: The Future of Omnichain Security
DeFi Security Summit 2022 · 27 Aug 2022 · 13:00
Ryan Zarick argues that cross-chain messaging faces two distinct risks: protocol upgrades reset deployed code’s security history, while application bugs can generate messages the messaging layer treats as valid. His proposed validation-library model makes upgrades optional, letting applications wait while new code builds a track record. He describes “pre-crime” as simulating delivery on forked chains, checking cross-chain invariants and withholding messages that fail. Zarick said the system was then live protecting Stargate.
Speakers
Topics
From DeFi Security Summit 2022, hosted by DeFi Security Summit.
Transcript
uh hi so uh my name is Ryan Zurich uh he said uh co-founder and CTO of layer zero Labs layer zero is an omni chain interoperability protocol that um allows smart contracts on disparate blockchains to communicate via generic messaging um sorry I can't be there today I am uh at the office homestick kind of with uh pneumonia so bear with me if I break into a coughing fit uh mid presentation uh I'll do my best not to um so today we're talking I'm going to be talking about pre-crime uh and Library upgrades which are two solutions that we think uh are the future on the Chain security so there's two major security risks
um that I like to go over today with when it comes to messaging and bridging um the first is protocol upgrade risk uh that is that these the Creator company uh is able to upgrade the smart contracts on uh any of the chains that they're connected to uh to either add you know bug fixes uh speed upgrades or just new technology right there's things that they're constantly developing and they want to uh you know be the be adding to their their protocol and not just be whatever they launched with uh and then the other is user application risk so beyond just messaging and the security of messaging uh applications that choose to build on top of like any type of generic messaging infrastructure
um have their own risks layout where they write their own smart contracts that could have bugs in them that um they would have maybe not have thought about uh when they're dealing with an atomic uh you know functions on ethereum or other applications and now uh they're dealing with this asynchronous asynchronous messaging uh that is not uh inherent and built into building uh smart contracts uh on these blockchains and so there's the risk that comes from them as well um so there's two there's I guess how do we measure security uh when it comes to Smart contracts right uh you can measure it by the number of audits they've had uh for the application the quality of these audits
um the size of the bug Bounty and how long the bug bounty has been out uh another way that we like to think about it is the money secured over time right the longer something has been out where it hasn't been hacked and it has had a larger amount of money secured over it meaning that the incentives are there for hackers to try to break it and they haven't yet the more secure it's perceived as right so that it's a it's one framework that you could look at it about now the problem is when a smart when messaging layers uh do smart contract upgrades uh all of that time that they were building up the security uh and over over a specific amount of time
they're securing so much money and all that and uh months go by and then they do an upgrade is lost right that is not the same smart contract code uh even if it's a little bit of change than it was when it was securing all of that money and so the clock resets and everything built on top of that also gets its clock reset and so if you are building on any generic messaging protocol and they're upgrading code on you uh you're forced into that whether you like it or not and so that becomes a vulnerability for you beyond your own smart contract code and so what that means is that ultimately any smart contract built with messaging uh that has messaging that has
the ability for upgradability reduces its security uh to a set of admin keys to a single set of admin keys and all the security that they can claim they have optimistic messaging ZK technology whatever they're doing uh is a sham because it actually just boils down to can they upgrade the code and rug you can they upgrade the code mistakenly and rug you uh yes they can if they can upgrade it and so that is what it boils down to and we saw that with uh like the ad the risk of having admin keys with you know the Ronin hack and the harmony hack where they um with those admin keys were corrupted and then able to steal money from uh from seal to steal the funds right
hundreds of millions of dollars uh and then beyond that for example wormholes hack uh the original hack was a zero Day Hack but then they had two other potential hacks where they made smart contract upgrades that they paid bounties out for both most recently a 10 million dollar Bounty where application where users or if a hacker was going to be malicious and didn't want to report the body and collect it they could have forged all messaging so everything built on top of of Wormhole that was secured before the upgrade was no longer secure and all their messaging could have been could have been forged to that moment we also saw this with the Nomad hack where their messaging was uh there everything was working they didn't upgrade that upgrade uh they didn't initialize something and then messaging
was able to be forged and everything built on top of nomad at that point in time uh uh could have had a message for it is forged against it um where previously they could not have before the upgrade and then furthermore on on The Nomad part the concept optimistic Bridges and Roll-Ups right um a roll-up is secured like so the fundamental security is it secured on so for arbitrum and optimism is secured on ethereum right the final state of what exists on arbitrim and optimism uh is actually on a theorem not on their off-chain entity and so it's optimistic in that they're pushing state their sequencer pushes State and then
anybody could be a watcher and submit a fraud proof uh that basically goes through on chain basically their own version of like a Geth essentially and verifying State transition and verifying that that instate was invalid or not uh with optimistic bridging it's actually you know the only thing they have in common is there's Watchers right there is some the The Entity is moving a message and then these whitelisted Watchers which is not open and permissionless they're whitelisted by The Entity um can veto a message right they don't have to provide a proof there's no fraud proof on the destination chain they could veto a message and then furthermore these uh in in this case uh these these keys can uh the the admin
can select uh who is whitelisted can remove whitelisted Watchers can set the from 30 minutes to zero and can send any message they want and Forge it all atomically so beyond just being able to do that with the hyper parameters and not being upgradable on top of that being upgradable any of these protocols could set the set that themselves the say the multi-signature to being able to forge any message they want and Forge it with a single upgrade and do that all atomically if they wished which is the ultimate risk of being able to be an upgradable protocol and having upgrades and so with layer 0 we had a different approach we didn't want the ability we wanted to take
the concept of what happens if uh we go bad or what happens if our keys are stolen are applications built on top of this at risk and so we we decided to take a different approach we call them Library upgrades or validation Library upgrades uh and the concept is is that we uh applications can not be forced into any upgrade that that we make right or anybody makes if you take this this concept uh this approach which is that uh every upgrade is optional you can automatically opt into it but you don't have to meaning as you as you see in this graph that if this if it's secured uh over time right and you've had more money secured over time and a new
upgrade comes out with say a speed upgrade or ZK technology or some new optimistic technology uh that we wanted to introduce those applications that we're building on top of us aren't forced into it they could wait until that new library stands the test of time has more has more money secured on it over a long period of time until they feel comfortable enough to say okay I think those benefits methods are worth it I've seen it last long in the wild and is worth upgrading to versus it being forced upon me and so that is the general approach uh that that is approached us built into layer zero itself uh and what we think is the right approach versus upgradability because
now layer zero Labs cannot do anything to anybody building on top of layer zero the protocol and the entity that holds the multi-sig for hyper parameters cannot can only introduce new things that you could opt into and cannot force things onto you now the second thing I want to talk about today was user application smart contract risk now Beyond uh you know the the messaging layer being secure as with the assumption that that there's no issues with the messaging layer there could still be issues with the smart contracts that you build on top of this messaging layer uh where if a bug exists the messaging layer is going to see a valid message because
from its perspective it is uh it doesn't know the state of your application and deliver it to uh another chain uh based on the instructions it received um and we saw this exactly actually with uh the wormhole's original hack actually they uh had a smart contract there and they were able a message that was able to steal funds on the destination chain was sent and all their validators signed that message because it was a valid message and delivered their own final blow that stole hundreds of millions of dollars on the destination chain and so how can you protect against this so what we came up with is something we call
pre-crime pre-crime takes advantage of the atom of of the of not having atomicity right right now in in smart contracts when there's an actual exploit um when because everything's Atomic you're able you're able to steal funds in one single transaction right but with with messaging there's you lose that atomicity and you have this gap of time of where block confirmations have to uh pass a certain threshold before the message is delivered to the destination chain and because you have that window you're able to to do something uh pretty incredible here what we call pre-crime which is what we do is we take uh this all the chains involved in a given uh
message involved with a given message we Fork those chains we deliver the message and then check them against a set of invariants and those invariants could be you know the total supply of a token has to be a billion and you check all the chains that the token exists on and the total supply has to be equal to 1 billion before and after delivery uh in stargate's example a case the total the the pre-crime the way it would work and the way it does work is that the books have to balance meaning I put in 50 000 on one side I take 50 000 the other side and total money deposited equals Total Money on the sum of all of the chains uh that exists uh out there
and so um basically uh we you you Fork that you you Fork the chains you run those invariants and you don't deliver the message if those invariants don't hope um and so we came out with this last eight this past April uh we silently launched it uh in May and it's been it's been live protecting uh Stargate and uh we're going to be and allowing other projects to now start using pre-crime uh to protect their projects as well so building on top of layer on top of layer zero you also have this added benefit of pre-crime uh and and in general uh I think even uh jump had mentioned it in
one of the recent posts the concept of of checking and variance off chain before you deliver a message uh is a natural progression to protecting uh messaging across between chains um so in the end uh pre-crime prevents the hack uh before it happens uh questions we can take the questions uh later we'll continue with detox and then we'll have all of the speakers in this session together for a panel plus any questions related to The Talk okay so thanks Ryan that was a really
nice talk