Skip to main content
Create your own

Token Security Review: Checklist Approach

Welcome to the final lesson of our course! Over the past several weeks, you have progressed from setting up a development environment to designing, building, and testing two sophisticated token contracts: a fiat-backed stablecoin and a security token. You've grappled with advanced Solidity patterns, integrated with standard libraries like OpenZeppelin, and explored key ecosystem tools. In our last lesson, we examined how to get data off-chain for analytics with The Graph. Today, we bring our focus back on-chain for the most critical step before any real-world deployment: a comprehensive security review.

Your background in business intelligence and consulting for asset management software has given you a deep appreciation for process, quality assurance, and risk mitigation. Just as you wouldn't release a financial reporting tool without rigorous validation, a smart contract, with its immutable nature and direct control over assets, demands an even higher level of scrutiny.

This lesson will guide you through performing a final security review of our token contracts. We will adopt a systematic, checklist-based approach that mirrors the practices of professional auditors. You will learn to shift your mindset from a builder to a breaker, consolidating all the security principles we've discussed into a final, structured quality gate.

The Lifecycle of Smart Contract Security

Before we dive into the "how," it's important to understand where a final review fits within the broader development process. Security is not a single activity but a multi-layered practice that begins at the ideation stage and continues even after deployment.

This timeline from Consensys Diligence illustrates that security is a continuous process. An audit is a critical, final checkpoint before mainnet release, but it builds upon earlier efforts like automated testing and static analysis.

As you can see, a formal audit is the culmination of a security-conscious development lifecycle. Our goal in this lesson is to simulate the mindset and process of this final review.

1. The Audit Process: A Systematic Framework

A professional security review is not an unstructured code reading session. It's a methodical process with distinct phases, much like a well-managed consulting engagement. Understanding this framework is the first step.

The video below, from professional auditor Owen Thurm, provides an excellent overview of a repeatable and organized auditing system. It outlines the entire process, from preparation to final reporting, and emphasizes the importance of a structured, focused mindset.

Complete Smart Contract Auditing System

This video offers a practitioner's perspective on the entire audit process, emphasizing a systematic approach that will be familiar from your work in structured business environments.

Please watch the following segments: Introduction: The speaker outlines his systematic approach to finding as many vulnerabilities as possible. Preparation: Notice the emphasis on time allocation, research, collaboration, and tooling—all crucial steps before any technical analysis begins. Laying the Groundwork: Pay close attention to his method of starting with a high-level walkthrough to understand the "jobs to be done" by the system, and using "audit tags" (comments in the code) to mark points of interest without getting sidetracked. Wrapping Up: Note the importance of creating a clear report with proofs-of-concept (POCs) and, crucially, the post-audit validation of fixes.

The key takeaway is that an effective review requires a shift in thinking. Instead of verifying that the code works as intended (convergent thinking), your job is to find ways to make it fail (divergent thinking). You must actively try to break the system's assumptions and invariants.

2. Automated Analysis: The First Line of Defense

The review process typically begins with automated tools that scan the codebase for known vulnerability patterns. These tools are fast and provide a great baseline, catching low-hanging fruit and freeing up mental energy for more complex, context-specific issues.

The most widely used tool for this is Slither, a static analysis framework from Trail of Bits. It analyzes the source code without executing it, identifying common bugs, coding anti-patterns, and violations of best practices.

Let's see it in action with Patrick Collins.

How to Audit a Smart Contract | Can you find the Solidity Security Vulnerabilities?

This video provides a clear, hands-on demonstration of installing and running Slither on a set of contracts containing various vulnerabilities.

Watch the segment from where he introduces and runs Slither. Observe how it automatically flags high-impact issues like uninitialized contracts and reentrancy, while also providing lower-impact suggestions for gas optimization and code clarity. This automated pass is an essential first step in any audit.

While Slither is powerful, it cannot understand your contract's specific business logic or find novel attack vectors. It is a necessary but not sufficient step. The real work happens in the manual review.

3. Manual Review: The Checklist-Driven Approach

This is the heart of a security review, where your understanding of the system's goals is combined with an adversarial mindset. To ensure a thorough and systematic manual review, auditors rely on checklists that cover a wide range of potential issues.

We will use a comprehensive, community-maintained checklist as our guide. This will provide the structure for us to methodically examine our Security Token and Stablecoin contracts.

tamjid0x01/SmartContracts-audit-checklist

This GitHub repository is an excellent collection of items to check when auditing Solidity contracts. Our goal is not to memorize every item, but to use its structure to guide our thinking and ensure we don't miss entire categories of risk.

Please open the README.md file in the repository. First, scan the General Review Approach section to get a feel for the high-level best practices. Many of these, like using require, the checks-effects-interactions pattern, and having test coverage, are principles we've followed throughout the course. Next, familiarize yourself with the structure of the document, particularly these sections: Variables (prefixed with V) Functions (prefixed with F) Code (prefixed with C) DeFi (prefixed with D) We'll now use this structure to perform a targeted review of the SecurityToken.sol contract we built in Module 9.

Applying the Checklist: A Simulated Review

Let's walk through a few checklist categories and apply them to our SecurityToken.sol contract.

1. Function-Level Checks (F section):

  • F9: Are the correct modifiers applied?
    • Let's check our administrative functions. depositDividends should be restricted. In our implementation, we used onlyRole(DEPOSITOR_ROLE). This is correct.
    • freezeAccount and forcedTransfer are highly sensitive. We restricted them with onlyRole(ADMIN_ROLE). This is also correct. A key review question is: who holds this admin role? This leads to discussions about secure key management, like using a multisig wallet.
  • F6: Is the checks-effects-interactions pattern followed?
    • The withdrawDividends function is the classic example. Our implementation first checks if the user has a withdrawable balance, then effects the change by setting their dividend balance to zero, and only then interacts by transferring the funds. This correctly mitigates reentrancy. We even added ReentrancyGuard as a second layer of defense.

2. DeFi-Specific Checks (D section):

This section from the checklist is particularly relevant to your goal of building for tokenized money.

  • D1: Check your assumptions about what other contracts do and return.
    • Our SecurityToken.sol interacts with an external allowlist contract via an interface. We assume this contract will correctly return true or false. What if it reverts? Our _beforeTokenTransfer hook doesn't explicitly handle a revert from IAllowlist(allowlist).isAllowlisted(). A robust implementation might wrap this external call in a try/catch block, although in this case, a revert is an acceptable way to block the transfer. The key is to have consciously considered the possibility.
  • D8: Watch out for fee-on-transfer tokens.
    • This is a fantastic, subtle point. Our depositDividends function accepts an ERC-20 token as a dividend. It calculates owed dividends based on the amount passed to the function. However, if the dividendToken is a fee-on-transfer token, the contract might receive amount - fee, while its internal accounting is based on amount. This would lead to a shortfall, where the contract owes more in dividends than it actually holds.
    • This highlights the importance of understanding the entire ecosystem your contract operates in. The fix would be to measure the contract's balance of the dividend token before and after the transfer to determine the actual amount received.

3. Access Control Checks:

Beyond the GitHub checklist, let's use the lens from the rwa.io article, which is tailored to tokenization.

Tokenization Smart Contract Audit: Checklist

This article provides an excellent checklist specifically for tokenization projects. Let's focus on its points regarding issuance and access control, which are core to our contracts.

Read the section "Security Measures for Token Issuance and Management." Pay close attention to the checklists under "Secure Token Minting and Burning Protocols" and "Access Control and Permissions Auditing." We can apply these questions directly to our Stablecoin.sol contract.

Applying this:

  • Is minting restricted? Yes, in our Stablecoin.sol, the mint function is protected by onlyRole(MINTER_ROLE).
  • Is the admin role overly powerful? Our security token's ADMIN_ROLE can freeze accounts and force transfers. This is a significant concentration of power, necessary for compliance but also a major risk. A formal audit report would highlight this centralization as a trust and security trade-off.

The final output of such a review is a report that categorizes findings by severity, enabling the development team to prioritize fixes.

An example of an audit report from OpenZeppelin. Findings are categorized as Critical, High, Medium, or Low, providing a clear action plan for remediation.

Conclusion and Your Path Forward

This lesson marks the end of our course, but it's the beginning of your journey as a security-conscious blockchain developer. We've seen that a final security review is a non-negotiable, systematic process that combines automated scanning with deep, manual, checklist-driven analysis. It requires adopting an adversarial mindset to challenge every assumption made during development.

Key Takeaways:

  • Security is a Process: A final review is the capstone of a security-first development lifecycle.
  • Systematic Approach: A proper review follows a structured process of preparation, analysis, and remediation.
  • Tools Augment, Not Replace: Automated tools like Slither are essential for catching common bugs, but they cannot replace the nuanced understanding of a manual review.
  • Adopt an Adversarial Mindset: The goal is to think like an attacker and actively try to break the contract's invariants and business logic.
  • Checklists Provide Structure: Using a comprehensive checklist ensures all major risk categories are considered, from function-level bugs to ecosystem-wide assumptions.

Congratulations on completing this course! You have successfully bridged the gap from a theoretical understanding of blockchain to the practical ability to build and secure smart contracts for tokenized money.

Your path forward is one of continuous learning. To deepen your expertise, I highly recommend you:

  1. Study Real-World Audits: Read the public audit reports from top firms like OpenZeppelin, Trail of Bits, and Consensys Diligence. This is akin to studying business case files to understand real-world successes and failures.
  2. Practice Your Skills: Hone your adversarial thinking by playing security "wargames" like Ethernaut and Damn Vulnerable DeFi. These are hands-on challenges where you must find and exploit vulnerabilities in smart contracts.
  3. Explore Secure Administration: Deepen your understanding of how to securely manage administrative roles by investigating multisignature wallets like Gnosis Safe, the industry standard for managing high-value contracts.
  4. Build! The best way to learn is by doing. Take the concepts from this course and apply them to a personal project. Design a new type of tokenized asset that interests you and build it from the ground up, keeping security at the forefront of your mind.

You have built a strong foundation. I am confident you have the skills and the mindset to contribute meaningfully to the future of tokenized finance. Good luck

Can't find a good explanation? Sign up and we'll make it for you

Sign up