A comprehensive guide on how to audit

Nowadays, protocols become more and more complex and introduce modular patterns in their systems.

Here’s a comprehensive guide on how to audit and understand the different types of contracts within larger project

1. Libraries

Libraries are toolkits that contracts can utilize without inheriting them directly. They're imported into contracts and are instrumental in providing utility functions for:

Safe transfers: Ensuring asset transfers occur without errors.

Hook checks: Validating conditions before or after certain actions.

De/encoding: Handling data in various formats.

Queues/orderbooks: Managing data structures for complex operations.

Math operations: Performing calculations reliably.

And more.

Audit Focus: Ensure libraries are used appropriately and check for misuse or misimplementation of their functions in contracts. Verify that library functions do not introduce vulnerabilities, especially in critical areas like asset transfers and data handling.

2. Abstract Contracts

Abstract contracts serve as the backbone for other contracts. They define a set of functionalities without fully implementing them, allowing derived contracts to implement the details. These are especially common in systems where core functionalities like staking are extended in various forms (e.g., staking1, staking2).

Audit Focus: Understand the base functionalities these abstract contracts define and how they're inherited and utilized by other contracts. Ensure that the derived contracts correctly implement and extend these base functionalities without introducing inconsistencies or security flaws.

3. Core Contracts [1] - Internal/Logic Functions

These contracts are critical as they handle the internal logic and data manipulation of the protocol. They're often not called directly by users but through other external-facing contracts.

Audit Focus: Look for logical bugs and vulnerabilities in data manipulation and internal function implementations. Verify that internal functions are correctly authorized and cannot be misused by external entities.

4. Core Contracts [2] - External Functions

This subset of core contracts deals with interactions with the outside world. They're designed to receive inputs from transactions, validate them, and direct them to the appropriate internal logic functions.

Audit Focus: Stress-test these contracts with various inputs and conditions to uncover potential vulnerabilities. Pay special attention to input validations, authorization checks, and how different condition paths are handled. Think creatively about possible attack vectors that could exploit the interaction between external and internal functions.

5. Auxiliary Contracts

Auxiliary contracts support the main protocol without being a core part of it. Examples include tokens, treasury management, vesting contracts, and more. These contracts often have a more isolated functionality compared to the intertwined nature of core components.

Audit Focus: Because they're less interconnected, you can audit these contracts more linearly. Review each contract's code for vulnerabilities, ensuring that its implementation aligns with the intended functionality and security standards.