Security Analysis and Audits
No single technique finds every bug, so secure projects layer several. This lesson explains static analysis, fuzzing and invariant testing, symbolic execution and formal verification, audits, bug bounties and monitoring, and how they fit into the development lifecycle.
Learning outcomes
After completing this lesson, you will be able to:
- Compare the main security verification techniques.
- Describe how static analysis findings are triaged.
- Explain fuzz and invariant testing.
- Describe the roles of audits, bug bounties and monitoring.
Layers of assurance
Each verification technique finds different kinds of problem. The following table compares them.
| Technique | How it works | Good at finding | Examples |
|---|---|---|---|
| Compiler warnings | Checks during compilation | Unused values, shadowing, unreachable code | solc |
| Unit tests | Developer-written checks of expected behaviour | Logic errors in known scenarios | Hardhat, Foundry |
| Static analysis | Scans source for known patterns without running it | Reentrancy, tx.origin, unchecked calls | Slither, Remix static analysis |
| Fuzzing | Runs functions with many random inputs | Edge cases developers did not think of | Foundry, Hardhat Solidity tests, Echidna |
| Invariant testing | Random call sequences checked against properties | Broken accounting and state machines | Foundry invariants, Echidna |
| Symbolic execution | Reasons about all inputs mathematically | Paths to unsafe states | Mythril |
| Formal verification | Proves properties against a specification | Guaranteed absence of specified bugs | Certora, SMTChecker |
| Manual audit | Expert review of design and code | Logic and economic flaws tools miss | Independent audit firms |
Assurance techniques
Static analysis in practice
Slither, an open-source Python tool, runs dozens of detectors over a Hardhat or Foundry project in seconds and ranks findings by impact and confidence. Its output must be triaged: some findings are real bugs, others are acceptable by design or false positives. Remix's Solidity Analyzers plugin offers similar checks in the browser. Running static analysis in continuous integration catches regressions on every change.
Fuzzing and invariants
A fuzz test is a test function with parameters; the runner calls it with hundreds or thousands of generated values, including boundary values, and reports any input that breaks an assertion. An invariant is a property that must always hold, such as "the sum of all balances equals totalSupply" or "the contract's ether is at least the total owed"; an invariant test executes random sequences of calls by random actors and checks the property after each.
// A Hardhat or Foundry Solidity fuzz test
function testFuzz_DepositWithdraw(uint96 amount) public {
vm.assume(amount > 0);
vault.deposit{value: amount}();
vault.withdraw(amount);
assertEq(address(vault).balance, 0);
}Audits, bug bounties and monitoring
A security audit is a time-boxed review by independent specialists, typically after the code is feature-complete and well tested. Auditors report findings by severity, the team fixes them, and the auditors review the fixes. An audit reduces risk but cannot prove the absence of bugs, and any change after the audit needs review again.
After deployment, a bug bounty programme rewards researchers who report vulnerabilities responsibly instead of exploiting them, and monitoring watches for unusual transactions, such as large withdrawals or calls to administrative functions, so the team can respond, for example by pausing.
Assurance across a launch
Planning assurance for a launch
A team will launch a staking contract holding user funds in eight weeks. What security activities should the plan include, and in what order?
During development: unit tests for every function and failure path, static analysis in continuous integration, and fuzz and invariant tests for the accounting. When the code is frozen: an external audit, fixes and a fix review, then a deployment rehearsal on a fork and on Sepolia. At launch: verified source, administrative roles on a multisig, caps on deposits for the first weeks, monitoring and a bug bounty. The audit should not be the first time the code faces scrutiny.
Triaging a tool finding
Slither reports "reentrancy-events" in a function that emits an event after an external call to a trusted, immutable token. The team asks whether this is a critical vulnerability.
The detector flags that an event is emitted after an external call, which could make event order misleading if the call re-entered. With a trusted, non-reentrant token, the impact is low, but moving the event before the call costs nothing and silences the finding. Each finding should be assessed for real impact, then fixed or documented as accepted, rather than dismissed or treated as automatically critical.
What is an invariant test?
Show answer
A test that runs random sequences of function calls and checks after each that a property always holds, such as the sum of balances equalling the total supply.
Exam Tips
Remember for the exam
- Combine tests, static analysis, fuzzing, invariants, review and audits; each finds different bugs.
- Slither and Remix analyzers detect known patterns; findings need triage.
- Invariant tests check properties after random call sequences.
- Audits reduce risk but are not guarantees; changed code needs re-review.
- Bug bounties and monitoring continue security after deployment.