solidity-argus 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/AGENTS.md +3 -3
  2. package/README.md +93 -37
  3. package/package.json +33 -7
  4. package/skills/INVENTORY.md +88 -57
  5. package/skills/README.md +26 -23
  6. package/skills/case-studies/beanstalk-governance/SKILL.md +52 -0
  7. package/skills/case-studies/bzx-flash-loan/SKILL.md +53 -0
  8. package/skills/case-studies/cream-finance/SKILL.md +52 -0
  9. package/skills/case-studies/curve-reentrancy/SKILL.md +52 -0
  10. package/skills/case-studies/dao-hack/SKILL.md +51 -0
  11. package/skills/case-studies/euler-finance/SKILL.md +52 -0
  12. package/skills/case-studies/harvest-finance/SKILL.md +52 -0
  13. package/skills/case-studies/level-finance/SKILL.md +51 -0
  14. package/skills/case-studies/mango-markets/SKILL.md +53 -0
  15. package/skills/case-studies/nomad-bridge/SKILL.md +51 -0
  16. package/skills/case-studies/parity-multisig/SKILL.md +55 -0
  17. package/skills/case-studies/poly-network/SKILL.md +51 -0
  18. package/skills/case-studies/rari-fuse/SKILL.md +51 -0
  19. package/skills/case-studies/ronin-bridge/SKILL.md +52 -0
  20. package/skills/case-studies/wormhole-bridge/SKILL.md +51 -0
  21. package/skills/manifests/smartbugs.json +1 -3
  22. package/skills/manifests/sunweb3sec.json +1 -3
  23. package/skills/vulnerability-patterns/access-control/SKILL.md +14 -0
  24. package/skills/vulnerability-patterns/arbitrary-storage-location/SKILL.md +13 -1
  25. package/skills/vulnerability-patterns/assert-violation/SKILL.md +8 -1
  26. package/skills/vulnerability-patterns/asserting-contract-from-code-size/SKILL.md +12 -1
  27. package/skills/vulnerability-patterns/authorization-txorigin/SKILL.md +2 -1
  28. package/skills/vulnerability-patterns/cross-chain-bridge-vulnerabilities/SKILL.md +217 -0
  29. package/skills/vulnerability-patterns/default-visibility/SKILL.md +13 -1
  30. package/skills/vulnerability-patterns/delegatecall-untrusted-callee/SKILL.md +2 -1
  31. package/skills/vulnerability-patterns/dos-gas-limit/SKILL.md +8 -1
  32. package/skills/vulnerability-patterns/dos-revert/SKILL.md +1 -0
  33. package/skills/vulnerability-patterns/erc4626-exchange-rate-manipulation/SKILL.md +64 -0
  34. package/skills/vulnerability-patterns/fee-on-transfer-tokens/SKILL.md +93 -0
  35. package/skills/vulnerability-patterns/flash-loan-attacks/SKILL.md +1 -0
  36. package/skills/vulnerability-patterns/floating-pragma/SKILL.md +8 -1
  37. package/skills/vulnerability-patterns/front-running-attacks/SKILL.md +209 -0
  38. package/skills/vulnerability-patterns/gas-optimization-patterns/SKILL.md +203 -0
  39. package/skills/vulnerability-patterns/governance-attacks/SKILL.md +208 -0
  40. package/skills/vulnerability-patterns/hash-collision/SKILL.md +8 -1
  41. package/skills/vulnerability-patterns/inadherence-to-standards/SKILL.md +12 -1
  42. package/skills/vulnerability-patterns/incorrect-constructor/SKILL.md +8 -1
  43. package/skills/vulnerability-patterns/incorrect-inheritance-order/SKILL.md +8 -1
  44. package/skills/vulnerability-patterns/insufficient-gas-griefing/SKILL.md +12 -1
  45. package/skills/vulnerability-patterns/lack-of-precision/SKILL.md +7 -1
  46. package/skills/vulnerability-patterns/logic-errors/SKILL.md +10 -0
  47. package/skills/vulnerability-patterns/missing-parameter-bounds/SKILL.md +44 -0
  48. package/skills/vulnerability-patterns/missing-protection-signature-replay/SKILL.md +17 -1
  49. package/skills/vulnerability-patterns/msgvalue-loop/SKILL.md +12 -1
  50. package/skills/vulnerability-patterns/off-by-one/SKILL.md +7 -1
  51. package/skills/vulnerability-patterns/oracle-manipulation/SKILL.md +9 -0
  52. package/skills/vulnerability-patterns/outdated-compiler-version/SKILL.md +8 -1
  53. package/skills/vulnerability-patterns/overflow-underflow/SKILL.md +1 -0
  54. package/skills/vulnerability-patterns/proxy-vulnerabilities/SKILL.md +209 -0
  55. package/skills/vulnerability-patterns/reentrancy/SKILL.md +9 -0
  56. package/skills/vulnerability-patterns/shadowing-state-variables/SKILL.md +8 -1
  57. package/skills/vulnerability-patterns/share-accounting-desynchronization/SKILL.md +44 -0
  58. package/skills/vulnerability-patterns/signature-malleability/SKILL.md +2 -1
  59. package/skills/vulnerability-patterns/stateful-parameter-update-drift/SKILL.md +44 -0
  60. package/skills/vulnerability-patterns/unbounded-return-data/SKILL.md +12 -1
  61. package/skills/vulnerability-patterns/unchecked-return-values/SKILL.md +2 -1
  62. package/skills/vulnerability-patterns/unencrypted-private-data-on-chain/SKILL.md +8 -1
  63. package/skills/vulnerability-patterns/unexpected-ecrecover-null-address/SKILL.md +8 -1
  64. package/skills/vulnerability-patterns/uninitialized-storage-pointer/SKILL.md +8 -1
  65. package/skills/vulnerability-patterns/unsafe-erc20-transfers/SKILL.md +132 -0
  66. package/skills/vulnerability-patterns/unsafe-low-level-call/SKILL.md +12 -1
  67. package/skills/vulnerability-patterns/unsecure-signatures/SKILL.md +12 -1
  68. package/skills/vulnerability-patterns/unsupported-opcodes/SKILL.md +11 -1
  69. package/skills/vulnerability-patterns/unused-variables/SKILL.md +8 -1
  70. package/skills/vulnerability-patterns/use-of-deprecated-functions/SKILL.md +8 -1
  71. package/skills/vulnerability-patterns/weak-sources-randomness/SKILL.md +8 -1
  72. package/skills/vulnerability-patterns/weird-tokens/SKILL.md +10 -0
  73. package/skills/vulnerability-patterns/zero-address-misconfiguration/SKILL.md +48 -0
  74. package/src/agents/argus-prompt.ts +24 -7
  75. package/src/agents/pythia-prompt.ts +3 -4
  76. package/src/agents/scribe-prompt.ts +7 -2
  77. package/src/agents/sentinel-prompt.ts +32 -3
  78. package/src/cli/cli-program.ts +29 -26
  79. package/src/cli/commands/check-skills.ts +135 -0
  80. package/src/cli/commands/doctor.ts +48 -26
  81. package/src/cli/commands/init.ts +5 -3
  82. package/src/cli/commands/install.ts +7 -5
  83. package/src/cli/commands/lint-skills.ts +16 -12
  84. package/src/cli/index.ts +5 -5
  85. package/src/cli/types.ts +3 -3
  86. package/src/config/index.ts +1 -1
  87. package/src/config/loader.ts +4 -6
  88. package/src/config/schema.ts +4 -5
  89. package/src/config/types.ts +2 -2
  90. package/src/constants/defaults.ts +2 -0
  91. package/src/create-hooks.ts +145 -34
  92. package/src/create-managers.ts +10 -8
  93. package/src/create-tools.ts +13 -9
  94. package/src/features/background-agent/background-manager.ts +93 -87
  95. package/src/features/background-agent/index.ts +1 -1
  96. package/src/features/context-monitor/context-monitor.ts +3 -3
  97. package/src/features/context-monitor/index.ts +2 -2
  98. package/src/features/error-recovery/session-recovery.ts +2 -4
  99. package/src/features/error-recovery/tool-error-recovery.ts +12 -7
  100. package/src/features/index.ts +5 -5
  101. package/src/features/persistent-state/audit-state-manager.ts +143 -60
  102. package/src/features/persistent-state/global-run-index.ts +38 -0
  103. package/src/features/persistent-state/index.ts +1 -1
  104. package/src/features/persistent-state/run-journal.ts +86 -0
  105. package/src/hooks/config-handler.ts +28 -11
  106. package/src/hooks/context-budget.ts +2 -5
  107. package/src/hooks/event-hook.ts +47 -23
  108. package/src/hooks/hook-system.ts +4 -4
  109. package/src/hooks/index.ts +5 -5
  110. package/src/hooks/knowledge-sync-hook.ts +18 -21
  111. package/src/hooks/recon-context-builder.ts +2 -2
  112. package/src/hooks/safe-create-hook.ts +6 -7
  113. package/src/hooks/tool-tracking-hook.ts +104 -50
  114. package/src/hooks/types.ts +2 -1
  115. package/src/index.ts +23 -36
  116. package/src/knowledge/retry.ts +22 -22
  117. package/src/knowledge/scvd-client.ts +88 -95
  118. package/src/knowledge/scvd-errors.ts +35 -35
  119. package/src/knowledge/scvd-index.ts +78 -80
  120. package/src/knowledge/scvd-sync.ts +106 -101
  121. package/src/managers/index.ts +1 -1
  122. package/src/managers/types.ts +19 -14
  123. package/src/plugin-interface.ts +7 -9
  124. package/src/shared/binary-utils.ts +44 -35
  125. package/src/shared/deep-merge.ts +55 -36
  126. package/src/shared/file-utils.ts +21 -19
  127. package/src/shared/index.ts +11 -5
  128. package/src/shared/jsonc-parser.ts +123 -28
  129. package/src/shared/logger.ts +16 -3
  130. package/src/shared/project-utils.ts +30 -0
  131. package/src/skills/analysis/cluster.ts +414 -0
  132. package/src/skills/analysis/gates.ts +227 -0
  133. package/src/skills/analysis/index.ts +33 -0
  134. package/src/skills/analysis/normalize.ts +217 -0
  135. package/src/skills/analysis/similarity.ts +224 -0
  136. package/src/skills/argus-skill-resolver.ts +17 -6
  137. package/src/skills/skill-schema.ts +11 -10
  138. package/src/solodit-lifecycle.ts +202 -0
  139. package/src/state/audit-state.ts +8 -8
  140. package/src/state/finding-store.ts +68 -55
  141. package/src/state/types.ts +88 -67
  142. package/src/tools/argus-skill-load-tool.ts +12 -7
  143. package/src/tools/contract-analyzer-tool.ts +60 -77
  144. package/src/tools/forge-coverage-tool.ts +226 -0
  145. package/src/tools/forge-fuzz-tool.ts +127 -127
  146. package/src/tools/forge-test-tool.ts +153 -157
  147. package/src/tools/gas-analysis-tool.ts +264 -0
  148. package/src/tools/pattern-checker-tool.ts +185 -190
  149. package/src/tools/pattern-loader.ts +5 -111
  150. package/src/tools/proxy-detection-tool.ts +224 -0
  151. package/src/tools/report-generator-tool.ts +268 -200
  152. package/src/tools/slither-tool.ts +266 -218
  153. package/src/tools/solodit-search-tool.ts +216 -119
  154. package/src/tools/sync-knowledge-tool.ts +7 -11
  155. package/src/utils/audit-artifact-detector.ts +28 -29
  156. package/src/utils/dependency-scanner.ts +37 -37
  157. package/src/utils/project-detector.ts +111 -124
  158. package/src/utils/solidity-parser.ts +103 -74
  159. package/skills/patterns/access-control.yaml +0 -31
  160. package/skills/patterns/erc4626.yaml +0 -29
  161. package/skills/patterns/flash-loan.yaml +0 -20
  162. package/skills/patterns/oracle.yaml +0 -30
  163. package/skills/patterns/proxy.yaml +0 -30
  164. package/skills/patterns/reentrancy.yaml +0 -30
  165. package/skills/patterns/signature.yaml +0 -31
  166. package/src/hooks/event-hook-v2.ts +0 -99
  167. package/src/state/plugin-state.ts +0 -14
@@ -0,0 +1,208 @@
1
+ ---
2
+ name: governance-attacks
3
+ description: Governance vulnerabilities including flash-loan voting, timelock bypass, quorum manipulation, and unprotected proposals
4
+ category: vulnerability-pattern
5
+ pattern_category: governance
6
+ detection_rules:
7
+ - regex: 'function\s+(execute|queue)\s*\([^)]*\)\s+(external|public)[^}]*\{(?![\s\S]*timelock)'
8
+ severity: High
9
+ confidence: Medium
10
+ description: Governance execute/queue function without timelock enforcement - critical governance actions can be executed immediately without delay, enabling flash-loan governance attacks (cf. Beanstalk $182M exploit)
11
+ - regex: 'function\s+(propose|castVote|castVoteBySig|castVoteWithReason)\s*\('
12
+ severity: Critical
13
+ confidence: Medium
14
+ description: Governance voting or proposal function detected - verify that voting power is snapshot-based (not live balance) to prevent flash-loan governance attacks where attacker borrows tokens, votes, and repays in one transaction (cf. Beanstalk BIP-18 exploit)
15
+ - regex: '(getVotes|votingPower|balanceOf)\s*\([^)]*\)(?![\s\S]{0,120}(snapshot|Checkpoint|getPastVotes|getPastTotalSupply|blockNumber))'
16
+ severity: High
17
+ confidence: Low
18
+ description: Voting power queried without snapshot or checkpoint mechanism - live balance queries for governance are manipulable via flash loans or token transfers; quorum can be artificially met or circumvented (cf. Build Finance DAO takeover)
19
+ - regex: 'function\s+propose\s*\([^)]*\)\s+(external|public)(?![\s\S]{0,200}(require|_msgSender|proposalThreshold|getVotes|onlyRole))'
20
+ severity: Medium
21
+ confidence: Low
22
+ description: Proposal creation function without apparent threshold or access check - any address can submit proposals, enabling governance spam or malicious proposal attacks (cf. Audius governance exploit)
23
+ - regex: 'function\s+(execute|executeProposal)\s*\([^)]*\)\s+(external|public)[^}]*\{(?![\s\S]*(_execute|state\s*==|ProposalState|hasVoted))'
24
+ severity: High
25
+ confidence: Medium
26
+ description: Governance execution without multi-step state machine - proposals can be executed without passing through proper lifecycle states (Pending, Active, Succeeded, Queued, Executed), enabling bypass of voting periods and quorum requirements (cf. Build Finance DAO hostile takeover)
27
+ ---
28
+
29
+ # Governance Attack Patterns
30
+
31
+ ## Overview
32
+
33
+ On-chain governance is a privileged execution pipeline. Any flaw in how proposals are created, voted, queued, or executed can be equivalent to handing over protocol admin keys. Unlike many isolated bugs, governance flaws often impact treasury control, upgrade authority, risk parameters, and emergency controls in a single exploit path.
34
+
35
+ Modern attacks exploit the difference between governance latency and liquidity speed. Flash-loan capital allows an attacker to assemble temporary voting power, pass malicious actions, and unwind in one transaction unless voting weight is checkpointed at historical blocks. If timelocks and state transitions are weak, proposals can skip social review windows and execute immediately.
36
+
37
+ The highest-risk governance systems combine three anti-patterns: live balance voting, weak proposal gating, and permissive execution paths. Auditing governance must focus on lifecycle invariants, not only individual functions. The question is whether every privileged state change requires a full, observable sequence of controls before execution.
38
+
39
+ ## Key Attack Vectors
40
+
41
+ - Timelock bypass in `execute` or `queue` flows allows immediate execution after proposal success.
42
+ - Flash-loan voting exploits live `balanceOf` semantics when vote power is not snapshot based.
43
+ - Quorum manipulation occurs when total supply or vote weight is read at execution time instead of proposal snapshot time.
44
+ - Unprotected proposal creation enables spam, griefing, and malicious payload staging by any account.
45
+ - Single-step governance design collapses propose-vote-queue-execute into partial paths that skip lifecycle checks.
46
+ - Weak role boundaries allow governance executors to call arbitrary targets with arbitrary calldata and value.
47
+ - Incomplete cancellation rules let compromised proposers preserve malicious proposals through changing conditions.
48
+ - Vote delegation edge cases can mint effective influence if delegation checkpoints are inconsistent.
49
+ - Cross-governance integrations can create circular privilege where one module can reconfigure another's quorum.
50
+ - Emergency guardian paths can become permanent backdoors if sunset logic is absent.
51
+
52
+ ### Typical Exploit Chain
53
+
54
+ 1. Acquire temporary voting power through flash loan or borrow market.
55
+ 2. Submit or support a proposal with privileged target calls.
56
+ 3. Satisfy quorum using live-balance vote accounting.
57
+ 4. Bypass or minimize delay due to weak timelock enforcement.
58
+ 5. Execute payload to drain treasury, transfer ownership, or upgrade logic.
59
+ 6. Repay borrowed capital and exit before governance can react.
60
+
61
+ ### High-Value Governance Targets
62
+
63
+ - Treasury transfer executors.
64
+ - Upgrade proxy admin contracts.
65
+ - Oracle and risk parameter setters.
66
+ - Pause and unpause emergency modules.
67
+ - Bridge allowlists and relayer configuration.
68
+ - Fee recipient and distribution routes.
69
+
70
+ ## Detection Heuristics
71
+
72
+ ### Lifecycle Integrity Checks
73
+
74
+ - Verify a proposal state machine exists with explicit transitions: Pending -> Active -> Succeeded -> Queued -> Executed.
75
+ - Confirm `execute` requires `Succeeded` or `Queued` state and cannot run directly from `Pending` or `Active`.
76
+ - Ensure `queue` enforces a minimum delay through timelock metadata that cannot be zeroed by governance itself in the same proposal.
77
+ - Check replay protections so a proposal cannot execute twice.
78
+
79
+ ### Voting Power Semantics
80
+
81
+ - Flag direct use of `balanceOf()` in vote calculation paths.
82
+ - Require `getPastVotes()` and `getPastTotalSupply()` at a specific snapshot block.
83
+ - Validate that the snapshot block is set at proposal creation and cannot be user-provided at vote time.
84
+ - Review delegation checkpoint code for overflows, stale checkpoints, and self-delegation assumptions.
85
+
86
+ ### Proposal Gating and Anti-Spam
87
+
88
+ - Confirm `propose` enforces `proposalThreshold` or role checks.
89
+ - Check whether threshold compares against historical votes, not current balances.
90
+ - Detect absence of proposal deposits, cooldowns, or proposer rate limits in high-noise systems.
91
+ - Verify guardian cancellation rights are bounded and transparent.
92
+
93
+ ### Timelock and Execution Constraints
94
+
95
+ - Check for `onlyTimelock` or equivalent guard on privileged execution methods.
96
+ - Confirm target/callData hashing includes all fields used at execute time.
97
+ - Validate operation IDs are unique and consumed on execution.
98
+ - Ensure timelock admin rotation itself is timelocked.
99
+
100
+ ### Concrete Code Smells
101
+
102
+ ```solidity
103
+ function castVote(uint256 proposalId, uint8 support) external {
104
+ uint256 weight = token.balanceOf(msg.sender); // live-balance voting
105
+ _countVote(proposalId, msg.sender, support, weight);
106
+ }
107
+
108
+ function execute(uint256 proposalId) external {
109
+ // no state or timelock checks
110
+ _execute(proposalId);
111
+ }
112
+ ```
113
+
114
+ ```solidity
115
+ function propose(bytes[] calldata calls) external {
116
+ // no threshold, no role, no deposit
117
+ _storeProposal(msg.sender, calls);
118
+ }
119
+ ```
120
+
121
+ ## Prevention
122
+
123
+ ### Governance Architecture Controls
124
+
125
+ - Use OpenZeppelin `Governor` with `ERC20Votes` checkpoints and `TimelockController`.
126
+ - Set non-trivial `votingDelay`, `votingPeriod`, and timelock delay based on protocol TVL and response capacity.
127
+ - Keep proposer thresholds dynamic or governance-adjustable, but changes should be timelocked.
128
+ - Separate emergency powers from treasury powers, with explicit expiry of emergency authority.
129
+
130
+ ### Secure Vote Accounting
131
+
132
+ - Compute voter weight from historical checkpoints only.
133
+ - Freeze quorum math to snapshot-era total supply.
134
+ - Include anti-whale and anti-borrow constraints where applicable (lock periods, staking requirements, escrowed governance).
135
+ - Monitor concentrated delegation changes near snapshot boundaries.
136
+
137
+ ### Execution Hardening
138
+
139
+ - Gate execution through timelock-only entry points.
140
+ - Require proposal state assertions at each stage.
141
+ - Bind targets, values, calldata, and salt in operation hashes.
142
+ - Prevent same-block queue and execute operations.
143
+
144
+ ### Operational Safeguards
145
+
146
+ - Add off-chain alerting for proposal creation, queueing, and execution scheduling.
147
+ - Publish human-readable calldata decoders for governance payloads.
148
+ - Maintain an incident playbook for malicious proposal response.
149
+ - Use simulation tooling to preview proposal side effects before queueing.
150
+
151
+ ### Baseline Hardened Pattern
152
+
153
+ ```solidity
154
+ function castVote(uint256 proposalId, uint8 support) external {
155
+ ProposalCore storage p = _proposals[proposalId];
156
+ uint256 weight = token.getPastVotes(msg.sender, p.snapshotBlock);
157
+ require(weight > 0, "No voting power at snapshot");
158
+ _countVote(proposalId, msg.sender, support, weight);
159
+ }
160
+
161
+ function queue(uint256 proposalId) external {
162
+ require(state(proposalId) == ProposalState.Succeeded, "Not succeeded");
163
+ timelock.schedule(_operationHash(proposalId), MIN_DELAY);
164
+ }
165
+
166
+ function execute(uint256 proposalId) external {
167
+ require(state(proposalId) == ProposalState.Queued, "Not queued");
168
+ timelock.execute(_operationHash(proposalId));
169
+ }
170
+ ```
171
+
172
+ ## Real-World Examples
173
+
174
+ ### Beanstalk (2022)
175
+
176
+ - Reference: https://rekt.news/beanstalk-rekt/
177
+ - Flash-loaned governance power was used to pass and execute a malicious proposal in a compressed timeline.
178
+ - Core lesson: snapshot voting and meaningful timelock delays are non-optional for treasury governance.
179
+
180
+ ### Build Finance DAO Takeover (2022)
181
+
182
+ - Reference: https://rekt.news/build-finance-rekt/
183
+ - Governance control was captured and treasury assets were redirected by hostile governance actions.
184
+ - Core lesson: weak lifecycle controls and insufficient proposer/voter safeguards enable hostile takeovers.
185
+
186
+ ### Audius Governance Exploit (2022)
187
+
188
+ - Reference: https://rekt.news/audius-rekt/
189
+ - Governance configuration weakness allowed attacker influence over protocol control paths.
190
+ - Core lesson: proposal and execution authorization must be explicit, layered, and invariant-tested.
191
+
192
+ ### Pattern-to-Exploit Mapping
193
+
194
+ - `timelock-bypass` -> Beanstalk-like rapid execution risk.
195
+ - `flash-loan-governance` -> temporary capital vote capture.
196
+ - `quorum-manipulation` -> live-balance distortion of quorum and support.
197
+ - `unprotected-proposal` -> governance spam and payload staging.
198
+ - `single-step-governance` -> lifecycle bypass into privileged execution.
199
+
200
+ ## References
201
+
202
+ - OpenZeppelin Governor docs: https://docs.openzeppelin.com/contracts/4.x/governance
203
+ - OpenZeppelin TimelockController: https://docs.openzeppelin.com/contracts/4.x/api/governance#TimelockController
204
+ - Rekt News Beanstalk: https://rekt.news/beanstalk-rekt/
205
+ - Rekt News Build Finance: https://rekt.news/build-finance-rekt/
206
+ - Rekt News Audius: https://rekt.news/audius-rekt/
207
+ - Trail of Bits governance security discussions: https://blog.trailofbits.com/
208
+ - Sigma Prime solidity security notes: https://github.com/sigp/solidity-security-blog
@@ -1,6 +1,13 @@
1
1
  ---
2
2
  name: hash-collision
3
- description: - Contract uses `abi.encodePacked()` to encode data before hashing (typically with `keccak256`)
3
+ description: '- Contract uses `abi.encodePacked()` to encode data before hashing (typically with `keccak256`)'
4
+ pattern_category: logic-error
5
+ detection_rules:
6
+ - regex: 'abi\.encodePacked\('
7
+ severity: Medium
8
+ confidence: Medium
9
+ swc: SWC-133
10
+ description: Packed encoding may collide when multiple dynamic arguments are hashed
4
11
  ---
5
12
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
13
 
@@ -1,6 +1,17 @@
1
1
  ---
2
2
  name: inadherence-to-standards
3
- description: - Contract claims to implement a standard (ERC20, ERC721, ERC1155, etc.) but deviates from the specification
3
+ description: '- Contract claims to implement a standard (ERC20, ERC721, ERC1155, etc.) but deviates from the specification'
4
+ pattern_category: token-standard
5
+ detection_rules:
6
+ - regex: 'IERC20\b'
7
+ severity: Informational
8
+ confidence: Low
9
+ swc: SWC-134
10
+ description: ERC20 interface usage should be checked for standard compliance assumptions
11
+ - regex: 'IERC721\b'
12
+ severity: Informational
13
+ confidence: Low
14
+ description: ERC721 interface usage should be checked for standard compliance assumptions
4
15
  ---
5
16
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
17
 
@@ -1,6 +1,13 @@
1
1
  ---
2
2
  name: incorrect-constructor
3
- description: - Solidity version <0.4.22 where constructors are named functions matching the contract name
3
+ description: '- Solidity version <0.4.22 where constructors are named functions matching the contract name'
4
+ pattern_category: logic-error
5
+ detection_rules:
6
+ - regex: 'constructor\s*\('
7
+ severity: Informational
8
+ confidence: Low
9
+ swc: SWC-118
10
+ description: Constructor syntax signal for legacy constructor-name migration review
4
11
  ---
5
12
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
13
 
@@ -1,6 +1,13 @@
1
1
  ---
2
2
  name: incorrect-inheritance-order
3
- description: - Contract uses multiple inheritance (`is ContractA, ContractB, ...`)
3
+ description: '- Contract uses multiple inheritance (`is ContractA, ContractB, ...`)'
4
+ pattern_category: logic-error
5
+ detection_rules:
6
+ - regex: 'is\s+\w+\s*,\s*\w+'
7
+ severity: Informational
8
+ confidence: Low
9
+ swc: SWC-125
10
+ description: Multiple inheritance declaration needing linearization review
4
11
  ---
5
12
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
13
 
@@ -1,6 +1,17 @@
1
1
  ---
2
2
  name: insufficient-gas-griefing
3
- description: - Contract relays or forwards calls on behalf of users (meta-transactions, multisig execution, relayer patterns)
3
+ description: '- Contract relays or forwards calls on behalf of users (meta-transactions, multisig execution, relayer patterns)'
4
+ pattern_category: dos
5
+ detection_rules:
6
+ - regex: '\.call\{gas:'
7
+ severity: Medium
8
+ confidence: Medium
9
+ swc: SWC-126
10
+ description: Caller-controlled gas forwarding can censor relayed execution
11
+ - regex: 'gasleft\(\)'
12
+ severity: Low
13
+ confidence: Low
14
+ description: Gas accounting logic should be checked for griefing resilience
4
15
  ---
5
16
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
17
 
@@ -1,6 +1,12 @@
1
1
  ---
2
2
  name: lack-of-precision
3
- description: - Contract performs integer arithmetic (division, fee calculations, reward distributions)
3
+ description: '- Contract performs integer arithmetic (division, fee calculations, reward distributions)'
4
+ pattern_category: logic-error
5
+ detection_rules:
6
+ - regex: '/\s*\d+\s*\*'
7
+ severity: Low
8
+ confidence: Low
9
+ description: Division-before-multiplication pattern that can truncate precision
4
10
  ---
5
11
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
12
 
@@ -1,6 +1,16 @@
1
1
  ---
2
2
  name: logic-errors
3
3
  description: Protocol logic bug patterns, exploit examples, and invariant-driven review strategies.
4
+ pattern_category: logic-error
5
+ detection_rules:
6
+ - regex: 'if\s*\([^)]*&&[^)]*\|\|'
7
+ severity: Informational
8
+ confidence: Low
9
+ description: Mixed boolean operators in one condition warrant logic review
10
+ - regex: 'require\(.*,\s*"'
11
+ severity: Informational
12
+ confidence: Low
13
+ description: Guard clauses can reveal critical business-logic invariants
4
14
  ---
5
15
 
6
16
  <!-- Source: DeFiFoFum/fofum-solidity-skills (MIT) -->
@@ -0,0 +1,44 @@
1
+ ---
2
+ name: missing-parameter-bounds
3
+ description: "Protocol parameters are accepted without min/max constraints, allowing invalid or unsafe runtime states."
4
+ category: vulnerability-pattern
5
+ pattern_category: logic-error
6
+ source_url: "https://github.com/bailsec/BailSec"
7
+ source_license: "CC0"
8
+ imported_at: "2025-02-20T00:00:00Z"
9
+ detection_rules:
10
+ - regex: "function\\s+(set|update|configure|initialize|constructor).*\\{[\\s\\S]{0,400}?(bps|fee|ratio|range|cap|threshold)"
11
+ severity: "Medium"
12
+ description: "Configurable economic parameter likely missing explicit bounds"
13
+ - regex: "require\\(.*<=\\s*(MAX|1e4|10000)"
14
+ severity: "Low"
15
+ description: "Use as a companion check to find setters lacking equivalent guardrails"
16
+ ---
17
+ <!-- Source: BailSec audit reports (CC0) -->
18
+
19
+ # Missing Parameter Bounds Vulnerabilities
20
+
21
+ ## Overview
22
+ Missing parameter bounds is a recurring configuration-class vulnerability where contracts accept values that violate economic assumptions, arithmetic safety, or protocol UX constraints. Typical examples include BPS percentages above 100%, negative-style behavior encoded in signed ranges, or credit and share thresholds that can be bypassed in one path but enforced in another. The issue is often not immediate code execution risk, but delayed protocol failure, broken accounting, or user-loss scenarios after governance changes.
23
+
24
+ A high-risk variant is validation drift: constructor and setter logic differ, so initial deployment can inject invalid values that runtime mutation would reject (or vice versa). This creates non-obvious states auditors miss when they only inspect one code path.
25
+
26
+ ## Common Patterns
27
+ - Constructor omits upper bound checks that exist in a later setter.
28
+ - Setter enforces one invariant but related functions do not re-check post-action states.
29
+ - Signed range parameters increase complexity and permit invalid semantics.
30
+ - Optional token interfaces or assumptions are accepted without compatibility gating.
31
+
32
+ ## Detection Heuristics
33
+ - Build a matrix of each mutable parameter: constructor checks, setter checks, and all usage-site assumptions.
34
+ - Flag any economic parameter lacking explicit min/max and unit documentation.
35
+ - Compare pre-state vs post-state constraints on mutating flows (supply/withdraw/rebalance).
36
+ - Review all checks for consistency in BPS, decimals, and scaling conventions.
37
+
38
+ ## Examples from Audits
39
+ - Bridge bonus percentage accepted in initialization without enforcing BPS cap, allowing values above 10,000.
40
+ - Fee parameter validated in setter but not in constructor, enabling out-of-range deployment state.
41
+ - Credit and liquidity-related validation logic that was difficult to reason about and left bypass opportunities in adjacent paths.
42
+
43
+ ## Remediation
44
+ Define parameter invariants once and reuse them through internal validator functions called by constructor, initializer, setters, and upgrade hooks. Prefer explicit constants (`MIN_*`, `MAX_*`) with unit comments. For safety-critical parameters, add two-step governance updates plus simulation checks before activation. Back this with property tests that fuzz all bounded values and assert protocol invariants remain true after each update. This makes future maintenance safer and prevents silent drift between code paths.
@@ -1,6 +1,22 @@
1
1
  ---
2
2
  name: missing-protection-signature-replay
3
- description: - Contract verifies ECDSA signatures for authorization
3
+ description: '- Contract verifies ECDSA signatures for authorization'
4
+ pattern_category: signature
5
+ detection_rules:
6
+ - regex: 'ecrecover\('
7
+ severity: Medium
8
+ confidence: High
9
+ swc: SWC-121
10
+ description: Signature recovery path requires nonce, chain, and domain separation checks
11
+ - regex: 'ECDSA\.recover\('
12
+ severity: Medium
13
+ confidence: High
14
+ swc: SWC-121
15
+ description: Library-based signature recovery still needs replay protection fields
16
+ - regex: 'permit\(|signTypedData'
17
+ severity: High
18
+ confidence: Medium
19
+ description: Permit or typed data signing — missing nonce allows signature replay
4
20
  ---
5
21
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
22
 
@@ -1,6 +1,17 @@
1
1
  ---
2
2
  name: msgvalue-loop
3
- description: - `msg.value` is referenced inside a loop (`for`, `while`) or in a function called multiple times within a single external call
3
+ description: '- `msg.value` is referenced inside a loop (`for`, `while`) or in a function called multiple times within a single external call'
4
+ pattern_category: logic-error
5
+ detection_rules:
6
+ - regex: 'msg\.value'
7
+ severity: Low
8
+ confidence: Low
9
+ swc: SWC-134
10
+ description: msg.value usage that may be reused across loop iterations
11
+ - regex: '(for|while)\s*\('
12
+ severity: Informational
13
+ confidence: Low
14
+ description: Loop context signal for msg.value reuse review
4
15
  ---
5
16
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
17
 
@@ -1,6 +1,12 @@
1
1
  ---
2
2
  name: off-by-one
3
- description: - Contract uses loops with boundary conditions, comparison operators at thresholds, or array index calculations
3
+ description: '- Contract uses loops with boundary conditions, comparison operators at thresholds, or array index calculations'
4
+ pattern_category: logic-error
5
+ detection_rules:
6
+ - regex: '\.length\s*-\s*1'
7
+ severity: Low
8
+ confidence: Low
9
+ description: Boundary arithmetic near array length that can hide fence-post mistakes
4
10
  ---
5
11
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
12
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: oracle-manipulation
3
3
  description: Oracle manipulation techniques, case studies, and secure pricing integration controls for DeFi.
4
+ pattern_category: oracle-manipulation
4
5
  source_url: https://github.com/kadenzipfel/smart-contract-vulnerabilities
5
6
  source_license: MIT
6
7
  imported_at: "2025-01-15T00:00:00Z"
@@ -14,6 +15,14 @@ detection_rules:
14
15
  severity: High
15
16
  confidence: High
16
17
  description: AMM reserve spot-price usage vulnerable to manipulation
18
+ - regex: 'observe\(|consult\('
19
+ severity: Medium
20
+ confidence: Medium
21
+ description: TWAP oracle usage — time-weighted average prices can be manipulated via sustained trading pressure
22
+ - regex: 'priceFeed|oracle.*decimals'
23
+ severity: Medium
24
+ confidence: Medium
25
+ description: Oracle price feed with decimal handling — potential decimal mismatch between oracle and token
17
26
  ---
18
27
 
19
28
  <!-- Source: DeFiFoFum/fofum-solidity-skills (MIT) -->
@@ -1,6 +1,13 @@
1
1
  ---
2
2
  name: outdated-compiler-version
3
- description: - Contract is compiled with a Solidity version significantly behind the latest stable release
3
+ description: '- Contract is compiled with a Solidity version significantly behind the latest stable release'
4
+ pattern_category: logic-error
5
+ detection_rules:
6
+ - regex: 'pragma solidity 0\.[0-7]\.'
7
+ severity: Informational
8
+ confidence: High
9
+ swc: SWC-102
10
+ description: Solidity pragma pins to an outdated major/minor compiler line
4
11
  ---
5
12
  <!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
6
13
 
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  name: overflow-underflow
3
3
  description: Integer overflow and underflow vulnerabilities in Solidity contracts
4
+ pattern_category: logic-error
4
5
  source_url: https://github.com/kadenzipfel/smart-contract-vulnerabilities
5
6
  source_license: MIT
6
7
  imported_at: "2025-01-15T00:00:00Z"