Arbitrum Stylus Unveiled: Where Rust Meets the EVM | Daniel Bigos - OpenZeppelin
Ethereum Denver·Thu, Oct 9, 2025, 12:00 AM
Arbitrum Stylus lets devs use Rust for EVM-smart contracts. This talk compares Stylus to Solidity, showing how it boosts crypto & compute in multi-language dApps. 🚀 Get Ready for ETHDenver 2025! 🚀 We're already hard at work preparing for next year's biggest Web3 event! Keep your eyes peeled for more info on ETHDenver 2025—it’s going to be epic! 🌟
Transcript
[Music] welcome everyone thanks for coming my name is Daniel Bigos and I am open source developer at open sapping and today we're going to talk about arbitrum stylus so let's start with the question what is arbitrum stylus so before arbitrum stylus was enabled on arbitrum chains arbitrum nodes hosted only evm arbitrum stylus adds additional coequal viral machine was virtual machine and that virtual machine allows us to develop smart contracts in any programming language that compiles to walls at this point I need to mention that W smart contracts are fully interoperable with solidity ones which which means that we can call either wmart contract or solidity contracts they can both call each other and it works just out of the box thanks to the was ritual machine we have faster execution and lower gas fees because uh operations on was virtual machine are much faster in comparison to the evm thanks to the arbitrum stylus we also have better security higher security because stylus disables re-entrancy by default now let's check the stock around arbitrum stylus so what we have Stylus SDK it is an rust SDK but it can be any other programming language SDK that provide set of tools libraries components to build your own evm was evm compatible was smart contracts also we have a cargo stylus and this is a command line tool that gives us possibilities to create a new project build our smart contract deploy it and do some do some other stuff around this also we have a n Nitro node and Nitro node is nothing besides the arbitrum node that holds multiv VM uh multi virtual machine both evm and the was virtual machine now let's try to build our first first stylus contract so let's generate the project with the cargo stylus command and as we can see on the screenshot it generates for us just a regular rust project and within this project we need to take care we need to check fre files cargot Tom the first file that we need to check uh in this file we have information about the smart contract name some of the metadata like the auto repository license stuff like that and besides that metadata we have also information about all the dependencies so dependency management comes from the caroom file the great thing around carg arbitrum Stylus is that we can use any rust crate that we want to in our stylus contract and it just works another file I would say the most important one is Leap RS in this file we put all the logic around our smart contract the last but not least main RS file it holds some logic around uh displaying our smart contract interface but we will go into this part later okay so for today talk we're going to build just a simple cter so let's start with defining the storage every style smart contract is built like a r structure that holds some data and in our case we just need to store the current counter value to have our stylus contract we need to use two rust macros that come from the stylus SDK the first macro storage this macro generates for us the rust code to interact with the evm persistent storage so with this attitude we can just store values for our counter and also retrieve the value from the storage the second macro entry point uh this macro generates for us all the code that we need to interact with our Styles smart contract of course that's a very basic contract but once building our own we can use any data type that we know from ethereum like integers Maps string vectors addresses anything that comes to our mind now it's time to Define some Logic for our smart contract and to begin with give you uh more perspective about trust any logic uh in Rust is defined in implementation blocks a rust struct structure can have many implementation block but the most important one is the one with the public macro the public macro exports all of the functions that we have in this implementation block to be smart contract functions so our counter smart smart contract will expose functions like value increment and decrement as you can see those functions are just regular as functions so they can return a value like unsigned integer they can return an error they can Panic as we as we can do in Rust the second implementation block shows us how to interact with the evm stuff like for example emit uh Anum blog also how to retrieve some information around the context like the message sender of course the stylus SDK provides many other functions to to play with the evm stuff having mentioned errors having mentioned events now let's try to Define them as you can see in the code snippet we use just a solidity syntax to Define both errors and events inside Soul macro so Soul macro is a rest macro that based on the solidity syntax generates for us all the structures all the rest code that we need to build evm compatible with smart contracts there is one thing to be mentioned that in Rust we need to strictly specify what type of Errors our function is going to return we may know that we we can have with function bunch of Errors to be to be returned solidity errors to be returned so we need to take the atud due of having just an inum and to have a binding between solidity errors and our rust inum error we just need to use derive solidity error we also need to take care and assure proper quality of our contracts the problem is that we cannot just use pure Ras test to write test for our Styles smart contract it is due the fact that we need some kind of evm emulation we also need some kind of uh was virtual machine emulation and to solve that problem to solve that issue my team at open sppin built a library called modu it is unit testing library to test our Styles smart contracts to write a modu test stylus un test we need to use just modu test macro and provide information which contract are we going to test and also the least of the addresses that we going to use in our test scenario and as you can see in our code snippet we can execute any of our smart contract function on behalf of of a specified address the great thing about stylus SDK is that uh the offchain labs team the team that builds uh the stylus SDK with the newest version of SDK introduced some changes that allow us to modify the context in in unit test which makes the testing easier and allows you to write your own uh testing tools okay so we have our contract ready to to deploy so let's deploy it for deployment we can use cargo stylus tool and during the deployment comment it sends two transactions to the arbitrum chain the first one called deployment it just posts was uh onchain the second one called activation does some operation on the was binary now it's time to introduce a term that might somehow trigger you and the term is Cash interesting cash in blockchain but the problem is loading wasn't binary from hard disk into memory take some time and to reduce that time offsh Labs team brought the idea of cash the cach is nothing more than uh quick access memory and we can store in cash at Max if I remember correctly 4,000 smart contracts everything is managed by the cash manager contract and to place smart contract in cash we just need to place some bit and we have it hashed we can also use our cargo stylus tool to check uh the minimum bid for the smart contract and place it in a cach now we want to know how to interact with the smart contract so let's check the main RS file in this file we have a single one instruction called print ABI and once we execute cargo stylus export ABI comment it generates for us solidity like ABI interface it looks exactly the same as for solidity contracts so it means that we can interact with our stylus contracts in the same way that we interact with just regular solidity contracts of course we may want to build more advanced smart contract that are composed from smaller smart contracts and it is also possible in stylus 2 we just need to create another structure that contains all of the components all of the smaller smart contracts and we need to make use of both borrow and inherit macro those macros we need to use to have the possibility uh to export all of the components contracts functions to be available in our erc20 example so thanks to borrow and inherit macros we have by default exported all of the all of the functions from erc20 rc20 metadata cup and posable contracts additionally if we want to we can also override some of the functions from our components contracts like I did for the for the decimals from the erc20 metadata all the contracts that are mentioned here come from our open saing stylus contracts library that my team was working on so I strongly recommend you checking out our repository playing with our contracts and suggesting ideas what we can build in the future for the whole ecosystem the question is right now if we Styles developers Miss solidity there are some stuff that I want to discuss right now so at first Constructors right now stylus does not provide Constructors we just need to use initializers or do some work around and injecting some cod during during the deployment but the grand information is that uh the PRS bringing stylus conru stylus Constructors are already merged to the main branch so we can expect them very soon the next point is that smart contract composition as I previously said we can have only a single public macro and that design decision prevents us for making use of the power of rust trades and auto implementing some of the interfaces another great news is that the offchain labs team is working on improving the developer experience and we should also have the changes available in the next couple of releases the next the next thing solidity modifiers to be honest in Rust we don't need modifiers we can just play it around with stuff with regular R functions the last thing is that we can't have multiple rust functions with the same name that differs in in arguments but due to some fact we may need to have ins solidity same function names and for that we can use just a selector macro now it's time to explore the power of rust and stylus I always say don't trust very verify and we decided to build a posidon hash in arbiton stylus and with this implementation we buil our own optimized big integers Library we also applied some tricks with was multiplication using the more efficient data types we did some Rust tricks with function in lining because calling function takes some CPU time also we did some Rust tricks with unrolling cut loops and in the end we use War optimiz optimizations on our binary with wasm OP to and we did some benchmarks with free smart contract the first smart contract with posidon implementation the pure solidity let's say easy to read maintain and audit the second implementation called U it's a posan implementation in solidity assembly and also of course our R smart our R implementation Styles implementation of a poson hash and to be honest we were so amazed with the results we get 18th time faster than the solidity implementation another use case that we may want to consider that we touched in the past our Unis swap before hooks we can imagine that we may want to do some intentional uh intense computations in our smart contract but we we can move the logic to the sty of smart contract to speed up the computations and just call the call the logic from our solidity solidity hook for example that computation may be uh custom cares in pricing models there are a bunch of many other use cases that we can leverage Leverage The Power of frust and stylus and those examples are for example onchain verification with ZK proofs additionally we may want to build some Advanced defi instruments not only us swap hooks but anything else we can also want to we may want to uh build some high performance onchain logic like onchain games we may want to optimize our C current protocols by moving the the intense computations to the to to stylus contracts and just to summarize we have endless possibilities what to build with stylus how to speed up our our protocols everything that's all from my side thank you so much for your attention do we have time for question okay so thank you so much if you want to join open sing just SC your QR code check the open positions and apply thank you so much
Automatic transcript — names and jargon may be misspelled.