ETHDay - Oracle Networks & the Oracle Problem - Chainlink
CryptoCanal·Sat, Oct 7, 2023, 12:00 AM
Amsterdam hosted Devconnect for a week, gathering the brightest developers and Ethereum builders. To get a glimpse into this universe, we hosted ETH Day on April 18th at the Transformatorhuis to showcase the best of the week to a wider audience. Learn more about Andrej Rakic (Chainlink) https://twitter.com/andrej_dev https://chain.link/ - a discussion around smart contract and web3 security and vulnerabilities, and best practices for avoiding them. We would like to thank our partners and sponsors that made this event possible. 🌷 Ethereum Foundation https://ethereum.org/en/ Balancer https://balancer.fi/ Oasis https://oasis.app/ Perpetual Protocol https://perp.com/ Lido https://lido.fi/ 🦦 CryptoCanal offers education, event and consultancy services for the crypto industry. Join our telegram community and stay free. https://t.me/CryptoCanalCommunity ETHDam in the making https://www.ethdam.com/
Transcript
foreign [Music] [Applause] thank you for having me uh today we are going to discuss the Oracle problem the importance of this Central historical networks we're going to tackle a bit on a hybrid smart contract and generally I would try to briefly explain you the chain link protocol if you are not already familiar with it so my name is Andre rakich I'm one of the developer advocates for channeling product called a trainer clubs you can see here listed my Twitter handles my email but you know I'll be here with you in person so feel free to reach me out to talk about anything chain link related actually if any of you attended to Austin Griffith's talk uh earlier this day about gaming uh on ethereum we are hosting tomorrow uh live smart live games for smart contract developers at 5 30. tickets are sold out but if you really want to attend and to play the same game Austin did earlier uh hit me with the DM on Twitter and I'll try to add you to the list but let's start with the agenda so in in the next briefly 30 minutes we are going to talk about the Oracle problem mainly about this Android Oracle networks as and as I said about the chain link protocol itself so to understand the Oracle problem we first need to understand the purpose of smart contracts so obviously I'm not going to explain you the the what smart contracts are you all already know that but we really need to understand and which problem smart contract solves and that's the problem of trust so with traditional agreements right imagine like uh bank loan that that's like a traditional agreement there's always some third party some contract operator which both sides of the agreements need to trust and the problem here is that one word trust so that third party can have some common interest can have some conflict of interested and that's this is bad right so we all remember that some centralized protocols banned regular users to trade game stocks when they need it the most right and there was that crisis in Greece couple of years ago when Banks limited cash withdrawals to only 10 or 30 Euros right with smart contracts and so-called digital agreements this is not possible because the term streets are written inside the code itself they're deployed to some general purpose blockchain cannot be changed cannot be modified cannot be corrupted deleted modified in any way right and the really nice thing with smart contracts is they rely on cryptography and blockchain as underlying Technologies so there's no need for a trust right but smart contracts are not perfect right so smart contracts are kinda limited to know about the things inside their own isolated environment like block number block timestamp maybe can call a method of some other smart contract for example I can if there's some erc20 token smart contract I can from my smart contract query the balance of some address but if we are on the same blockchain network of course but what about other data which are kind of necessary to create really powerful agreements right like what's the current weather here in Amsterdam was the price of eth in terms of USD smart contracts can't know that info can't get that data and that so-called smart contract connectivity problem and now uh I I would like to introduce to one other term and that's Oracle so technically the Oracle is any entity that can bring any type of off-chain data to the blockchain period this is a really complex sentence by the way because like what's that any ATT entity what's how they can bring that data to the chain but to understand deeply understand the Oracle problem the problem is that Oracle can be centralized point of failure inside your dap right if you have only one node Oracle Source whatever and all call your whole set of smart contracts your app relies on that one entity it's a problem it's essentially a centralized point of failure light so we need some kind of decentralized environment to get us off-chain data on chain right and that's why decentralizorical networks are so important and the solution to this smart contract connectivity problem slash Oracle problem is trailing protocol so chain link protocol is basically open source decentralized Oracle network of nodes which serves as a middleware layer to provide off-chain data to various types of blockchains so chain link is not a blockchain but it that decentralized Network needs to reach a consensus so to come back a bit to the Oracle problem so what's going to happen if we have one centralized node as a service so we are at risk to get inaccurate data or no data at all that's why chain link is so heavily focused on decentralization uh the trailing Oracle Network consists of four replicas by independent and simple resist node operators which can provide off-chain data so anyone can run their own chain link node can become part of the network itself and the thing is that all of these nodes can have their own source or sources of Truth for any type of of chain data right and once the request from the smart contracts goes to the training Oracle Network each of those nodes has the ability to provide their own data but then as I said the chain link Network needs to reach a consensus it's not a blockchain but it has its own consensus algorithm and you have the incentive as a node operator to provide provide valid data because you can get a rewards in link tokens and if you don't provide valid data you're at risk to be punished by the network itself because the they have like the consensus algorithm so what are some hybrid smart contracts that I mentioned like in one sentence hybrid smart contract is any type of smart contract which combines combines both on-chain data and computation and both of chain data and computation and they're really powerful so how many of you know to read solidity a lot of people cool so I wrote this simple text so it's like the simplest decks ever so you can see there's only two storage variables like token one and token two and it have this on the bottom add liquidity function so you can add some initial liquidity to the pool and it has this swap function so I can swap token one for token 2 and vice versa there's some kind of requirements never mind but if you go to this unswipe amount get equals get swipe price so you can see that I implemented also a get swap price for this simple decks right and it's really simple so it's one line function it basically Returns the initial amounts amount time the balance of the destination token and divide that value to the balance of from token balance inside the pool okay and can someone tell me why it's a bad idea to use this get swap price in my D5 project that I'm going to build on top of these decks you know I want to build a D5 protocol but I need a price of these tokens why it's not a good idea to use this smart contract or this function yep you can manipulate the price but how exactly yeah so what he said is basically you can manipulate this price with the flash loan inside the single block block so you can either do a series of conjunctive swaps to drain one side of the liquidity or you can uh add enormous amount of liquidity to one side and you'll get inaccurate price and the problem is if you're building a DFI protocol on top of these decks you're at risk for your users to get users to get wrecked because of the simple inaccurate price uh but imagine that now there is another decks you're building on top of it much better than my mine of course with 20 lines with audited code it's like a you know industry standard decks whatever why still is not a good idea to rely on that d-wop Oracle as a source of Truth for your prizes has ideas Maybe okay because if you think about it it's still a centralized point of failure because you're relying on only one Dax that it will provide you the correct price of any asset but there's Warriors but you know there's various sources of Rises and other decks some C5 protocol some centralized exchange whatever like debt prices can differ a bit you know in by that decimal places but in D5 we really care about that decimal places and that's why the good idea is to use training data vids so training datafits is one of the probably the most used product by chain link it power like over 76 76 billion in the D5 world and that number keeps growing and basically it has the full Market coverage so it covers all sorts of truths like taxes taxes volume base average whatever and it's using OCR I will talk a bit uh about OCR later if you're already familiar with price fits but imagine that you want to get the price of it in terms of USD dollars how chain link price fits work basically you have on the right side of the screen smart contract calling to chain link price fits to get the latest price of each token uh and then all of these nodes has the or has the have their own source of fruit or fruits for example one of these notes can use my vulnerable decks as source of Truth for price some other can use some other decks third note can use one decks one sex and one another decks as source of Truth and each of these nodes has to provide their own answer to to this question like what's the current market price of ethereum in terms of USD dollars and then the whole network needs to reach a consensus to aggregate all of this info into one single price and then return that correct price as a callback to the calling smart contract and you know if the node one of the nodes use my vulnerable decks as a source of Truth here's the truth to get punished outside not punished but the to to not get rewards because it provides inaccurate data how you can see which nodes provide you data for the price fit your you want to consume for example ethereum it in terms of USD a simple go to data.chain.link you can see all of the info about specific price fits and you can go to docs that change the link to see how easy is to use it inside your solid smart contract I'm not going to demo it because it's a simple one line of code basically and it's really really simple like to to grab it from the official Docs and I mentioned this off-chain reporting so if you're already familiar with the price fits and use it in the past uh you know that uh in the past we use so-called flux aggregator model where each of node was needed to commit or on to make transaction of their like uh source of price whatever with off chain reporting uh now all of these nodes can communicate between themselves in a P2P Network and then like uh they can reach consensus in a that way so imagine like you're hosting uh you're having like uh let's say online store and you have like 10 10 Pro 10 products needs the same to ship to some one same address with the previous model you pack all of these products inside the single box make a stamp and then send it with OCR you you take all of these 10 products put it in the same box and ship it to the end user so let's start with another solidity trivia so imagine that you're making a game now it's a simple coin flipped game basically if you can have for example uh you you just call a flip function with the gas as a Boolean parameter so true false is it like head of or tails and if you can if you for example say you make a 10 consecutive events you can get 32 eaters as a reward and became a validator for example and you can see how we uh basically calculate this block value and how we then decide which side is true or false or head of Tails uh can someone see what's the problem with this smart contract yep exactly so this is obseer the randomness this is not a true Randomness and as she said it depends on block number and miners can manipulate that unlock number and can know because like they can see these smart contracts of course this source code on meter scan or whatever like it's all all public they can know uh in in front of time which random so-called random value this smart contract will provide and they can hack our game and win the grand prize So to avoid that we can use chain link vrf so chain link vrf is a service which can provide you a truly a Randomness truly random values to your smart contract which can also and this is really important can be cryptography verifiable anytime so basically malicious operate RNG operators are risk if you're creating a game which shows some money you're at a risk to lose all that money because someone can predict your pseudo random values and if you think about it like if you call net.random function inside the JavaScript it's not a true Randomness it's obscill to Randomness and it's okay for some use cases right if you want to host a giveaway to all of you and to give you like one t-shirt it's okay to use method of random but if you if you handle the money on the real blockchain real people tokens coins whatever they're really you're really at risk and you definitely should not do that and you should definitely use chain link prf uh so couple of notable projects are already projects are already used vrf basically you can select lottery winners you can create random threats and it's really simple to implement it inside your inside your code and if you are not following us so we recently released chain link beer fv2 it's a new version of training qrf much powerful much gas efficient and for the first time you can specify the number of random values you want from in a single call so with vrf we want you can only request request one random value per time which we are halfway to you can get like five numbers in a single transaction call and do with that five values whatever you want to do it right and it's really a gas efficient in terms of ovrf we want so I definitely encourage you to try it you can see it on our dock so docs the chain.
link also we have a bunch of starter kits hard hat truffle brownie Foundry adapto starter kit where you can see how you can use it in inside the solidity code and how you can properly test it which is really important and maybe it's not into at first glance and finally I would like to let's see the time okay we have it to introduce you to chain link Keepers so chain link keepers are the way to automate your smart contract execution so smart contracts are Passive by Nation by Nature so to to trigger a state change on a smart contract you need to somehow ping it to call some function and then smart contract with execute some function and then we will have the change from state a to State B right but if you want to do some if we want to do some devops thing inside the smart gun or on on the blockchain there's no easy way for us to do it so we need to use chaining keepers so basically what chain link keepers are imagine that you're yield farming some DFI protocol for example and uh you need to call that Harvest or tanned or whatever the name of the function has is or in some specific time frames based on some conditions so the solution one is for you to be in front of your laptop during whole day try to manually click transaction on your wallet metamasker whatever coinbase whatever wallet you are using or you can set up a simple smart contract and Implement so-called keeper compatible interface so what is this keeper compatible interface you can also go to dogs.train.link to seeds but basically is a solidity information interface consists of only two functions so one function is check upkip and the other function is perform upkeep so checkupcup will be in most of the case like 99 of the cases The View function and checkup Kip has the logic for for the keepers basically the keeper network from the chain link Oracle network will ask your smart contract on each block or in each regular time frame like depends on the Chain you are do you need something for me calling the checkup like I'm doing it something for me doing something for me doing something for free and that track track upkeep function returns Boolean value true or false and can return also by its 32 value which if you need it like as a function argument to your performer object like it differs but basically my checkup keep will return true or false so if my checkup can function return false nothing happens we are currently we are still in state a if my check up cap returns true then the perform upkeep will be automatically called by The Keeper Network and inside that perform upkeep is your logic you know something you need to be implemented inside that perform APK function can be a call to some yield farming protocol like called The Harvest and that perform upkeep will actually cost you money because you're updating the state but check up keep will be a view function free for you uh to to use chain link Keepers after you after you like deploy that keeper compatible interface your contract partner you just need to go to keepers.chain.link to register your app keep and to find it a bit with link token and then just forget about it so with vrf and Keepers there's some simple uis where you create subscriptions and then fund it with some amount of Link tokens and basically you can forget about it because it's going to execute all of this stuff automatically you also have the ability to withdraw their tokens if you need or to fund it more or to cancel upkeeps or to cancel Randomness to add some new consumers whatever but it is that simple so what we covered today we covered the benefits of smart contracts we tackled a bit of the Oracle problem I present you a bit of the training protocol all of new stuff uh we're currently building and if you want to continue to learn more about the training protocol itself you can go to our Discord chat to co to chat with the community members link is over here I mentioned starter kits so basically it's a boilerplate templates for you to write and use a chain link inside your smart contracts as I said we have hard hist Target both JavaScript anti-script Edition tropos Advocate brownist arcade Foundry adaptools Solana all of this uh really useful developer tools obviously number one place for you to go when when you want to use chain link is to the official documentation so the URL is docs.
chain.link and finally if you're a beginner in the space or you just want to learn more about the latest trends we recently launched chain link Academy so go to chain link.education sign up for for like um for curses like from the beginners to more advanced and also if you want to participate in training hackathon there's still time for you to to apply at hack.chain.link uh I think next Friday or this Friday is the official launch so if you still have time to to to apply to hackathon and win some some prizes as well uh I think that's it yeah so we have a couple of more minutes for questions if you have some questions feel free to raise your hand I see you hi uh thanks for the presentation so I have just a pretty simple question so on April 4th Elon Musk tweeted that he became the largest shareholder on Twitter on that day the stock jumped up like 15 let's say I want to make sort of like a smart contract that does options based on what Elon Musk tweets right it's very easy to use the chain link system to sort of build out to get the price of the Twitter stock uh onto the blockchain you know uses a small contract that way but do you see sort of so like chain link is great for like numerical data input but for example if I want to get the data like the actual tweet um tax from Elon musk's account is there something in sort of does would chain link work with something like that right now or do you guys have something down the road map or because from what I understand it like you have multiple data providers and you sort of get like the average with the consensus algorithm so do you like moving to sort of more non-numerical data input is there something that qingling could do or or is you guys something working on something like that yeah yeah good question by the way uh so yeah so about the first part of the question so whatever the stock price will be dependent on retweet or whatever other off-chain circumstances whatever uh chain link will provide you the current price at that moment and it's like a architectural layer and you build on top of that basically you maybe want to gamble of this never mind but there is a there is a way for you to make a HTTP get request from a smart contract to Any Given URL on the outside world so on if you go to dog the chain.
link find a section with any API so any API is a service for that and basically you can create any type of HTTP get requests from a smart contract for for a given URL so you can even hard code that URL inside your smart contract or you can pass it as argument whatever and the the second thing is that you can go to market.chain.link where you can see all of various providers provide various types of data because you need to pay for them to get you that data and they have like different prizes you know so you can uh you know negotiate whatever and also like we have a on our Discord Channel like on our Discord server specific channel for that types of request events so you can maybe host your own node to become a node operator to provide some of this data or maybe you can ask someone to to provide it but basically go to any API and that's the way for you to get HTTP HTTP gets requests one thing is that you said you want the text so your smart contracts need to know the specific type of the request so it need to know that this is a text or it needs to know that this is a value or it need to know that it's it's a number but with several decimal steps you need to compute the decimal steps etc etc but if you know like which kind of data and in which format like Json or whatever your url will provide that they data you can use it by chain link any API hope that answer your questions I do have a follow-up question so so just uh so again um getting a text like you say is from the marketplace right but from what I understand so like the with again with the numerical data input you saw that averages out or you try to find the majority consensus from the data providers but there's no such thing for tax in that scenario so is it just like I have to trust the data providers that I find in the marketplace or is there sort of like a diff like if for example there's a malicious actor trying to feed like oh Elon didn't tweet that he acquired majority snake and try to mess with the smart contract that way the slight changing sort of like is there a fraud prevention mechanism in chain length for dealing those texts so this is still a really young project so that's why we have like that separate Discord uh you know chat in order to like chat with other people I I think yeah I can say this currently the market.chain.link is in a rebuilding phase so we are going to completely reveal this to basically answer your question and your needs so just follow our and you will be notified soon that's it cool thanks any follow-up questions Maybe one two three yeah otherwise I have a quick question as a node operator you do you have the option to only uh Supply let's say certain data feeds and not everything or do you have to run everything in a very one very big monolithic node yeah so right now you need to specify which data video one can to consume and like the majority ones are there uh you know if you create your own token will probably not supply it but if it gets traction you can request a addition of training price with new price of it and that's that net recover basically constantly growing because like for each new token there's like a number of nodes that need to like reach consensus so that's like a critical piece but you can request basically from the UI and then we'll try to implement it for you okay thanks yeah yeah um assuming I'm a look operator is meeting ethereum prices to the within the network of a data provider and I'm keep submitting 5000 for whatever reason so I'm being malicious how long does it take for me to being kicked out and what's the process is like oh good question so I'm not the the one who actually constantly working on a protocol itself but basically it's an open source code so if you go to smart contract chain link this is the official repo for chain link node it's written in go so if you know like to read a bit go you can probably find your answer there so all of this stuff even the consensus algorithm are open source so at the moment I not sure like what's the current time frame but you it can be easily trackable because it's not a hard-coded value but it depends on some conditions and it's the best way to actually Deep dive into the code itself and find the answer yeah cool thanks okay very good I think we have time for one more question and if not we of course thank you Andres for your presentation today an amazing thank you for having me it was my pleasure to be with you guys enjoy [Music]
Automatic transcript — names and jargon may be misspelled.