EVM Opcodes & Solidity Gas Mastery Tutorial | Cyfrin Updraft Assembly & Formal Verification Excerpt

2024 ж. 17 Мам.
8 922 Рет қаралды

This is an excerpt from the upcoming Assembly, Opcodes, and Formal Verification course. We go over the following in this video:
- How to write a smart contract in Opcodes (with Huff!)
- How to disassemble a smart contract
- How to read the bytecode of a smart contact (without it even being verified on Etherscan!)
- How to write Yul/Inline assembly in Solidity
- How to truly become a gas optimization professional using low-level programming languages
- How the Opcodes in the EVM work
GitHub repo associated with this video: github.com/Cyfrin/1-horse-sto...
GitHub Repo for the coming course: github.com/Cyfrin/assembly-ev...
Security Course on Updraft: updraft.cyfrin.io/courses/sec...
Register for Cyfrin Updraft: updraft.cyfrin.io/
⏰ Timestamps ⏰
0:00:00 | Introduction
0:02:57 | Horse Store - Huff & Opcodes
2:07:39 | Breaking down solidity compiled opcodes
3:24:47 | Yul
3:48:40 | HorseStoreV2 - Huff
4:28:30 | Gas Comparisons & Summary
😸😸Follow Patrick!😸😸
Cyfrin: www.cyfrin.io/
KZhead: www.youtube.com/@PatrickAlpha...
Twitter: / patrickalphac
Medium: / patrickalphac
TikTok: / patrickalphac
🛡️ More Cyfrin
CodeHawks: codehawks.com/
Solodit: solodit.xyz/
Updraft: updraft.cyfrin.io/
All thoughts and opinions are my own.

Пікірлер
  • The full course gonna be insane (This will be the new part 2 of the security course) Also I say “binary” instead of “opcodes” like 5 times - sorry

    @PatrickAlphaC@PatrickAlphaC2 ай бұрын
    • I'll be there no matter what!

      @victormalomo8839@victormalomo88392 ай бұрын
    • Waooo it is going to be the absolut mega course ever 💣💥💥💯 🥳🥳🥳

      @fursan7525@fursan75252 ай бұрын
  • Bro... I don't know what to say except... you're a treasure for Humanity. Seriously. Given the importance that crypto development is gonna reach with all the A.I. b*lls**t, the fact that you are doing so much to help people write reliable and efficient code... you already deserve AT LEAST some mentions in future history books. Thank you ❤

    @an-eios7125@an-eios71252 ай бұрын
  • I legit spent the last 48 hours trying to figure this exact thing!

    @clarencejones4717@clarencejones47172 ай бұрын
    • I’m here for you!

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
    • HOLD ME @@PatrickAlphaC

      @lawniczakjohn@lawniczakjohn2 ай бұрын
  • I was a EVM muggle before this course, thank you so much.

    @skim3708@skim3708Ай бұрын
  • Learning and becoming better each day in Web3 Security by Patrick Collins sir 🔥🔥

    @mayanksharma4965@mayanksharma49652 ай бұрын
  • I'm a simple developer. I see new Patrick upload I click and I like before watching💯

    @olaade730@olaade7302 ай бұрын
  • The fact all of this is for free in this economy says a lot.. thanks Patrick

    @highpoint4925@highpoint49252 ай бұрын
  • Bro puts out more content than Disney+ 🤯

    2 ай бұрын
  • Patrick strikes again!🔥

    @valentineorga@valentineorga2 ай бұрын
  • Ohhh my gosh...was in the process of replicating the hardhat FundMe project in huff and here it is...the goat has launched it....This is a boost....BASED!

    @carlvk1893@carlvk18932 ай бұрын
  • thank you for providing quality content

    @rikanghuang7714@rikanghuang7714Ай бұрын
  • Bro is a legit legend !

    @beemdude2@beemdude22 ай бұрын
  • I can't wait to see how long the full course is going to be.... hopfully challenging as the motivation is very hiiiigh now 😎

    @fursan7525@fursan75252 ай бұрын
  • I love you Patrick ❤ seriously you are the best

    @riotech3839@riotech38392 ай бұрын
  • woohooooo! finally we are getting tutorial of my favorite in solidity the inline assembly !!

    @jayendrabhagat3607@jayendrabhagat36072 ай бұрын
  • Completing this video could be exhausting because of the low-level stuff. But trust me, it's worth watching this video more than 10 times. After struggling with these vague opcodes for two years, I now have a better perspective of what the hell is happening behind the scenes.

    @Parsaaminii@ParsaaminiiАй бұрын
  • Thanks for your service to humanity

    @ibrahimshehuibrahim918@ibrahimshehuibrahim9182 ай бұрын
  • He is back! with another banger!!!!!!!!!!

    @positiveguy8371@positiveguy83712 ай бұрын
  • Thank you so so much Patrick!! 👍👍🙏🤗

    @uservstabicudiu2023@uservstabicudiu20232 ай бұрын
  • Another incredible course by the one and only Web3 guru himself!

    @lawniczakjohn@lawniczakjohn2 ай бұрын
  • 172nd...Thanks Patrick. You are the best !!!

    @jopadjr@jopadjr2 ай бұрын
  • back with a bang

    @vijayguru7648@vijayguru76482 ай бұрын
  • My bro is one🔥

    @mehrdad1068@mehrdad10682 ай бұрын
  • Omg this is soooo cool patrick youre the best!!! 😍

    @q44444q@q44444q2 ай бұрын
    • Hell yes it is

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • WE OPTIMIZING FOR GAS WITH THIS ONE🗣🗣🔥🔥🔥🔥

    @shivdhandesh2002@shivdhandesh20022 ай бұрын
    • You damn right

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • This is why we call you legend

    @fakemonkgin@fakemonkgin2 ай бұрын
    • Anytime fren

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • this is amazing can you do something on account abstraction

    @ralphwealth163@ralphwealth1632 ай бұрын
  • What the hell is it, crazy super video, lets learn

    @belajarblockxhain@belajarblockxhain2 ай бұрын
  • LFG ! legend Now we just need to get a collab with something like GOTO or NDC Conferences.. Oh and BlackHat

    @goldnutter412@goldnutter4122 ай бұрын
  • we need more inline assembly!!!

    @rashmor1@rashmor12 ай бұрын
    • MOAR

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • Wow

    @vishwa7dcap761@vishwa7dcap7612 ай бұрын
  • I forgot some hex now I dusted it off for people like me, remember every hex value weighs 4 bits because every hexadecimal value can be represented in 4 bits that's why remove the 2 on 0x0102 because it weighs 4 bits try to put another hex value like A you'll see always returns 10

    @karm4tips@karm4tips2 ай бұрын
  • Well done with this excerpt of the course @PatricAlphaC I really enjoyed it. Quick question how can we identify the value type of each of the values used within the opcodes? For instance how do we know the number of horses updated is in fact a uint256 ? And also if there are multiple inputs to a function (address and amount) how do we identify these?

    @danielbotha8994@danielbotha89942 ай бұрын
    • In bytecode, you don’t! When someone sends a “uint256” it’s just the hex of the uint256. So as far as the opcodes are concerned, it takes a bool, uint256, bytes32 whatever! This is where a compiler helps, since the compiler will not compile if types don’t match. But the opcodes don’t care, they just look at what the raw call data is.

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
    • If there are multiple parameters, you’d just see a second bytes32 object in the call data. Your call data would look like this: First 4 bytes: function selector Next 32 bytes: parameter 1 Next 32 bytes: parameter 2 For a total of 4+32+32 =68 bytes of call data

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
    • would building logic to convert each input into a type (uint256, bool, bytes32, etc.) and then matching that to a matrix (as a first step) to identify types that make sense (example perform a checksum test on a value to confirm if it is a checksum address) allow for the initial automation of assigning types to these values? @@PatrickAlphaC

      @danielbotha8994@danielbotha89942 ай бұрын
    • @@danielbotha8994 you could, but honestly the extra gas wouldn’t be worth it IMO

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • hey patrick,i was see your foundry course and still watching security course, actually i have a question. I am almost familiar with solidity and smart contracts(foundry framework) and the same with security issues but now I am confused, what exactly should I do? for next step to become a security researcher? to find bug's? Contest? Reading writeups? or what?

    @Itsmohammadh@Itsmohammadh2 ай бұрын
    • If you watch the security course, we tell you your next step 100% is CodeHawks. Go compete!

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • Amazing course! But still, I didn't get one thing. When I've compiled huff file with CONSTRUCTOR, the arguments has been added in the end of the runtime bytecode. Is it some default behavior?

    @user-hk4tv7ug7k@user-hk4tv7ug7k2 ай бұрын
    • Correct! This is often how arguments are added to EVM code! Solidity does the same thing as huff. Yes this is default.

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • 17 ❤❤❤❤❤❤❤❤❤

    @justkaz7104@justkaz71042 ай бұрын
  • Whether the program counter and jump destination are same Patrick

    @codeWithBala@codeWithBala2 ай бұрын
    • Sort of. The program counter must match the jump dest - huff does that for us

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • one item to be added to must-do list, c'mon Patrick, i haven't finished foundry course yet 😂

    @freetimegames8585@freetimegames85852 ай бұрын
    • Ahah - keep up your pace, and you’ll catch up soon!

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
    • Haha. I'm on the same page too. Yet to finish foundry and advanced foundry. Patrick's a blockchain wizard. sweet jesus..

      @toppojaiwant@toppojaiwant2 ай бұрын
    • @@toppojaiwant the course is like a drug, i'm so addicted lol

      @freetimegames8585@freetimegames85852 ай бұрын
  • In all bug bounty gas optimization is informational,so no bounty 😢

    @axelvirtus2514@axelvirtus25142 ай бұрын
    • But if you’re a dev, gas bad

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • LFG

    @dapponics@dapponics2 ай бұрын
  • Your Yul code is super weird. Why divide by 2^224? Bitshiting by 224 is cleaner in my opinion and produces less bytecode.

    @navibongo9354@navibongo93542 ай бұрын
    • Which function?

      @PatrickAlphaC@PatrickAlphaCАй бұрын
    • So its essentially the same thing but with less bytecode at the end.@@PatrickAlphaC In your "selector" function you divide the word by 2^224, which leaves you with the selector. But in your version of the code, you hardcode 2^224. Instead you coud just hardcode 224 to bitshift. So like this, the code should compile with less bytecode: s := shr(0xe0, calldataload(0)) This works because x >> y = x/2^y Also on that note, you can calculate 2^224 in wolframAlpha or wherever and cast it to hex, to get your magic value to confirm. I used docker to run solc 8.20. Lastly to compile yul must add the --strict-assembly /path/... flag. Compare the final bytecode.

      @navibongo9354@navibongo9354Ай бұрын
    • @@navibongo9354 Ah took me a second to recognize what you were talking about, sorry! Yeah, in retrospect, I should have done it more similar to the way I did the huff, which is what most compilers do, but a lot of the yul documentation did it like that, so I wanted to more closely resemble the docs. But yeah, good point!

      @PatrickAlphaC@PatrickAlphaCАй бұрын
  • pls add subtitles

    @sigmamale7914@sigmamale79142 ай бұрын
    • They take a few days to populate

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • wtf, he has beard now

    @David-rz4vc@David-rz4vc2 ай бұрын
    • Sometimes lol

      @PatrickAlphaC@PatrickAlphaC2 ай бұрын
  • 😅 *promosm*

    @kaitli5279@kaitli5279Ай бұрын
  • The 🐐 strikes once again! Thanks ser! 🫡

    @evmlionel@evmlionel2 ай бұрын
  • aah shit here we go again🚀🫡

    @moossajaseempk5452@moossajaseempk54522 ай бұрын
KZhead