Gerrit - Vyper + DeFi = 💘
ETH Latam Buenos Aires 2022 · 17 Aug 2022 · 27:44
Gerrit makes the case for Vyper, the Python-style smart contract language, in a friendly tour aimed at developers and non-developers alike. The talk traces how Vyper began, why the 3.2 release closed the feature gap with Solidity, and how its focus on security, simplicity and readability appeals to DeFi protocols such as Curve and Yearn. It also covers auditability, gas efficiency, new tooling like Titanoboa, and how to join the growing Vyper community.
Topics
From ETH Latam Buenos Aires 2022, hosted by ETH Latam.
Transcript
[Music] [Applause] [Applause] which is good because i don't speak much spanish as you can tell but i'm from america los estados unidos they barely teach us one language there so we'll see what i can get through with this i'm very excited to be here to talk with all of you about viper and d5 and for those of you who aren't developers you
might be thinking that there might be a lot of foreign language in this don't worry this is aimed for ed beginners so even if you're not technical we hope that you'll come away with this with more appreciation of the evm as well as a bit of context into this solidity versus viper wars you might have heard something about but we think there's been enough fighting in this world we believe that we should have an end to all these wars so we're not going to be trying to fan the flames of these wars we're going to say nice things about both salidi and about viper in fact in my night job i teach a class on solidity so if i trash solidity i'm out of work now let's talk business here i know why most of you are here some of you have flown from part way across the world so
you can sit in your seats and read twitter on your phones that's fine that's fine it's very entertaining to aid all of you in fact this entire presentation is going to be covering only material from twitter so we of course have to start with uh el hombre grande or delgado vitalik and he brought viper to a lot of people's attentions a few weeks ago when he was talking about out of the blue how much progress viper has made and of course this started up some flame wars don't worry we're not here to inflame these wars any further but a lot of people don't actually realize that viper was started by a vitalik himself and this was several several years ago again more tweets as
mentioned everything on here is from twitter so if any of you are featured in here please shout out because it'd be great to meet all of you and more importantly if anything in here is mistaken don't sue me sue the authors of these tweets so vitalik started viper out of a clone of an earlier language called serpent and you might be saying what's vitalik doing is he trying to destroy solidity well not at all like i think everyone agrees that what's important is when we interact with the blockchain itself when we're interacting with the evm so in fact everyone wants there to be more languages we want solidity we want viper we want other languages the ethereum foundation is in fact funding yet another language called fe so we want as many different possible
languages as possible because at the end of the day what's going on with all these languages is they're a very high level abstraction layer at the very top layer we're trying to create these languages that humans can understand because if you look at the what the evm byte code is executing it's horrible it's these strings of hexadecimal numbers they're super well optimized for all your ethereum nodes but they are really terrible to program against so we've invented solidity we've invented viper fe so that humans can work with these things in a much easier fashion so at the end of the day more languages more apps more apps everyone gets to have a lot more fun as mentioned we're here for a call for unity so we're going to start this off
by featuring a number of viper maximalists saying nice things about solidity viper itself calls solidity in and of itself it says this is a good option we agree again i'll be out of the job if uh solidity goes out of business curve finance uh company i'm a very big fan of is built all their contracts out of viper for reasons we're going to talk about in a little bit and they point out that the more competition we have between all these compilers the better more compilers dev features get better devs they're able to build all the apps that we like to use patrick collins a legendary developer uh he also is an advocate that you should just build in what you like and for a long
time this has been a question of the syntax if you think that python's better use vypr if you think that java or javascript is better use solidity but what's interesting is more recently it's evolved a bit beyond this because there's actually people that prefer the javascript style syntax of solidity and yet they choose viper because the compiler is getting very very good it's gotten to a point where viper has innovated a lot of amazing things and this brings us to verrano viper caliente hot viper summer and you're probably saying i'm loco it's not it's in vienna not verano well up north we do things a little bit differently so up in the north we're all really hot right now except the developers were inside an air conditioning coating and a lot of people
are enjoying hot viper summer so what exactly is going on with hot viper summer it traces back to uh april in april the viper 3.2 got released and this is a major major milestone because before this viper and solidity there are actually functional differences between the languages you couldn't do certain things in viper you could do in solidity you could only do certain things like nfts it was impossible to get a viper nft on openc before this because there was certain bytes type missing once viper 3.2 got released though these two moved into harmony you could do pretty much anything you wanted to do in solidity versus viper so it was no longer a functional choice it became a stylistic choice
so viper said hey give it a shot why not try building some apps and viper and here we see ape works which is a really fantastic tool for learning vipre released a great tutorial recently pointing out that now solidity and viper are compatible so there's no more technical shortcomings vipre's ready for prime time and people started saying all right we'll go ahead we'll give it a shot and when they did they found viper's actually pretty good very clean very comfortable syntax and this particular um this particular point we're going to come back to quite a bit which is that miraculously viper contracts in addition to being kind of nice to use they tended
to compile a little bit better so we got better gas usage this one here really warms my heart because this uh person here is mentioning that the viper has some advantages in terms of the community and the tooling and this is exciting because just a month earlier there have been a bit of a war where in response to viper summer people who prefer solidity said well we don't like this viper because it doesn't have the tooling it doesn't have the ecosystem but this is very fast growing and this is thanks to a lot of the amazing work that's been done if you know about paradigm capital it was a really big win when all of a sudden some of the team there started looking things over and saying you know what we've taken the viper pill we think that the viper is pretty much there
there's still a few cases like foundry integration modules but generally it's catching up very fast to talk about how vipre developed into what it is today let's go to the core values that underpin vipre and really the values underlying vipre is what's driven this development to be what it is today there's three primary goals security simplicity and auditability so i think anyone who's been following the space for longer than 10 minutes knows that hacks are incredibly common within cryptocurrency my um my favorite curve even had a hack itself although it was thankfully a web 2 hack not a web 3 hack the web 3 infrastructure is very
commonly you see a lot of mistakes you see a lot of errors so you could see where the emphasis on security is really really useful within cryptocurrency in particular and just here on the screen we can see a few of the places that vipre is going beyond security it's going to be working in the next several months on ux developer experience trying to become the safest performing language and the highest use smart contract length for new projects we might within a year see a flipping but the safety thing we really have to double down on because it thankfully there's not yet been a major high profile viper hack although small sample size vipre is this concept that when you're writing code even if you're novice and don't understand what's going on by
default we should just make it easy to write secure code so it's a great language to learn from scratch i'd argue because you can start learning this and by default it has a number of things like adding a non-re-entrancy filter to make it a little bit safer make it a little bit easier and avoid potential issues and this is one reason that you see a lot of d5 protocols that have an emphasis on security tend to use viper another big one is urine you'll notice that a lot of these protocols that do have this huge emphasis on security pick viper it might be causation it might be correlation we don't know but whatever it is like i think that we can all agree that more security in the space is a good thing but one of the most important features that we're going to drill down a lot is
this concept of readability and it sounds like a bit of a squishy concept but it's really really important viper has this concept that by default it should be easier for the reader of the contract even if it makes the coders life more difficult and even further if you don't know how to program you should still be able to read vipre contracts and understand it and that's not easy to do it was in part this is one of the reasons that vipre was built off of python and this is more developer wars that go even further back javascript versus python and we certainly don't want to escalate these wars a bit um but there is a concept within the python programming language that it should be easy to follow syntactically you can look at it and understand what's going on even if you're a bit of a novice
so this is really important uh the viper community wants to make sure that contracts are safe and most importantly that people can actually look at it and read it when you're dealing with solidity you have to follow a lot more practices therefore to actually make sure that your contracts are safe and this point here is one that we're going to return to a lot which is this idea that if your code is unreadable you might be able to squeeze some gas savings out of it or you can sacrifice the gas savings and make your contract more readable so there really is an important concept of readability but it's a false dilemma you don't have to sacrifice these the solidity evm the way that the solid code is designed
happens to make it currently difficult to write gas efficient and and very readable contracts but viper has managed to do both and it really warms my heart when i see testimonials like this when people say that viper contract aka python smart contract code very readable for business people for lawyers so every day people can read through and kind of know what's going on this brings us to the final concept behind viper which is auditability we all know that a lot of smart contracts pay for expensive audits and they sometimes don't work we also know that most people sometimes they release contracts that don't even get audited when you are looking at how people behave when they
interact with smart contracts odds are at least about half of you don't even bother doing any due diligence you just say good enough it's on the blockchain let's throw some money in there and we can't change that behavior um 40 are just looking for social proof uh only like 10 or so are actually doing any due diligence and everyone else is just hoping that these people who read through the contract are doing the due diligence so if nothing else we hope that more people actually try we move some of this 40 that are just reading twitter to trying to read the github trying to read through and understand because auditors do their best but they can't catch everything so it's incumbent on all of us as a community to do that auditing to just take a glance ask questions and see what we can do and if we're able to build a
smart contract programming language where anyone can serve as an auditor i think we'll see fewer hacks and fewer funds lost in d5 so then when it comes to auditors like auditors still have a place and viper's thought is that if the code is easy to read it'll be easier for auditors and this benefits everybody if auditors are able to get a sense of what's going on and better understand what's happening then they're more likely to catch some bugs so there's still a great place for auditors and hopefully we'll make auditors lives just a bit easier so this leads to these are the values underlying viper and this has really informed its construction and at this point i mentioned that this is not going to be a flame war between solidity and viper there's things that solidity is better at uh solidity has
modularization and viper strictly rejects it because of these principles um again there's not a technical talk so what modularization refers to is that programmers like me we're very lazy we don't want to write code over and over and over again we want to write a piece of code if it works then we just import it and use it again and again and again solidity is very good at this one of the reasons that nfts and erc20 tokens are popular is because open zeppelin built some templates so even if you don't know much about coding you can just import the work people have done and it's done for you viper currently prohibits this they are working on a pythonic version of modularization which will be coming out soon but for the time being it is a choice so you might prefer solidity if you want to import libraries
other people have written the problem i see with having extensive amounts of modularization like this is it makes it very tough to audit the code if you are trying to read through solidity code when you import into etherscan if you have all these extra imports you're doing sometimes you have 15 files you have to read through so understanding how all the variables are moving around between all the files can just become a bit of like trying to guess it becomes very tricky so i personally prefer the uh approach of just forcing everything into one flat file so every viper contract is one file it contains everything within it and as a result you have that one file you can look at and try and audit everything now
of course ether scan to their credit has been making it easier and easier auditors had complained about having to sift through many files etherscan is one of the best resources and has made it so you can sift through all 72 files but really why do you need 72 files like that and of itself is going to become a bit of a pain so i mentioned that this is not a flame war viper plus d5 is a match made in heaven so i'm going to go ahead and grant that let's say solidity and mfts probably have the advantage there so this user asks why is viperlang overtaking solidity and i'm going to say that uh easy miller i hope you're not here is wrong because viper is not overtaking solidity you can all look at
the most recent 10 contracts deployed to etherscan and i'm willing to bet there's not a single viper contract in there i'm also willing to bet that maybe half of them are nft contracts funny enough we have this amazing global supercomputer and its primary application at this point is printing expensive jpegs of things like monkeys so that you know that's what we want to do with ethereum that's great if you look at the most recent activity on ethereum most of this money to miners is getting paid in the form of nfts d5 is smaller than that over this particular window 5.5 of gas used actually went not to uniswap not to curve not to seaport it went to a nft
project called other side meta and in the course of this over a hundred million dollars was burned just on gas wars to mint this nft so i bring this up because my thesis is that viper is really gas efficient and i don't think this is a value add to people who are minting nfts people who are minting nfts probably don't care if they're willing to spend 100 million on this mint gas savings might not be a big factor and that's fine uh it doesn't matter if you're paying the contract if you're paying a gas person as long as you get your great collectible it's fine which isn't to say that there haven't been really amazing attempts within the nfp world to solve this so one was the azukis which is a very gorgeous nft they introduced this
erc721a standard so the open zeppelin contracts very readable but not so good with gas erc721a is a less readable version of the erc721 nft standard but it is incredibly gas efficient and similarly openc was authored in solidity it's a smart very very popular nft trading platform and it's a bit gas bloated so they did an amazing engineering job and really you should read through it because incredible developers are doing all these amazing optimizations to try and build a much more gas efficient nft trading platform but this is where a bit of a uh a bit of a battle broke out between the solidity and the viper
communities so shown here again you don't need to know too much about coding but all these pages is the function that is used to transfer an nft using cport and the important thing to note is that when we looked earlier we saw that there's all this kind of assembly code which is the code on the blockchain and then there's solidity which is supposed to be human readable and what the solidity is doing is basically directly writing assembly so a viper developer senor pero wrote that had a little bit of fun with this saying that what's going on why are you using this abstraction to just write direct assembly why not write assembly language directly the point of solidity is to try and make this human readable you're kind of losing something here
and it's worth pointing out vipre doesn't allow you to do this so this is yet another trade-off viper says if you're just dealing with bytecode no human can understand that easily so viper doesn't allow it if you need assembly you need to go with solidity fubulobu went a little bit further and this is really an epic tweet so we're gonna have to break this one down he was playing with this uh erc20 transfer that's going on within this uh within this seaport contract and he's looking at this transfer function and if you look on the right here this is a full function it's like if you printed out maybe 10 pages of code and it's really confusing it's all this stuff it's well documented just doing so much under the hood so we decided to do
a head-to-head test let's see how this does against viper's equivalent which is five simple lines of code you can probably kind of guess what's going on just by reading it it's simply taking a token and transferring it but you know that's fine solidity is trying to sacrifice readability for gas consumption so much to fubulobu surprise the simple version that was not gas optimized in the slide this still comes out better so he had a bit of a laugh a lot of casualties but i think our communities have made true sense then we bring this up because gas usage doesn't seem to matter for nft people and we're willing to bet that most nft people fall in the category people that don't particularly care about
readability um given the amount of seed phrase hacks we've seen amongst the board ape community we don't even know if people necessarily know how to use a theory no offense if there's any board eight people here i really wanted board ape and just a quick plug if you are interested in viper nfts the first viper nft deployed to open c or deployed in compatible with open c was written by me so feel free to check that out there's a great repository a lot of fun building it and it was in it was for an organization that i'm involved with called pak dao which is a public goods focused on in particular like positive advocacy of cryptocurrency with so much negative stuff happening with governments trying to suppress cryptocurrency i think it's a really good cause so this gorgeous nft by scooby doomer was commissioned and
released as the first viper nft that i know of so i'm conceding that solidity is probably a good match for nfts you can just import the nft erc 721 standard from open zeppelin and you don't need to change much because most nfts have the exact same functionality you can use 721a it's good enough people understand it and this is a big concession we saw that this is most of ethereum but i do think that viper in particular has a really great use case with d5 and we mentioned that there's very very few contracts that are actually actually released using viper so if you take a look at most recent contracts
they're almost all solidity and yet despite this viper has this really outsized portion of tvl or total volume locked within d5 so there's obviously some sort of fit here where if you're programming a defy app viper might be a really good fit and we look at this in several different ways but when we're talking about nfts essentially you're taking a pile of money dumping it into a black hole you don't care what happens you get your collectible out when you're dealing with d5 every single penny really matters because you might be trading a thousand dollars for another thousand dollars of a stable coin and if you're losing out in terms of gas if you're losing out in terms of slippage it isn't like a really big deal so when you're dealing with d5 you have to shave off these pennies you have to
be able to count every single thing and here's where people are finding that use the vanilla erc20 token from viper and generally out of the box it's going to be performing as good or in most cases better than the erc20 equivalent in some cases even the like hyper gas optimized erc20 equivalent but even more so within this readability also plays into it so as far as like gas wars go that's a race to the bottom if solidity and viper want to compete on gas there's a theoretical limit of what the evm blockchain can do but when you look at for example a curve which is a site that i spend a ton of my day focused on
curve is people are saying well is it actually that much better it seems like the gas is com gas is worse in some case but if you actually dig into it it just happens to be because some of these curve contracts are doing really really complex stuff if you look at the baseline viper still is the edge but where viper is a really good choice here is that curve is using incredibly advanced math and here's where i'm really really bullish on just even beyond viper defy in general i really think that we're in this sort of first generation of d5 where most of the apps that we're seeing and d5 are not that complicated it's usually like give a token get a token back and that's great it can also just be done using a standard four function pocket calculator addition subtraction maybe there's some
multiplication and division if you want to get fancy but we haven't really seen that many d5 apps that are utilizing some of the complex mathematical capabilities and i think that in particular curve is one that's really using d5 to its full potential one and at this point we're not talking about what both languages can do on the blockchain we're talking about what the compiler is choosing to do which makes it better to code some of these applications so if you're building a complex defy app like curve has done and urine has also done one of the issues you come with with solidity for some time was this stack too deep there's a limited number of variables you can get before the compiler chokes but viper has planned for this and allocated its memory efficiently and there's no such thing as stack too deep so you can build the most complex defy
app using vipre without having to cut corners it just makes it a more natural easier way to program and then on top of this the defy applications that can be built that are going to be more complex if you think about it it was like 2008 when we started seeing like the really fancy trad five products like all these complex derivatives and those destroyed the market so don't build those but there is room for more complicated math to be done using d5 and if you're trying to do that vipre has a number of complex mathematical functions built in at the compiler level so it's right there if you need to do things like shape rotation if you need to do things like elliptic curve math there's functions that exist for that again these are compiler choices so solidity could build these if they like
but because viper has had these principles of let's build this from scratch and most importantly when you're trying to deal with advanced math it's already going to be tough enough so make it as easy as possible for the auditors to understand what's going on under the hood because uh the math that's being done by some of these curve contracts is mind-boggling um if you're not super familiar with tri-crypto it's a pool that contains bitcoin ethereum and dollars and it's able to self-rebalance itself so in other words if the price of bitcoin fluctuates the pool picks this up without any external oracle it just does the math on the trade volume and figures out what the price should be rebalances liquidity itself using some complex exponential smoothing functions and as a result it's been up for over a
year with no issues so some incredible stuff being built we're going to see much more incredible stuff being built and this ties back to this point we had the beginning which is the community because all these and the tooling because all the tooling is being built by a community of people who are finding viper very easy to work with so recently since uh viper launched it hasn't slowed down any it's launching this new feature called titanoboa you can think of it as a natural execution layer which makes it easy to plug into for example a jupyter notebook python has a number of great data science libraries so it wouldn't surprise me if we start to see people integrating much more complex features like we haven't seen the many machine learning algorithms or even neural
networks applied too much to cryptocurrency yet but we can build some very amazing things when it happens and i think that the kind of natural level of tooling that's being built is going to really assist in this and of course all these great tools here's another one that's being built is coming just because of hot viper summer because all these people are finding the viper community and finding it's a great place to make a big impact in cryptocurrency so viper is being built just by the contributors and there's never been a better time to simply hop into a discord and be able to ask a question and have one of the core engineers of viper answer your question toss out a feature request say hey here's what i'm building i'm having trouble with this they can actually pretty quickly add something together and have that ready in the next release
they're shipping very fast and they're shipping really amazing things and on top of this like the documentation is very good but if you have questions like the community is always there always ready to ask and answer questions viper just in case you're curious it's not funded by vcs it gets a lot of its funding from a project i had the privilege of working on called ve funder which takes curve gauge emissions and instead of directing this to curve pools it sends this directly to good causes uh viper is one of these so vipre was the first project that received just a stream of incoming curve pools so if there's things you need funding for you might be able to ask vipre and they might be able to help out and if that's not enough amazing ascii art
so i really believe that together we're all going to be building some amazing stuff and at viper 3.3 we've essentially caught up with solidity so we can just imagine what kind of amazing things are going to get released when viper 4 gets released inevitably finally a plug if you're interested in learning viper i've been working on a series of youtube tutorials in which you can build a erc20 backed stablecoin in my case a curveback stablecoin not the curveback stablecoin and unfortunately i'm not allowed to release any alpha about that but if you want to build a generic curveback stablecoin with much simpler likely math then you can follow this tutorial i've been working on but other than that if you'd like to join the discord this year link will join you we'll be happy to chat there or if anyone has any questions i don't know if
we do q a here no q a so questions are all on the discord thank you everybody really appreciate this adios [Applause] [Music] [Applause] [Music] you
