Arweave and Lazy, Multi Language Smart Contracts - Andres Pirela
web3con 2022 · 6 Mar 2022 · 25:20
Andres Pirela introduces Arweave, the permaweb, and the idea of lazy smart contracts. When contract source code and interactions are stored permanently on a blockchain, any executor can evaluate the state on demand instead of every node running it globally. The talk covers SmartWeave and 3EM, an open source executor that runs contracts written in Rust, C, C++, Zig, JavaScript, Solidity and Vyper, and shows the Verto exchange as a working example, with live demos.
Speakers
Topics
From web3con 2022, hosted by Developer DAO.
Transcript
this talk is sponsored by the graph the graph is a decentralized protocol for querying blockchain networks like ethereum and ipfs the graph serves over 2 billion queries per day with thousands of subgraphs deployed for gaming nfp and d5 web 3 applications learn more at thegraph.com hello everyone my name is andres pirella and i want to welcome everyone that's watching this conference right now and who will later watch the conference too it is my great pleasure to be here at the web3 conference and i have to say it's amazing to see how as a community we're coming together in this kind of conference you still got
to talk about our favorite technologies to talk about our favorite networks to talk about how to solve issues with applications in web3 how to solve issues in a decentralized way i cannot stress enough how amazing it is to see all this community growing in web 3 and how passionate people are working towards web 3 applications um it's really visible it's really basically happens on twitter you have been seeing github you can see a lot of development um being being worked on regarding web training it is really mind-blowing and i think many of us here are here for that reason because we're passionate about web 3 applications and solving issues in a decentralized and fair way
um with that said i want to thank the web3 conference for having me today and i also want to thank all the different speakers that we're going to have throughout the day and throughout the next few sessions because we're all here for the same purpose and we're all here to talk about amazing things so thanks everyone for watching and thank you staff that has made this possible and i want to thank all these speakers as well i'm going to be focusing on our reef verto 3m and i'll talk later about it with some examples i'll be sharing my screen and you all can see what i'm referring to but first a little bit of background
what is our riff riff is known as the burma web the permanent weapon arrif is a blockchain meant to store data any kind of data um just like bitcoin is meant to store bitcoin transactions and ethereum is meant to store a state of contracts and contracts hours code and ethereum by code and execute those contracts are we was meant to store data and it was meant to store data in a way that's scalable in a way that's cheap right now as i'm speaking it costs you seven dollars or around
0.25 our weave tokens to sort one gigabyte of data inside the rv ecosystem and that's going to be distributed that's going to be consensually album and it's going to be in a perma way it's going to stay there forever so if you want to become an out and going to the art with network you're going to have access to all these data people are constantly sharing and it's really mind-blowing everything that you can do with a perma web you can store all kind of files all kind of files you can store binary files you can sort images video pdfs json files text files anything at all you can store anything that you anything that can be part of your computer you
can install it in in reef and right now while the community is growing it's really impressive to see all the usages of this for example right now the rift team started the russia ukraine initiative where we're starting all the data related to ukraine in russia the current situation that's going on and the reason why we want to do this is because we want to protect the data in the perma web as sam williams mentioned founder of our weave we don't care whether that information is true or not we just care about storing the data and with the permaweb we're going to let historians figure it out
because they're going to have access to this data they're going to have access to this data that cannot be modified they're going to have access to all this data that's immutable so historians in the future can modify this the perma web is the illusion of the way we store data just like we did with books then just like the egyptians did with paintings on drugs right now humankind have the ability to store data and pass it to other generations and pass it over time without the risk of it being lost without the risk of it being manipulated which is a reset existed until a few years back
you could modify books you could modify anything but you cannot modify the perma web or you cannot modify any blockchain for instance so the perma web dedicated to scale and to store data [Music] makes possible a lot of things it makes possible the transmission of the information three generations in an immutable way but it also makes possible a new concept it makes possible lazy smart contracts and what is a lazy smart contract a few a few things here smart contracts are usually the way we think of smart contracts is not issuing in a lazy way so smart contracts in
platforms like ethereum or mcnier or any other platform any other blockchain that accepts a smart contract as a first class citizen it's all based on a global execution a global machine in global state so whenever you send an interaction to the theorem network the ethereum network is going to catch that interaction and it's gonna execute it and it's gonna all the notes are gonna agree up on this result of that execution along with our execution you have things like us um you have things you know different different fees um attached to the to the interaction that you're doing to the smart contract in all these computers around the world
execute the same code execute the same interaction which is the input of the new smart contract and agree upon the final state and this happens every time the contract receives an interaction and there's consensual agreement on it um but this is all done not lazily because you have all these computers as i mentioned working on that contract actually executing that contract as soon as the contract receives a new interaction as i mentioned before with rwe you're able to sort any kind of data any file any anything at all which means and which opens the door to lazy
evolated smart contracts and what is the lazy avoidance my contract basically the principle is if you can save the source code of the smart contract in the perma web and you can save the interactions the transactions the smart contract is going to receive in the perma web you're going to be able to execute the contract and always get the same result and why in the perma web because the perma web ensures the immutability of that source code the perma web ensures immutability of those transactions that are being sent and anyone can send interactions to the contract
with a few with a few configurations your contract gets readable but you need you need some sort of execution machine and that's why the rv team decided to create what's known as smartweave smartweave is a standard and it's an execution machine currently written in node.js which pulls all these interactions and which pulls the source code and executes the contract with this concept you can easily write contracts in any language because as i mentioned you can upload any kind of files right now it is possible with we
smartweave with our brief to inheriting smartweave to write contracts in javascript which is something not so common and it's it is possible to write it in a deterministic way which means the same input is always gonna lead to the same output of the contract also known as the state there have been a few inventions out there that make this possible such as 3m but i'll talk about it a little bit later right now i want to focus on this concept of lazy volatile contracts with the principle that if your source code is a store in the blockchain and all your interactions are starting the blockchain as well
then any person can run this smart contract in a secure way why because of determinism because the network ensures this consensus on those side on that source code in on those interactions which means whenever an user a new user pulls all that through a software like smart way for 3m they're all going to get the same um output they're all going to get the same state this is just because determinism and blockchain blockchain makes it immutable blockchain makes the source code of the contract immutable blockchain makes interactions of the contract immutable and the executor such as smartwave or 3m
may just execute this executable interpret all this search code and that leads to lazy worded contracts which means every time you want to run the contract every time you want to reassure the contract is valid you just need to load the the executor put your interaction your contract id and the result be done by the server that that's interpreting those interactions and i'll show a few examples about it 3m on the other side is a contract execution machine and it's called 3m because it was meant to be known as the web3 execution
machine 3m allows you to write a smart contract in different languages such as rost javascript sick c sequels plus and we're looking forward to integrating more of them as part of the car team of 3m we've seen a lot of growth in in this concept of lazy related contracts and we want to keep integrating new languages so we can onboard new communities oh i almost forgot with 3m you can evaluate solid contracts so 3m is actually capable of running contracts written in those four
languages i just mentioned plus solidity or anything that's compiled to ethereum by code 3m is capable of doing that and the reason why we decided to structure it this way is because we wanted to do one thing we wanted to more members of different communities such as the ethereum community or the solana community with the ros contracts that 3m is capable of running we wanted to to integrate all members from different backgrounds inside the artwork ecosystem and we're successful in doing so as 3m grows in usage many many applications out there already
using laser voltaic contracts to name a few vertu which is a decentralized exchange that uses laser element contracts and with the principle as i mentioned verto is actually able to securely and in a decentralized way transfer tokens from wirecon to another account and so on all done in a lazy way no need for a global computer or thousands of computer evaluating the same contract as our weave ensures that the charge code and interactions are gonna be there so you only need to worry about running
it with it said we're gonna go into some examples on how to achieve these behaviors now that we're back here with the examples i want to go with this quick presentation of who i am and what i'm going to be talking about in the examples and since we have a very limited time i will try to not extend so much and i will just try to cover what's important about our weaving lasability contracts and and everything that i that i talked before um so i'm on the respirator as you as you know um this is an introduction to war with 3m and vertu
who i am i'm a software engineer i love other activities skin running i love animals and i live in in the state of florida sunny florida in the united states i'm very passionate about software and i've been arguing consultant for berto which i'm gonna touch ground in the future as we go down the road and in the open source community i'm car i'm part of the car developers of 3m which we'll see in more detail soon so what is our weave are we it's a decentralized blockchain based storage um which is also known as a perma web so if you read about r weave you might find
the word permaweb very common inside the r with context and the reason why it's called the permaweb it's because it allows any type of information any type of data any type of files to be served and the nodes have the ability to to serve this data as regular files in urls so you don't need to to do something technical you don't necessarily need to something technical such as downloading a node to access the information but you can access within url that's going to serve the data in the way it's supposed to be served um so one quick example about about hardware being a decentralized storage is as i said you
can store any type of data and nodes can actually serve the data so for example here we have this transaction that was sent and it has a content type tie it's it's attack so transactions inside rwef have the ability to to contain tax which is metadata you can put anything in any tag or you can have as many tags as you want and one regular tag that we know is content type so right now this transaction this id of the transaction and this some sort of blog explorer this transaction is a content type application pdf which tells us um this is a pdf that's being stored in our
weave in the perma web so if i want to proceed and open it i would do the following and now this being redirected this url that i put here is being redirected to a node and the node is actually serving this this document so it's not like it's being saved in any amazon storage or something like that it's actually been saved somewhere in in the world in a computer in a decentralized computer um well in a note that's serving that's working for this decentralized network known as rwef and it gives you the ability to to serve these files and you can do this with with pictures with audio and any type of files
or data you can you can search jsons and so on so if we go to this wallet has several transactions um i believe this adjacent one let's let's try to find a json transaction oh gosh oh they're all pdf okay um okay so here we have a adjacent transaction so the content type is application json so if we repeat the same process now with this transaction id which i copy from here we should be expecting a node to serve this json and let's give it some seconds while it loads and here we have
um we're getting we're getting jason served from rv so we're getting a json serve in our browser from a decentralized computer centralized blockchain network rp now um moving on to a little bit of how can i upload a file how can i upload content to the to to work with well there's different ways and i won't extend so much in it um but there's applications out there there's wallets that you can install in your browser as an extension and you can actually upload a file there's also our drive that i owe which is some sort of google drive but backed by by our weave so everything
that you plug here is um goes to work with and inaudib has a very competitive price so with nine dollars which is the equivalent um in in in ar which is the native token of our weave with this amount of ar which is nine dollars you can upload one gigabyte and it has a very competitive price it's no so expensive and you only paid once so after you play a file you only pay once for that file and it's going to be stored forever in the perma web but i have an example here um a very straightforward example i'm not uploading a file percent i'm uploading a hello world hello webcom with tricom
so here i'm importing this a node.js file um here i'm importing the r weave and they are with package and then i'm uploading it here and then i i'm doing i'm reading from my wallet i'm creating the transaction i'm signing it and then sending it to the network so if i do this i'm expecting this id and now we're going to look for this id inside the block explorer we have from here if i copy this id and and i go to are with the dead which is the central well the gateway that interacts with nodes and it's capable of serving this data to you
um if i go here which is the the the transaction we just posted with this content we see we have a file downloaded and if i open it hello web3con um so that's with javascript it's a very straightforward library and you can upload any type of data strings json objects buffers for binary files images pdf whatever you want and by adding tags um this way you can add for example content type and then you would do application pdf if you're uploading a pdf so then the network is going to recognize that piece of data as a pdf
file um we know what start with a decentralized storage what are the lazy validity contracts laser holiday contracts are basically you upload the the source code to the to the burner web to our weave and interactions and then with an executor which can be any software that's able to interpret those interactions those transactions are going to be able to generate a result um so for example here we have a contract and this is in the expo in some set of vxporter here we have the code which is stored in our weave it's a javascript code it's a smart contract written in javascript
then here we have the transactions the transactions are just json as you can see here the regular jsons that you pass and then you can read the state with tools like smartweave or 3m so for example it's loading all in the interactions so it's pulling from the perma web it's pulling from our width and it calculates the state so it runs this code based on the transactions or the interactions that it's creating and it generates a final state which you can also see here so that's a lasik contract because our
weave is not computing it's not doing any calculation to this contract but you do it off-chain as a lazy evaluation you only need to have the executor which can be 3m or smartweave as smart with as the native project built around our weave and and you can you can plug in the id and use it as mentioned some of the are with mario contract executors since these offshoring lazy evoluted are smartweave and 3am at what is 3m 3m is a fully deterministic so unlike smartweave which runs inside node.js in
ogs environment it has a lot of security flash for the same reason and you can use non-deterministic behavior so 3m fixes all this by being fully deterministic um it's also security sandbox it has no access to cisco so it's not like you can um download a file and plug it inside the person that's running the contract and it's multi-language so it's super evm languages such as viper solidity and it also support raw sig assembly script c simple plus in javascript it's blazingly fast it's about three times faster than smartweave and here we have a demonstration of what 3m looks like so here i'm running this contract
i'm running this contract id which is the same one with rom with a smartweave and now i'm gonna run it and yep here we have the state so it's blazingly fast it's way faster than smartweave as you can see and and it has all these features such as fully intermission and secure and multi-language and this one i'd say this one of the biggest feature of 3m finally i want to touch ground with what virtue is verto is a decentralized exchange that runs inside are we so how does this work because our weave doesn't support smart contracts per se but um it supports flexibility contracts with offshoring
executors as shown before so verto actually makes use of flexibility contracts in and it powers a whole exchange um where you can trade tokens and fts and all those kind of things so what i want to point out with this is we is that with replaceability contracts you can have the same behavior and you can have to some extent the same benefits of decentralized computers such as ethereum such as solana that are always running smart contracts um when placeability contracts you have a lot more flexibility but you can accomplish the same and this very important remark only last note if you're interested to
interact with arbi i highly suggest to do to check this package or with the gs it has all the information and it's it's it's compatible with the browser and node.js and it has all the information about how you can interact with our reefs and send interactions and transactions sign transactions um it's very it's ready to tell and very useful so this has been a little um maybe rush introduction to to our with 3m and verto don't forget to follow me on my twitter which i'll be i'm always posting things about this ecosystem and if you have any questions please do reach out
i hope you enjoyed this presentation and i'll see you next time this was our week 3 mm virtue and most importantly lazy validity contracts a new concept to the web 3 ecosystem thank you so much
