# Solidity Inline-Assembly for Developer Experience by vectorized | Devcon SEA

- Channel: [Devcon](https://streameth.org/devcon)
- Date: 2025-10-09
- Duration: 16:41
- Topics: Science & Technology
- Watch: https://streameth.org/watch/yt-CUHov__69b0
- YouTube: https://www.youtube.com/watch?v=CUHov__69b0

## Description

We demonstrate how inline-assembly is used at Solady to improve the account abstraction developer experience, write concise code, and create novel features.

Solady is a Solidity library (MIT-licensed). 

Some of our biggest users include Coinbase, Optimism, Uniswap.

Speaker(s): vectorized
Skill level: Intermediate
Track: Developer Experience
Keywords: Gas, Account Abstraction, solidity

Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum, https://warpcast.com/devcon
Learn more about devcon: https://www.devcon.org/
Learn more about ethereum: https://ethereum.org/ 

Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on Swarm, IPFS and more.

Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. 
Devcon SEA was held in Bangkok, Thailand on Nov 12 - Nov 15, 2024.
Devcon is organized and presented by the Ethereum Foundation. To find out more, please visit https://ethereum.foundation/

## Transcript

[Music] okay so I'm vectorized um in my free time I maintain this Library called so lady which is a solidity library of various features written mostly in inline assembly so today I'm going to talk about how we use inight assembly to make things simpler uh for users of the library okay so to start off some time ago I posted this tweet saying the beginner used assembly to save gas because that's the most obvious thing the intermediate use assembly to avoid the spirus dragon limit because assembly makes your bik code much smaller like even without e if you use SOL lady you probably can see like 20 to 30% right code reduction then the advanced use assembly to save time once you are so used to writing in assembly you just straight away write the optimal U code so in that assembly and U we can use it interchange interchangeably in this context okay so um today I'm going to describe a bit of two and three the second and third Point wait okay so some examples to start with the first one is safe transfer leap I'm also going to talk about the leap CL in so lady so in so lady we have this Library uh for proxies and our proxies are mostly I will say most if not all our proxies are like directly written in bite code then we also describe like some higher level features for example lip s and how having uh in assembly can help in testing okay so for example safe transfer de we use this uh let's say if you want to send ether to someone in the auction contract but what if the sender is some smart contract that guess grief or does not implement the receive function so in so we have this function called Force safe transfer if which users self-destruct to force send the ater to the person so as a user you don't need to care about all this Integrity you just use the function and you can be very safe that the addor will be actually for send to the person and why is this useful uh we know that rep if is like not on the same address on every L2 so if you want to deploy your contract to the same create two address and you use rep if is a bit Troublesome so instead you can just use this function and you can save your uh brain space and time okay in lip clone we have this function called uh deploy ERC 1967 which deploys a minimal bright code proxy that is upgradable so it's based on this uh ERC called 7760 so uh this proxy has been written for more than a year but recently we want to consolidate all this into a ERC so that block Explorer can Implement Auto verification easily so because this ERC has been around like the proxies has been around for some time it has also gained a bit of adoption so on base chain uh it is the proxy of choice used for the coinbase M wallet and for polygon I think they are using it for something else also so there are like over 100,000 examples of these proxies being use around and the advantage is that is fast is small and on uh some cases it auto verifies so it save your time you don't need to do some at scan API key it just verifies it by itself so lip s also have some high level functions uh can be useful for your testing purpose like we have set operations on sorted arrays you can use it for your invent test and then for test class uh we know that if you def write your test in Foundry you have to Define your the random variables in in the function arguments and there's limited amount of space you can do that and you have to think of like nice names for the variables which I find is very time consuming so instead I use uh like a lot of black magic to write this underscore random method which allows you to use uh to Generate random stream of numbers anywhere in your code so you can do something like guided fast testing and if you want to uh know how to integrate into your project you can follow the link below okay so here are some other example libraries you might want to check out uh one thing I find a bit interesting is dynamic array lead for example in solidity if you define a array you know you can't do like a pen or push back but whereas this Dynamic array de has that function okay so why inite assembly is good for a library writer like me first it provides some techniques like it helps me do some uh fine-tuning of the code so that users of the library don't have have to worry that my library caus them to have a stack too deep you also can enable some cool math that is not accessible in normal solidity and then uh if you know how to push the compounder in the right direction you can achieve some zero cost compound time extractions so for example avoiding stack too deep uh we have this function called La what in fix Point MEF Li if you use it on its own uh sometimes uh the compiler tries to inline it and it causes causes a St too deep but if we rewrite the function in inline assembly you can somehow rearrange how the variables are allocated on the stank and by rearranging the variables you help the compiler compound in a way that avoids St too deep with or without IR so in uh so da we are very particular that it must work in as many situations as possible so whether you use V or whether you choose not to use V we want to make sure that it just works you don't need to worry that our library is the culprit of a stack to deep that's why we are very particular with all these tiny details okay then inight examp also allows us to make some cool math you don't need to understand what the math is about but there are some op codes like the bik op code and the branchless uh op codes that allows us to make math faster for example in this lock two method and the advantage of having a fully branchless function that is inline uh that is possible with inline assembly is that when you when the solidity compiler try to optimize it will first check whether a function has any branches if it has branches then the function uh is likely not to be in line uh with the V Pipeline and if you use the Legacy pipeline it will defitely not be in line so um by writing stuff in inline asmp we help the compiler produce more efficient back code by telling the compiler that this function is inlinable so using this trick we can also achieve some other techniques like if you want to compare a short string with another short string traditionally you will use some kind of Ky cut 256 but if you know uh in assembly you can do some kind of black magic that will tell the comper that instead of doing useless memory allocations just emit the optimal op code so all these although it looks like a lot of op codes but in the end after you press compile it it somehow simplify into just a few op codes and this is only possible if the the entire chunk of code is branchless okay so the thing about solid is that it's a very beautiful language you can write all the low level things and users don't have to be concerned about the details so all the nitty-gritty black magic has been extracted away from the users the users need to just care about what are the high level apis and what are the tradeoff of all the different functions so you can write clean and performance readable high level solidity without actually going deep into the inight examply rabbit hole okay so some core goals like norstar Sol lady we want to make sure uh that solity is the best smart contract Language by providing a res set of Highly optimized utilities that fits the solid compounder now and into the future then uh okay so the idea is that people say uh we want to write our language in Ras because it has a Library we want to write in C++ because there's a wider library but in solidity we have this uh exotic math function called Lambert w01 which is only available in Python maybe some math language and solidity you can find it in any other like major languages so that is so ladies go if it's touring complete if it's possible within the touring completeness of evm we will implement it we also want to scale e ethereum to sh app layer optimizations and also make the code beautiful so we also have plans for E uh although I am a bit it's quite a chore but I see the importance of it in because EF C is actually uh more optimal for stuff like sp1 proving so even ually I think quite soon so lady will have a eof it won't be a breaking chain so we have a source directory and then we'll have a EF directory so you can use either one we won't like force you to use either eof or the Legacy we'll give you the option okay so here are some links uh you can visit Sol lady. which is a shortcut to show Sol lady or you can uh visit my GitHub or my ex sometime I post like small solid lessons on my next okay I think that's all for my thought thank you thank you Rector eyes for this talk I guess we have all now a better idea of how to leverage assembly inline assembly in our code um in the meantime we have plenty of time for questions so if you have any make sure to please send them through this QR code um I'll be starting with the one the first one on the leaderboard um did assembly ever bite you in the butt where vanilla solit would have been more safe okay um when I was starting up like maybe two years ago I think the fix the safe transfer leap forgot to clean some upper beats because it was uh I directly pter it from soate but then uh someone spotted that but so these days like I am super paranoid paranoid about unclean in dir upper bits so it becomes like a second second nature so I think recently it should be quite safe all right next one when to use lead and when to use M store okay lead is a way of defining variables in in line assembly uh if like let's say uh somehow you can force the compiler to reorganize a stack to avoid stack too deep then you might have to use M store to use the scratch space for temporary variables but you atos can only use two uh parts of the scratch space like two slots because the other slots are for for other purpose for important stuff um next one why do you prefer solid inline assembly over other low level languages like Huff okay so the thing about I I like HFF but uh the benefit of solidity is that it allows you to recycle your efforts and also it allows you to generate more compact bike code for example in half the inline is really in line but where in solid if you have like 10 use if your function is a giant Chun of bik code and it's used like in 30 different places you might not actually want to inline it every single time next one uh at l2's called C data with call data feedback function I guess from libzip has greater gas versus non-compressed call data but has slightly cheaper gas at L1 is that correct what happens under the hood okay um this depends on your L2 some l2s already uh forward the gas Savings of compressed core data to the users so if you use CD forb back on optimism you might not you will most probably not be able to save any cor data money so if you're Depo on op St just don't use that when using assembly based libraries is there a higher likelihood that it is less compatible with future Sol versions I would say that is actually less likely Hood because for example if you look at transient storage solidly implement it on the assembly level first then later it become like a higher level thing so one thing you have to worry about is that um solidity might change in ways that the high high level Parts interpret the memory slightly differently so uh that you have to keep up with the change lock Vector also has a nice friend a nice hat and a panda on his hat do you want to show everyone yeah I guess that helps you as well and coding um next one I guess uh how so L these features saturated how many more libraries and functions do you plan to add okay I think right now we have mostly saturated uh we have a lot of work to do to port to e like is especially the leap clone is is going to be but the solidity team has actually much much a much more stuff to do compared to me another one About Soul ad the new solid compiler in R impact solidity solid I think this new solidity compiler called solar they try to become like a feature parity with uh the official solidity compounder like for example in C++ you have uh Clen you have GCC I think we might go that route down the road and if you just writing in a high level language you don't need to care whether you use CL or GCC all right that wraps up for our Q&amp;A session uh thank you very much for the questions and give a big round of applause for Vector eyes
