Smart Contract Auditing

Introduction to Web3 Auditing

Choices and Considerations

Preparation and Initialization

  • Audit Prerequisites : Essential elements and documentation required before starting an audit.
  • Audit Checklist : A comprehensive list to prepare projects for security audits.
  • Initial Code Walkthrough : The importance of a preliminary code review before the audit begins.
  • Communication Channels : Messaging Channels and regular meetings for updates via Video Conference are normal, there may be barriers due to languages and time zones. Ongoing communication is key to a successful audit.

Audit Reports

The Basics

Smart Contract Auditing Tools

  • Foundry Forge : A Rust based Development Framework that includes many useful tools for understanding and testing smart contract including a stateless and stateful (Invariant) fuzzer
  • Mythril : A security analysis tool for Ethereum smart contracts. It uses concolic analysis (dynamic symbolic execution), SMT Solving taint analysis, and control flow checking to detect a variety of security vulnerabilities.
  • Slither : A static analysis framework that can detect common issues such as re-entrancy, suicidal contracts, and incorrect visibility.
  • Echidna : A property-based fuzzer that can be used to find bugs in smart contracts.
  • Certora : Formal verification tool for smart contracts.
  • MythX : A SAAS security analysis platform for Ethereum smart contracts.

Smart Contract Testing

  • Unit Testing : Unit tests for auditors individual components of your contract function as expected.
  • Integration Testing : Testing multiple components of a contract together to ensure they work correctly in unison.
  • Creating POCs : Creating Proof of Concepts to demonstrate the vulnerabilities found in the audit.

Fuzzing

Formal Verification

Mastering the EVM and Low-Level Programming

Identifying Vulnerabilities

  • Understanding Business Logic : Understanding the business logic and the intended interactions within and between contracts is paramount.
  • Technical Review Process : The process of identifying vulnerabilities in smart contracts.
  • Developing Heuristics : Develop and utilize heuristics for auditing smart contracts.
  • Common Smart Contract Vulnerabilities
  • Timestamp Dependence : Smart contracts that use the block.timestamp variable may have this vulnerability.
  • Gas Limit and Loops : Loops that run for an indeterminate number of iterations can hit the gas limit, causing transactions to fail.
  • Denial of Service (DOS) Attacks : Exploiting design flaws or gas-related vulnerabilities to make contracts unusable.
  • Re-entrancy Attacks : This occurs when an external contract hijacks the control flow, and makes recursive calls to the original contract.
  • Delegatecall : delegatecall is a low-level function similar to a dynamic library call in other languages. If not used carefully, it can lead to serious vulnerabilities.
  • Math-Related Vulnerabilities : Integer overflow, underflow, and rounding errors are common in smart contracts due to the lack of native floating-point support in Solidity.
  • Unchecked Return Values : Failing to check the return values of low-level calls such as send, call, and delegatecall can lead to vulnerabilities where contract execution continues even after a failed external call.

Upgradeability Patterns and Vulnerabilities

MEV and Front-Running

Cryptography and Signatures

DeFi Security

Case Studies: Lessons From Major Exploits

Continuing Education and Resources

  • Auditing Courses : Free and paid courses, bootcamps, and cohort programs; suggested learning path.
  • Certifications : An honest survey of the certification landscape — which credentials carry weight, which are largely commercial.
  • Online Channels, Communities, and Forums : Discords, X / Farcaster accounts, newsletters, podcasts, and CTF communities.
  • More Resources : Solodit, Rekt, SWC, EIPs, books, playgrounds, tooling repositories, on-chain forensics, and contract libraries.

Solidity-Specific Attack Vector Catalog

  • Access Control Pitfalls : tx.origin, default visibility, unprotected ether withdrawal and SELFDESTRUCT, missed/incorrect modifiers, overpowered roles, unsafe ownership transfer.
  • Reentrancy Variants : Cross-function, cross-contract, and read-only reentrancy; defenses beyond nonReentrant.
  • Storage and Data Pitfalls : Unencrypted private data on-chain, arbitrary storage writes, improper array deletion.
  • Encoding and Low-Level Pitfalls : Unsafe typecast, dirty higher-order bits, fixed-point arithmetic, abi.encodePacked hash collisions, function selector abuse, short address, hardcoded gas, insufficient input validation.
  • Randomness and Entropy : Why on-chain "randomness" sources fail; VRF, commit-reveal, threshold randomness, and integration pitfalls.
  • Source-Text and Compiler Pitfalls : Bidi tricks (U+202E), floating pragma, outdated compiler, deprecated functions, variable shadowing, complex modifiers, incorrect interface.
  • Historic Attacks : Constructor-name bug, call-depth attack, ABI Encoder v2 bug, Constantinople reentrancy — and their modern echoes.