Code Reconnaissance Methodology
Purpose
Rapidly understand what the code does through structural analysis and flow tracing.
This is reconnaissance, not vulnerability hunting.
1. File Discovery
By Language
| Language |
Find Files |
Framework Markers |
| Solidity |
Glob("**/*.sol") |
foundry.toml, hardhat.config.* |
| Rust |
Glob("**/programs/**/*.rs") |
Anchor.toml, Cargo.toml |
| Cairo |
Glob("**/*.cairo") |
Scarb.toml |
| Move |
Glob("**/*.move") |
Move.toml |
Skip These
test/, tests/, *.t.sol, *.test.sol
mock/, mocks/, *Mock.sol
node_modules/, lib/ (dependencies)
- Generated/compiled files
2. Contract Structure Analysis
For Each Contract, Extract:
Contract: {Name}
File: {path}
Purpose: {one line description}
Inherits: {parent contracts}
Key State: {important state variables}
Entry Points: {external/public functions}
Inheritance Mapping
BaseContract
├── ChildA
│ └── GrandchildA1
└── ChildB
External Dependencies
| Import |
Type |
Notes |
| @openzeppelin/... |
Standard lib |
Usually safe |
| @chainlink/... |
Oracle |
Price dependency |
| @uniswap/... |
DEX integration |
External call |
3. Flow Tracing
The Core Question
"How does value enter, move through, and exit this protocol?"
Entry Flows (How users put value in)
| Pattern |
Function Names |
What Happens |
| Deposit |
deposit, supply, provide |
Assets in, receipts out |
| Stake |
stake, lock, bond |
Assets locked, tracking updated |
| Swap In |
swap, exchange |
Asset A in, Asset B out |
| Mint |
mint, create |
Payment in, tokens created |
Internal Flows (How value transforms)
| Pattern |
What to Look For |
| Calculations |
Fee deductions, interest accrual, share pricing |
| State Changes |
Balance updates, position tracking |
| Internal Calls |
Function-to-function flow within contract |
| External Calls |
Interactions with other contracts |
Exit Flows (How users get value out)
| Pattern |
Function Names |
What Happens |
| Withdraw |
withdraw, remove, redeem |
Receipts burned, assets out |
| Unstake |
unstake, unlock, unbond |
Assets released |
| Claim |
claim, harvest, collect |
Rewards distributed |
Privileged Flows (Admin operations)
| Pattern |
Risk Level |
What to Note |
emergencyWithdraw |
High |
Can bypass normal checks |
sweep, rescue |
High |
Can move arbitrary tokens |
pause, unpause |
Medium |
Can halt operations |
setFee, setRate |
Medium |
Can change economics |
4. Protocol Type Classification
Identify by Code Patterns
| Protocol Type |
Key Indicators |
Main Flows |
| AMM/DEX |
reserve0, reserve1, k, swap(), addLiquidity() |
swap, add/remove liquidity |
| Lending |
borrow(), collateral, liquidate(), interestRate |
supply, borrow, repay, liquidate |
| Vault |
totalAssets(), totalSupply(), shares, ERC4626 |
deposit, withdraw, yield |
| Governance |
propose(), vote(), execute(), quorum |
propose, vote, execute |
| Staking |
stake(), rewards, epoch, rewardPerToken |
stake, claim rewards |
| Bridge |
lock(), mint(), relayMessage(), nonce |
lock on L1, mint on L2 |
5. Asset Storage Patterns
ETH Storage
// Direct balance
address(this).balance
// Wrapped
WETH.balanceOf(address(this))
Token Storage
// External balance check
IERC20(token).balanceOf(address(this))
// Internal accounting
mapping(address => uint256) balances;
uint256 totalDeposited;
Share/Receipt Tokens
// Protocol issues these
mapping(address => uint256) shares;
uint256 totalSupply;
function balanceOf(address) external view returns (uint256);
6. Notable Patterns to Mark
Mark location only. No analysis needed - Phase 2 handles that.
| Pattern |
Why Notable |
.call{value:} |
External call with ETH |
delegatecall |
Code execution delegation |
| External contract calls |
Trust boundary crossing |
onlyOwner, onlyAdmin |
Privileged operations |
| Oracle integration |
External data dependency |
| Complex math |
Potential calculation issues |
| Assembly blocks |
Low-level operations |
7. Search Queries
Find Entry Points
Grep("function.*external|function.*public", glob="**/*.sol")
Find Asset Movements
Grep("transfer\\(|transferFrom\\(|safeTransfer", glob="**/*.sol")
Find Privileged Functions
Grep("onlyOwner|onlyAdmin|onlyRole|require.*msg\\.sender", glob="**/*.sol")
Find External Calls
Grep("\\.call\\{|\\.delegatecall\\(|address\\(.*\\)\\..*\\(", glob="**/*.sol")
Output
Write findings to .vigilo/recon/code-findings.md following the format in
template.md.
Additional Resources
- template.md - Output template for code reconnaissance findings
- examples/minimal-output.md - Minimal output example for small projects
1---2name: code-analysis3description: Code Analysis4---56# Code Reconnaissance Methodology78## Purpose910Rapidly understand **what the code does** through structural analysis and flow tracing.11This is reconnaissance, not vulnerability hunting.1213---1415## 1. File Discovery1617### By Language1819| Language | Find Files | Framework Markers |20|----------|------------|-------------------|21| Solidity | `Glob("**/*.sol")` | `foundry.toml`, `hardhat.config.*` |22| Rust | `Glob("**/programs/**/*.rs")` | `Anchor.toml`, `Cargo.toml` |23| Cairo | `Glob("**/*.cairo")` | `Scarb.toml` |24| Move | `Glob("**/*.move")` | `Move.toml` |2526### Skip These27- `test/`, `tests/`, `*.t.sol`, `*.test.sol`28- `mock/`, `mocks/`, `*Mock.sol`29- `node_modules/`, `lib/` (dependencies)30- Generated/compiled files3132---3334## 2. Contract Structure Analysis3536### For Each Contract, Extract:3738```39Contract: {Name}40File: {path}41Purpose: {one line description}42Inherits: {parent contracts}43Key State: {important state variables}44Entry Points: {external/public functions}45```4647### Inheritance Mapping4849```50BaseContract51├── ChildA52│ └── GrandchildA153└── ChildB54```5556### External Dependencies5758| Import | Type | Notes |59|--------|------|-------|60| @openzeppelin/... | Standard lib | Usually safe |61| @chainlink/... | Oracle | Price dependency |62| @uniswap/... | DEX integration | External call |6364---6566## 3. Flow Tracing6768### The Core Question69**"How does value enter, move through, and exit this protocol?"**7071### Entry Flows (How users put value in)7273| Pattern | Function Names | What Happens |74|---------|---------------|--------------|75| Deposit | `deposit`, `supply`, `provide` | Assets in, receipts out |76| Stake | `stake`, `lock`, `bond` | Assets locked, tracking updated |77| Swap In | `swap`, `exchange` | Asset A in, Asset B out |78| Mint | `mint`, `create` | Payment in, tokens created |7980### Internal Flows (How value transforms)8182| Pattern | What to Look For |83|---------|------------------|84| Calculations | Fee deductions, interest accrual, share pricing |85| State Changes | Balance updates, position tracking |86| Internal Calls | Function-to-function flow within contract |87| External Calls | Interactions with other contracts |8889### Exit Flows (How users get value out)9091| Pattern | Function Names | What Happens |92|---------|---------------|--------------|93| Withdraw | `withdraw`, `remove`, `redeem` | Receipts burned, assets out |94| Unstake | `unstake`, `unlock`, `unbond` | Assets released |95| Claim | `claim`, `harvest`, `collect` | Rewards distributed |9697### Privileged Flows (Admin operations)9899| Pattern | Risk Level | What to Note |100|---------|------------|--------------|101| `emergencyWithdraw` | High | Can bypass normal checks |102| `sweep`, `rescue` | High | Can move arbitrary tokens |103| `pause`, `unpause` | Medium | Can halt operations |104| `setFee`, `setRate` | Medium | Can change economics |105106---107108## 4. Protocol Type Classification109110### Identify by Code Patterns111112| Protocol Type | Key Indicators | Main Flows |113|---------------|----------------|------------|114| **AMM/DEX** | `reserve0`, `reserve1`, `k`, `swap()`, `addLiquidity()` | swap, add/remove liquidity |115| **Lending** | `borrow()`, `collateral`, `liquidate()`, `interestRate` | supply, borrow, repay, liquidate |116| **Vault** | `totalAssets()`, `totalSupply()`, `shares`, ERC4626 | deposit, withdraw, yield |117| **Governance** | `propose()`, `vote()`, `execute()`, `quorum` | propose, vote, execute |118| **Staking** | `stake()`, `rewards`, `epoch`, `rewardPerToken` | stake, claim rewards |119| **Bridge** | `lock()`, `mint()`, `relayMessage()`, `nonce` | lock on L1, mint on L2 |120121---122123## 5. Asset Storage Patterns124125### ETH Storage126127```solidity128// Direct balance129address(this).balance130131// Wrapped132WETH.balanceOf(address(this))133```134135### Token Storage136137```solidity138// External balance check139IERC20(token).balanceOf(address(this))140141// Internal accounting142mapping(address => uint256) balances;143uint256 totalDeposited;144```145146### Share/Receipt Tokens147148```solidity149// Protocol issues these150mapping(address => uint256) shares;151uint256 totalSupply;152function balanceOf(address) external view returns (uint256);153```154155---156157## 6. Notable Patterns to Mark158159Mark location only. No analysis needed - Phase 2 handles that.160161| Pattern | Why Notable |162|---------|-------------|163| `.call{value:}` | External call with ETH |164| `delegatecall` | Code execution delegation |165| External contract calls | Trust boundary crossing |166| `onlyOwner`, `onlyAdmin` | Privileged operations |167| Oracle integration | External data dependency |168| Complex math | Potential calculation issues |169| Assembly blocks | Low-level operations |170171---172173## 7. Search Queries174175### Find Entry Points176177```178Grep("function.*external|function.*public", glob="**/*.sol")179```180181### Find Asset Movements182183```184Grep("transfer\\(|transferFrom\\(|safeTransfer", glob="**/*.sol")185```186187### Find Privileged Functions188189```190Grep("onlyOwner|onlyAdmin|onlyRole|require.*msg\\.sender", glob="**/*.sol")191```192193### Find External Calls194195```196Grep("\\.call\\{|\\.delegatecall\\(|address\\(.*\\)\\..*\\(", glob="**/*.sol")197```198199---200201## Output202203Write findings to `.vigilo/recon/code-findings.md` following the format in204[template.md](template.md).205206---207208## Additional Resources209210- [template.md](template.md) - Output template for code reconnaissance findings211- [examples/minimal-output.md](examples/minimal-output.md) - Minimal output example for small projects