1/5
--- Now that we have identified the need to scrutinize the assembly code, let's dive into its complexities. Assembly language, notorious for its challenging readability, demands a meticulous approach to decode each operation. #### Leveraging Testing Frameworks Given the density of assembly language, testing frameworks are indispensable. They streamline the process by automating the evaluation of code line by line, a task that is otherwise time-consuming and prone to error. #### The Role of Formal Verification and Fuzzing While tools like fuzzing and formal verification provide high assurance of code correctness, manual review remains crucial. These tools help in validating the mod function, which, as specified in the documentation, performs the operation `x * y / wad`, rounding down the result. #### Delving into Test Functions Exploring the test suite reveals specific functions `mod` and `mod fuzz`. However, initial examples in these tests do not showcase scenarios involving rounding, an aspect critical to understanding the mod function's behavior. This highlights the utility of more comprehensive fuzz tests which simulate varied and complex inputs to ensure robustness. #### Detailed Breakdown of a Fuzz Test In a detailed fuzz test, the operation `x * y` is equated to `x * y / 1E18`, emphasizing efficiency in gas usage. An unchecked conditional within this test ensures the function behaves correctly under maximum constraints for `uint256`. #### Step-by-Step Explanation of Key Operations 1. **Bitwise Operations**: Using the `not` operation from the Yule documentation, we transform values at the binary level. For instance, `not X` inverts every bit of `X`, turning a binary `0001` into `1110`. 2. **Division and Guard Conditions**: The code handles divisions by zero, a typical problematic operation, by returning zero instead of throwing an error, which is different from many programming environments where such an operation would result in an error. 3. **Comparison for Reversion**: The assembly code checks if after a division, the result is greater than or equal to `X`. If true, it suggests a potential overflow, prompting a reversion to avoid computational errors. 4. **Handling Special Cases**: The additional multiplication by `Y` in the condition addresses edge cases where `Y` equals zero, which can skew the results of division-based checks. #### Practical Testing of Assembly Code To solidify understanding, the script includes running code snippets directly in tools like Chisel, allowing us to visualize and verify each step's outcome. This hands-on approach helps clarify the underlying mechanics of the operations described.
A deep dive into the muWad function in Solidity - The lesson examines the code used in a muWad function within a Solidity contract. Specifically, it analyzes the assembly code in depth, breaking down each line and the various opcodes used, with the use of a helpful tool called Chisel.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Assembly
Writing smart contracts using Huff and Yul
Ethereum Virtual Machine OPCodes
Formal verification testing
Smart contract invariant testing
Halmos, Certora, Kontrol
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Josselin Feist
Head of Blockchain at Trail of Bits
Last updated on January 17, 2025
Solidity Developer
Assembly and Formal VerificationDuration: 30min
Duration: 4h 38min
Duration: 3h 57min
Duration: 1h 56min
Course Overview
About the course
Assembly
Writing smart contracts using Huff and Yul
Ethereum Virtual Machine OPCodes
Formal verification testing
Smart contract invariant testing
Halmos, Certora, Kontrol
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Josselin Feist
Head of Blockchain at Trail of Bits
Last updated on January 17, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar