The comprehensive EVM deep dive for Solidity developers. Made by @0xMacroSecurity

Joined January 2023
⚙️ LearnEVM.com retweeted
All EVM opcodes in one diagram by @LearnEVM
10
42
332
13,440
⚙️ LearnEVM.com retweeted
Building on the Solana virtual machine (SVM) is very different than building on the EVM. Differences include: - Data cannot be encapsulated - External call depth capped at 4 - All account reads and writes must be known ahead of time and much more (tighter transaction limits, built-in upgradability, program-derived accounts and their ability to be signers, and so on). If you're looking to build on Solana and could use an expert opinion to accelerate your development, contact us via telegram, or via inquiry form on our website. Up to 50% of your pre-audit security reviews can be applied to a future audit (limited time only). Stay secure out there 👊 - Macro Security team
3
6
1
36
9,501
⚙️ LearnEVM.com retweeted
The Solidity Developer Survey 2024 has gotten 500+ responses so far. If you're yet to take the survey, you've got one last week to let us know... ✨ how you are using Solidity. 🆕 which recent changes impact(ed) you the most. 🔮 which features you anticipate the most. It takes ~10min to contribute to the future of Solidity. 🔗cryptpad.fr/form/#/2/form/vi…
1
19
4
47
11,605
⚙️ LearnEVM.com retweeted
I have a monopoly on arranging EVM opcodes beautifully and optimally. And it’s free and open source. Milady.
24
9
3
242
11,927
⚙️ LearnEVM.com retweeted
The simplicity of the EVM is beautiful.
8
3
47
2,632
you can use bytecode as storage
you can use bytecode as storage.
1
5
700
⚙️ LearnEVM.com retweeted
trim is so cool 😍 there are a couple simple open issues if anyone wants to take a crack at them, too
trim just got its first contributor PR merged! open source is so sick thanks & credit to @emo_eth ! 🔥🔥
1
4
525
Arbitrum got 6 modified OPCODEs Optimism got 7 modified OPCODEs + 1 added precompile ZkSync got 14 modified OPCODEs + 8 deleted precompile They are all EVM but not EVM-equivalent. Making them into native rollups would be a fun time.
19
11
7
215
41,573
⚙️ LearnEVM.com retweeted
Every evm opcode ever in a single diagram 👇
3
11
4
72
6,135
⚙️ LearnEVM.com retweeted
Behold: The router contract that can be generated to handle over 4000 function selectors! 🤩 And not an ounce of Solidity was used. No sir, we're diving into EVM opcodes with this one! 🔥🔥 If you want to improve your low-level knowledge of how the EVM works, ima bout to give a break down on this awesome contract and how it works at a very high level 🤓 Let's dig in 👇👇👇 The first two lines is the deploy code 🚀 When you deploy a contract to an Ethereum chain, you don't just upload the contract body – you also upload the deployment bytecode. The EVM runs your deployment code and then throws it away (this is why you don't have access to constructors in Solidity btw). Your deployment code can do whatever you want, but it MUST AT LEAST RETURN the body of your contract – in other words, the runtime code of your contract. This is what gets persisted onchain. The (init-runtime-code) macro above simply generates a standard 15 bytes of opcodes that does this returning. It involves copying bytecode into memory, and then returning it. Next up we have some definitions: `def` is a macro defining a custom macro. Macros are nifty Trim features that convert one text to another. Makes for some really clean code. Here we're defining what we call "registers". Most VMs have registers, but the EVM doesn't. Not a problem; we simply decide to use the first few words of memory to put some working, named data. This technique makes our code WAY simpler, as we don't have to manipulate and memorize the state of the stack, instead we can just MSTORE and MLOAD. Next up, some init code. Check the faded out code right under \$input. This is a very standard technique of loading the 4 byte function selector into memory. This is the function that the caller wants to call, and the function we want to search for in our binary search. If you don't know what function selectors are, head over to @LearnEVM and fix yourself up! Now for the main body: This is the heart of the contract body. It uses a binary search to find the function selector within the hardcoded function data we have at the bottom of the contract. The star of this show is CODECOPY, which allows you to load bytes of your own contract bytecode into memory. Extremely cool feature! So yeah, if the search finds a matching selector, then it loads the correct module and delegates to it. Otherwise, it reverts. Since Twitter only allows 4 images on a post, let's skip over the DELEGATECALL code – something quite standard that you can find info on elsewhere – and jump into the hardcoded function data: This is the beauty to behold! When you write raw bytes like this, Trim leaves it exactly as you wrote it, literal verbatim at that position in your contract body. The way we've set things up, the contract's execution never actually gets to this point (it returns or reverts before it). In other words, this is literal raw data sitting in our contract bytecode! And our search code – using CODECOPY – treats it like a database 😍 As you can probably imagine at this point, adding functions and modules to this contract has a very small cost. All you need to do is: - Add 4 bytes for the selector - Add 1 byte for the module index - Add 20 bytes for the module address – ONLY if it's not already present! 🔥🔥🔥 And that's it! This little guy can support up to 256 modules and 4000 function selectors. Tweaked a bit, it could hold more modules and fewer selectors, if that's what you really need. Either way, we've got a beautiful piece of code, written in a beautiful little language for the EVM (if I don't say so myself 🤓) That's all for now, folks! ---- P. S. You may have noticed that this contract does not have Diamond Loupe functions that are required by the EIP-2535 spec. This is true. Although this router generator is already useful on its own, adding these functions is what I plan to do next. In theory, it shouldn't add much code to the body of the contract... (in fact, if you wanted to, you could delegate call to another hardcoded contract with the diamond loupe functions. Since these functions are only really used offchain, it would be an appealing option. But a project requirement of @usecannon was that these contracts should be self-contained, so that's the context we're working with) ...and it definitely won't add any gas costs to the runtime – assuming the selector you're calling is one that the contract expects. Check out @LearnEVM and @0xMacroSecurity for deeper dives into this fun micro world of EVM opcodes. Until next time! xitter.cf/0xgib/status/187775866…
I'm extremely excited to introduce Trim – a newly updated, tiny language for writing highly optimized smart contracts for the EVM! 🤓 But why Trim? Let's just say there's a... "solidity-shaped" reason behind it 🧐 It all started with a curious engagement with @usecannon...
6
8
3
38
5,016
⚙️ LearnEVM.com retweeted
I'm extremely excited to introduce Trim – a newly updated, tiny language for writing highly optimized smart contracts for the EVM! 🤓 But why Trim? Let's just say there's a... "solidity-shaped" reason behind it 🧐 It all started with a curious engagement with @usecannon...
1
11
2
21
1,663
⚙️ LearnEVM.com retweeted
EVM opcodes are so back new thing coming soon 👀
1
6
171
⚙️ LearnEVM.com retweeted
3 years ago we raised $6.3m from @1kxnetwork, @coinbase, @kain, @richardchen39, @delitzer, @shl, @6thManVentures, @FurqanR, and many (138) more for @0xMacroSecurity this year we got it profitable, and concluded that it was unlikely to offer a venture-scale return so, we gave back almost half AND let investors keep their full ownership as founders we get many shots on goal, but only one reputation - I think doing this earned us good will but time will tell much love & thanks to everyone who took a bet on us! special shoutout to the earliest angels @JuliaLipton @lisacuesta & @ViktorBunin, @patrickxrivera, @lindaxie who started the snowball of intros to the rest, won't ever forget <3 p.s. 2024 profit distributions are on deck! p.p.s. the team is rockin' -- if you need EVM or Solana audits, hmu
33
11
7
322
59,050
⚙️ LearnEVM.com retweeted
If you are curios about EVM @LearnEVM is a hidden gem. learnevm.com/chapters/intro/…
3
13
604
Was writing a PoC today and ran into a 'stack too deep' error. Fortunately, I learnt about the stack at @LearnEVM which helped me to know exactly why I was getting that error message. I then refactored the function by reducing the number of cached variables. QED #web3security
1
3
116
⚙️ LearnEVM.com retweeted
In the EVM, accessing a distant memory slot incurs costs for all preceding slots. For example, if the last used slot is 0x80 and you access 0xff, every slot in between will be initialized, leading to additional gas costs I remembered this vaguly but had difficulty finding clear documentation to confirm it Found the reference here: learnevm.com/chapters/evm/me… Thanks, @LearnEVM
1
4
38
1,936
⚙️ LearnEVM.com retweeted
If there’s one thing you should read today, it’s this: How EVM Function Calls Work - How Off-Chain Queries Work - How EOA Contract Calls Work - How Contract-to-Contract Calls Work If you don’t understand these in depth yet, you will now. learnevm.com/chapters/fn/int…
8
42
240
10,502
⚙️ LearnEVM.com retweeted
Don't we already have account abstraction? Why does EIP-7702 exist? True, we do have EIP-4337... But we don't have 𝐢𝐝𝐞𝐚𝐥 𝐀𝐀 – yet 🧐 EIP-7702 helps Ethereum solve a piece of this puzzle by giving EOAs the ability to 𝐞𝐱𝐞𝐜𝐮𝐭𝐞 𝐜𝐨𝐝𝐞.
1
4
9
1,107
⚙️ LearnEVM.com retweeted
🎉 Breaking News: Orange Teams Up with @0xMacroSecurity! 🎉 Orange is stoked to announce our latest partnership with 0xMacro, the rockstars of smart contract audits, working with projects like @MakerDAO and @fraxfinance
592
38
1
77
4,986