DappCon23: Best Practices For Oracle(s) Implementation - Brenda Loya

DappCon 2023 · September 2023 · 25:24

Oracle design choices take center stage at DappCon 2023, covering how smart contracts source and verify external data reliably. The talk works through implementation patterns for feeding price feeds and other off-chain data into dApps, weighing tradeoffs around decentralization, latency, and manipulation resistance. It frames oracle integration as a foundational piece of DeFi infrastructure rather than an afterthought.

Speakers

Topics

From DappCon 2023, hosted by Dappcon Berlin.

Transcript

hi everybody um who here is actually planning to eventually found your own project yeah okay have you guys actually gone through the through the thought experiment of thinking what would happen if I wake up one day you go lunch you go live you're being successful and all of a sudden you get hacked like what happens that morning when you find out that people lost money that everybody stops sit with you and your protocol if you haven't do it hopefully never happens but this is one of the reasons why I'm doing this

talk my so I'm one of the co-founders of teller teller is an oracle we've been live since 2019 um nothing has been perfect along the way um and is actually my second startup my first startup was actually daxia it was a decentralized derivatives protocol and we we launched that in 2018 with a centralized Oracle because there was really nothing available um Oracle IED that's not provable it was basically the only thing that was available and it's super centralized um so after about I don't know a year of being daxia we're like okay now we really have to focus on or

implementation because it's obviously the weakest link in our design and we couldn't find anything that was available so we ended up developing teller for our own use case and you know we the one thing we was that was a non-negotiable was decentralization so we knew it was going to be a little bit slower but at the time you know for decentralized derivatives at least we didn't need anything that was too fast so you know we we we came out with our MVP we ended up getting investment for that in our teller uh but with that said as you develop your own protocols there's three main things that you need to keep in mind when you are actually using an oracle as a user you have to be able to define the data that you need

and Define it in a way that is robust the second thing that you have to look at is what Oracle or oracles and the implementation that you're going to do and include into into your system and do the evaluation based on what you need and then the third thing is what are the back stops if all goes if everything goes to hell with your Oracle what happens to your users to your their money how do you settle because those are three different parts of your design that is that you know it's at the end of the day they hack your protocol it's going to be your fault no matter whose fault it is if you're the CEO if you're the co-founder it's going to be your fault anyway so moving on to something happier

um I'm sure every this is a very technical conference so I'm assuming everybody knows what the Oracle problem is um there's a lot of oracles out there we all try to do the same thing basically bring offchain data onchain and now more recently there have been more talk about the Oracle list Defi and how basically you're trying to find um price discovery on chain and honestly I think that was the initial um goal that we all had is like you know what everything's going to be independent it's going to be a completely separate system from what the traditional system offers and then Along Came all of the centralized exchanges and the moment that

they basically list your token so we we have trb the moment binance and coinbase listed us the majority of our liquidity just everybody moved there so now even if you wanted to do price discovery on chain it's it's harder because people just like the convenience and they're great for onboarding people that are not as familiar with um web 3 as you know some of us that are more technical but it it creates this this um disconnect like our original design was like let's you know everything's on chain everything's going to be independent we're going to be able to survive with or without the traditional system and hopefully bring some some competition so

that they continue to serve their actual users and add you know abuse or you know charge extreme fees or whatever it is that that we were trying to accomplish but the whole goal was to have this whole ecosystem that was separate and then ultimately um you know there is a lot of price discovery that you could do on chain but then honestly depending on what you're building that may not even be possible so you might still need oracles and even if it's not just for Price Discovery maybe you're just doing a different type of query um so this is basic basically you know this a very very basic example of how oracles are used on chain and like I said we bring data that possibly you cannot really

create on chain or data that um that just makes you use cases a little bit more interesting um there's a lot of oracles out there there's uh teller whitet band Dia chain link um we all work a little bit different but ultimately we're just trying to bring off chain dat on chain and who is the best protocol to use um on your system it's going to depend on what you actually need and a lot of people leave this to the end of their design because you're focused on your cool protocol right you're you're focused on what you want to build and this is just one part of it but ultimately it's such a big part of security that you have to go through

this thought experiment otherwise you end up having unintended consequences some um these are just three examples of things that have happened in the space that you know two of these were not even malicious attacks they were just it just happened oops how do I go back um they just happened like black Thursday had a lot of unintended consequences for maker right just because gas prices were so high and they couldn't get their Oracle to update fast enough and then Jesus this is like trying to give to move faster and then the bcx hack was actually a malicious attack where they took a flash loan to manipulate the

Oracle and then use uh tornado cash to like sort of like take the money and leave and it was all in like an atomic transaction it was actually two hacks so because they moved so quickly they settled everything so quickly there was no way not even a fork could save them once the money is gone the money is gone and then synthetics it wasn't really a hack either that was actually the AP they were using one single API for their price feed and the API all of a sudden started reporting three extra zeros and that led to a bunch of liquidations luckily it was a bot and they worked out with the bot owner and they got most of the money back if not everything and

so the first thing we're going to go through is I'm going to give you a framework as for when you're actually designing your own protocol how to think about these 3D different aspects of your design first one's going to be data definition obviously no matter which Oracle you end up using you're going to have to tell them what it is that you need and hopefully they'll be willing to help you come up with a robust definition um how often do you need it what sources do you need them for from and whether or not you want to actually specify the sources and I'm going to go into that a little bit in the next slides but up guys this is okay and then what type

of aggregation you you may need you know from different exchanges volum weight of averages like what is it that's going to make it harder to actually attack the actual asset and then obviously like if you're trying to secure billions of dollars with an asset with a really low market cap or very low liquidity and just listed in like one exchange that's probably not going to work so you just have to think about those things be when you're starting to Define your data for any Oracle this is not you haven't even decided which Oracle you're going to use but you do have to decide this no matter what and obviously if you do decide to provide specific apis in a a very specific calculation and aggregation for

what you need then you also have to think about what happens what kind of a larer detection system do you want because what happens if an a API comes down what happens if they if the API since you don't control it they change what they're actually providing or they happen to be testing something and Report you know three extra zeros and what happens if the API provider bans you from using it or you you you reach uh rate limitations rate limits with them what happens if you don't actually get the data um and then also like you know in terms if you are using an asset because right now let's be honest most oracles

what we're providing on chain it's some sort of pricing um this price you know pricing information but if you are doing that right going back to like how can it actually be manipulated and what's the cost of it versus what it is that you're trying to secure it's going to be super super important and then this are some of the the ways that you can sort of mitigate the risk of this type of attack if you do decide to provide specific API sources you also have to be mindful that you're basically providing a Target you're you're providing an attack Target basically and and that's fineec

especially if you don't have a lot of range for volatility within the information that you need or if it's a very specific type of asset that you know is not listed everywhere it's not like you're asking for the price of eth or Bitcoin I think more generally that's going to have low smaller margins and no matter where people get it from get this information from it's probably going to be very close because it's so highly liquid and so broadly available but that's something that you have to keep in mind um if you are using like coin gecko or like some some of these type of information apis they Pro they already do some of their own aggregation so you need to understand how they actually work and what they

actually include or can exclude because that it will affect you directly Jesus um and then obviously what type of aggregations do you want nobody should have ever used a spot price um that is something that is in traditional system there's plenty of literature of how you can Define robust pricing mechanisms because you know a spot price can easily be manipulated it's just you know ethereum or Bitcoin or you know you you don't really reach finality finality until like a few you know blocks later and that's because it just makes it more expensive as time goes by to actually break a system for that much longer it's

one of the reason coinbase makes you wait seven to 10 confirmations right before they actually say like yeah you have that money and you can spend it now in terms of the Oracle protocol these are some of the Char you know you have to evaluate them based on the characteristics that you need for your protocol to to work properly and that's going to be different based on whatever you're building and I'll give you an example that I really liked um from Rick Paro from liquidy he actually went and did like this infographic that I'm going to show next and and went through like all of the different Oracles and based on what they needed and when that what they thought was important then he went back and say like these are the trade-ups that I'm willing

to make and then this is the actual structure that we're actually going to use as our Oracle and I thought it was really like I have not seen anybody else do that honestly in in since 2018 actually um so it was pretty nice to to see that people are actually thinking about this um when you're actually evaluating a protocol based on how they work now you have to be very mindful of like you can if they're upgradeable you can plan for every attack Vector that they have at this moment but if they're upgradable and they change how they work that can have an effect on your security so that's something that you have to keep in mind and you have to say like what is upgradeable how does it does it

really have an effect in my security um what is their process do you have enough time to react if it's going to take a year for them to like vote on it on a dow that's cool you know maybe you can react you can do V3 and either take them out or address whatever it is you need to address so that you don't get hacked um do they have an admin key or a multi-c what can they actually control and does it really an effect on your security and then obviously liveness what happens if they go away what happens if if you don't get any data like what happens if the team gets sanctioned by the SEC or the cftc what happens to your

protocol uh this is the infographic that Ray came came up with um I'm really sad they're not going to be using teller but um we are are we never negotiate on decentralization and so we are a little bit slower but we are deploying T layer next year and that's going to allow us to reach consensus a a lot faster but this is basically his way of analyzing what Oracle worked best for them and I love it I I mean everybody you know the fact that he won specifically the things that they needed and what was acceptable or what basically those um the green yellow those colorcoded basically it's like what are the things that I'm

willing to trade off because there's no perfect Oracle but there are some things that you might be willing to trade to to do tradeoffs on anyway that's his Traer if you go there he has a a whole uh feed on it um the way that I that I've seen in the last few years people handle this type of risk is basically by implementing either multip multiple oracles and aggregating them on chain or using fallback oracles so when you use a multiple Oracle structure what you need to remember is that you cannot put all your eggs in one basket CU if you choose three different Oracles they're going to have uh different attack vectors or

different ways of working which is great because then like for somebody to break your feed they're going to have to pay a lot more money right because now pay a lot more money it's going to be more expensive and it's going to be a little bit more technically difficult ult to achieve but if you have all of the three oracles providing information from the same three apis and the API comes down none of your oracles are going to work no matter how you know because then your it's your data definition that is is lacking so it's like don't put all your eggs in one basket if you use different Oracles you variate your definition you can they can overlap but at a very minimum use extra or different API so that if one Oracle

cannot get that information then the other two can or five however many you decide to use then the other implementation that I that I've seen is using the fallback oracles where because they want either something faster you know they they might Implement one Oracle as a primary and then do triggers to fall back to a a slower Oracle or to to something that that they believe is would provide them some sort of um liveness guarantee so here the is the triggers because that's basically where the attack vectors can come in so this is something that you have to really sit down and think about because those triggers is is that if you don't do them correctly that's where the weaknesses

can come in but and then within your protocol so this is you just you know going through defin your data providing a really robust definition that you know it makes it very very expensive to manipulate the acid then um looking into the oracles determining what actually works for you and then the third part of that is like what happens if everything goes to hell what kind of back stops am I going to actually Implement within my design um what happens to your users assets and some of the things that we've actually seen in practice have been implementing a delay maker has a delay to use their

Oracle of 1 hour um they don't that uh you can freeze the system I know maker can freeze their system and they did that when um that H when the whole black Thursday happened um you can also limit the change of the asset within your protocol or or trigger a freeze based on maybe um liquidations but all of this you have to plan beforehand obviously when you before you launch and limiting the asset uh the change of an asset sounds like a good idea because it could limit the losses but it it also limits the gains and not all users are going to

be thrilled about that so be transparent um and then um a fork so a fork only works if if you didn't actually settle and they didn't take the money into tornado cash and left if they are allowed they're able to do that then you're out of luck of not even a fork is going to save you when that happens right so but with a delay like let's say if you had a delay implemented where they cannot um withdraw within I don't know 7 Days of some sort of dispute I don't know something that you know it's seven days of some sort of dispute then that gives you the ability to maybe fork and as

long as you you know even if you don't have checkpoints included in your token you can probably go back through events and like different to go and figure out their balances and sort of fork them Fork the Bad actors out of the system but all of this you have to think before you launch and it has to be part of your design for your own protocol even though it has to do with the Oracle design or the Oracle implementation um okay I'm have one minute um this is basically a cheat sheet of you know I there's basically your protocol can be or in terms of the Oracle it can be and the option vulnerabilities are going to be on your data source and your data definition

these are some of the ways that you can sort of mitigate the risk of that and then for the onchain oracles obviously um evaluating them taking the time to evaluate them before you implement them and then the second thing is like what kind of structure do you want to use and whether you know it's obviously like I said the goal would be like for every type of price Discovery to happen on chain that would be amazing that unfortunately I feel I think that for some use cases it's going to be great and for some use cases it's going to be just impossible and that's just for personal experience I remember thinking like it was great it was amazing when coinbase and binance listed us but then it was like wait a minute like now there's like no liquidity outside of

those exchanges they have basically all of our you know or the majority of our tokens and and that's great but then now it kind of limits some things and with that I'm so I have you know you guys have any questions happy to hello everyone um yes I can see the Tran at the back thanks for the talk I think it was great and um we're designing a defi protocol so very very relevant uh how do you balance security with lack of service Interruption uh what I mean is let's say you use vwap or t WAP um to get aggregated prices but then if the market moves and the volatility is still

to high if there's a flesh crash then people not going to be able to you know execute transactions so like what's the right balance there I I think that's something that that as a designer that would be your balance uh or the the tradeoff that you that you have to make depending on on what you're trying to use or how fast you you you want to make your your protocol but is I cannot tell you it's you know it should be like I cannot give you a number because it shouldn't depend on us it depends on you and what you think your users want and the risk profiles are and I think as long as you're transparent with what they're actually

getting into it should be whatever you decide should be fine that should be that was going to be that's what's going to define the risk um profile of your Market but I don't know that I can tell you like do it like this and yeah um I mean if you if you look at uh Rick's chart like he he he's the one of the biggest examples of like actually sitting down and going through the thought process of what they're willing to or how they they're willing to manage that risk um but that's but then you know they decide what what they want to

do so look at that I'm Rick perau I I might be mispronouncing his last name but he's from liquidy he has a whole and I can give you he he also did a talk about it talk on it on the blockchain Oracle Summit in Paris and yeah sorry I can't give you a straight answer okay just take one more question at the back hey hey thanks um great presentation I just had a question on the part of like offchain data and like making sure that you have multiple data sources how precisely would you do that currently because most of the Oracle projects don't either don't tell you where the data comes from or don't give

you the means to verify it so if you use them you you don't know what's under the hood so how do you make sure that's it's more than one API for instance okay so I know at least for for band and for us um you are able as the user you are able to provide a definition and for teller it's it's always publicly available because that's how people we allow anybody to initiate disputes on the validity of the data so the way that it works for teller is the definition is available on ipfs for everybody to know what to report and what is being reported as the user you

will be like the owner of that um data specification and you get to decide what what's in there and that's where also you have to make this trade off of like if I provide specific apis and spe specific aggregations um then I'm also providing a Honeypot or a vector of attack but that's why you make it so robust that it will make it very very expensive for somebody to go attack the asset and then or if you do it the opposite direction where you're a lot more vague and don't give a specific apis like you're just like the price of e USD get it wherever you would want to then now people don't know what um what to be a Target what what what to attack so then now it's you know you're still

going to get your price but that also depends on the type of asset that you are list that you are using because if it has very very small or low liquidity and it's just listed in one exchange or it's just on Unis Swap and the market cap is really low then you're setting yourself up for a cap of a security cap based on the value of that asset and that's a tradeoff that you do at least like I said for for tlor for whitnet for band you're able to specify what you want or you're able to just say like I just want this um but you should be able to know what you're getting thanks yeah awesome well uh please let's put our hands together for

Brenda uh thank you very much