solidity-argus 0.1.8 → 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.
- package/AGENTS.md +3 -3
- package/README.md +229 -13
- package/package.json +37 -8
- package/skills/INVENTORY.md +88 -57
- package/skills/README.md +72 -6
- package/skills/case-studies/beanstalk-governance/SKILL.md +52 -0
- package/skills/case-studies/bzx-flash-loan/SKILL.md +53 -0
- package/skills/case-studies/cream-finance/SKILL.md +52 -0
- package/skills/case-studies/curve-reentrancy/SKILL.md +52 -0
- package/skills/case-studies/dao-hack/SKILL.md +51 -0
- package/skills/case-studies/euler-finance/SKILL.md +52 -0
- package/skills/case-studies/harvest-finance/SKILL.md +52 -0
- package/skills/case-studies/level-finance/SKILL.md +51 -0
- package/skills/case-studies/mango-markets/SKILL.md +53 -0
- package/skills/case-studies/nomad-bridge/SKILL.md +51 -0
- package/skills/case-studies/parity-multisig/SKILL.md +55 -0
- package/skills/case-studies/poly-network/SKILL.md +51 -0
- package/skills/case-studies/rari-fuse/SKILL.md +51 -0
- package/skills/case-studies/ronin-bridge/SKILL.md +52 -0
- package/skills/case-studies/wormhole-bridge/SKILL.md +51 -0
- package/skills/checklists/cyfrin-defi-core/SKILL.md +3 -0
- package/skills/manifests/cyfrin.json +16 -0
- package/skills/manifests/defifofum.json +25 -0
- package/skills/manifests/kadenzipfel.json +48 -0
- package/skills/manifests/scvd.json +9 -0
- package/skills/manifests/smartbugs.json +9 -0
- package/skills/manifests/solodit.json +9 -0
- package/skills/manifests/sunweb3sec.json +9 -0
- package/skills/manifests/trailofbits.json +9 -0
- package/skills/methodology/audit-workflow/SKILL.md +3 -0
- package/skills/protocol-patterns/amm-dex/SKILL.md +3 -0
- package/skills/references/exploit-reference/SKILL.md +3 -0
- package/skills/vulnerability-patterns/access-control/SKILL.md +27 -0
- package/skills/vulnerability-patterns/arbitrary-storage-location/SKILL.md +13 -1
- package/skills/vulnerability-patterns/assert-violation/SKILL.md +8 -1
- package/skills/vulnerability-patterns/asserting-contract-from-code-size/SKILL.md +12 -1
- package/skills/vulnerability-patterns/authorization-txorigin/SKILL.md +8 -1
- package/skills/vulnerability-patterns/cross-chain-bridge-vulnerabilities/SKILL.md +217 -0
- package/skills/vulnerability-patterns/default-visibility/SKILL.md +13 -1
- package/skills/vulnerability-patterns/delegatecall-untrusted-callee/SKILL.md +8 -1
- package/skills/vulnerability-patterns/dos-gas-limit/SKILL.md +8 -1
- package/skills/vulnerability-patterns/dos-revert/SKILL.md +14 -1
- package/skills/vulnerability-patterns/erc4626-exchange-rate-manipulation/SKILL.md +64 -0
- package/skills/vulnerability-patterns/fee-on-transfer-tokens/SKILL.md +93 -0
- package/skills/vulnerability-patterns/flash-loan-attacks/SKILL.md +13 -0
- package/skills/vulnerability-patterns/floating-pragma/SKILL.md +8 -1
- package/skills/vulnerability-patterns/front-running-attacks/SKILL.md +209 -0
- package/skills/vulnerability-patterns/gas-optimization-patterns/SKILL.md +203 -0
- package/skills/vulnerability-patterns/governance-attacks/SKILL.md +208 -0
- package/skills/vulnerability-patterns/hash-collision/SKILL.md +8 -1
- package/skills/vulnerability-patterns/inadherence-to-standards/SKILL.md +12 -1
- package/skills/vulnerability-patterns/incorrect-constructor/SKILL.md +8 -1
- package/skills/vulnerability-patterns/incorrect-inheritance-order/SKILL.md +8 -1
- package/skills/vulnerability-patterns/insufficient-gas-griefing/SKILL.md +12 -1
- package/skills/vulnerability-patterns/lack-of-precision/SKILL.md +7 -1
- package/skills/vulnerability-patterns/logic-errors/SKILL.md +10 -0
- package/skills/vulnerability-patterns/missing-parameter-bounds/SKILL.md +44 -0
- package/skills/vulnerability-patterns/missing-protection-signature-replay/SKILL.md +17 -1
- package/skills/vulnerability-patterns/msgvalue-loop/SKILL.md +12 -1
- package/skills/vulnerability-patterns/off-by-one/SKILL.md +7 -1
- package/skills/vulnerability-patterns/oracle-manipulation/SKILL.md +22 -0
- package/skills/vulnerability-patterns/outdated-compiler-version/SKILL.md +8 -1
- package/skills/vulnerability-patterns/overflow-underflow/SKILL.md +11 -1
- package/skills/vulnerability-patterns/proxy-vulnerabilities/SKILL.md +209 -0
- package/skills/vulnerability-patterns/reentrancy/SKILL.md +22 -0
- package/skills/vulnerability-patterns/shadowing-state-variables/SKILL.md +8 -1
- package/skills/vulnerability-patterns/share-accounting-desynchronization/SKILL.md +44 -0
- package/skills/vulnerability-patterns/signature-malleability/SKILL.md +11 -1
- package/skills/vulnerability-patterns/stateful-parameter-update-drift/SKILL.md +44 -0
- package/skills/vulnerability-patterns/unbounded-return-data/SKILL.md +12 -1
- package/skills/vulnerability-patterns/unchecked-return-values/SKILL.md +13 -1
- package/skills/vulnerability-patterns/unencrypted-private-data-on-chain/SKILL.md +8 -1
- package/skills/vulnerability-patterns/unexpected-ecrecover-null-address/SKILL.md +8 -1
- package/skills/vulnerability-patterns/uninitialized-storage-pointer/SKILL.md +8 -1
- package/skills/vulnerability-patterns/unsafe-erc20-transfers/SKILL.md +132 -0
- package/skills/vulnerability-patterns/unsafe-low-level-call/SKILL.md +12 -1
- package/skills/vulnerability-patterns/unsecure-signatures/SKILL.md +12 -1
- package/skills/vulnerability-patterns/unsupported-opcodes/SKILL.md +11 -1
- package/skills/vulnerability-patterns/unused-variables/SKILL.md +8 -1
- package/skills/vulnerability-patterns/use-of-deprecated-functions/SKILL.md +8 -1
- package/skills/vulnerability-patterns/weak-sources-randomness/SKILL.md +8 -1
- package/skills/vulnerability-patterns/weird-tokens/SKILL.md +10 -0
- package/skills/vulnerability-patterns/zero-address-misconfiguration/SKILL.md +48 -0
- package/src/agents/argus-prompt.ts +27 -10
- package/src/agents/pythia-prompt.ts +7 -8
- package/src/agents/scribe-prompt.ts +10 -5
- package/src/agents/sentinel-prompt.ts +36 -7
- package/src/cli/cli-output.ts +16 -0
- package/src/cli/cli-program.ts +29 -22
- package/src/cli/commands/check-skills.ts +135 -0
- package/src/cli/commands/doctor.ts +303 -23
- package/src/cli/commands/init.ts +8 -6
- package/src/cli/commands/install.ts +10 -8
- package/src/cli/commands/lint-skills.ts +118 -0
- package/src/cli/index.ts +5 -5
- package/src/cli/tui-prompts.ts +4 -2
- package/src/cli/types.ts +3 -3
- package/src/config/index.ts +1 -1
- package/src/config/loader.ts +4 -6
- package/src/config/schema.ts +6 -5
- package/src/config/types.ts +2 -2
- package/src/constants/defaults.ts +2 -0
- package/src/create-hooks.ts +225 -29
- package/src/create-managers.ts +10 -8
- package/src/create-tools.ts +14 -8
- package/src/features/background-agent/background-manager.ts +93 -87
- package/src/features/background-agent/index.ts +1 -1
- package/src/features/context-monitor/context-monitor.ts +3 -3
- package/src/features/context-monitor/index.ts +2 -2
- package/src/features/error-recovery/session-recovery.ts +2 -4
- package/src/features/error-recovery/tool-error-recovery.ts +79 -19
- package/src/features/index.ts +5 -5
- package/src/features/persistent-state/audit-state-manager.ts +158 -52
- package/src/features/persistent-state/global-run-index.ts +38 -0
- package/src/features/persistent-state/index.ts +1 -1
- package/src/features/persistent-state/run-journal.ts +86 -0
- package/src/hooks/agent-tracker.ts +53 -0
- package/src/hooks/compaction-hook.ts +46 -37
- package/src/hooks/config-handler.ts +31 -11
- package/src/hooks/context-budget.ts +42 -0
- package/src/hooks/event-hook.ts +48 -23
- package/src/hooks/hook-system.ts +4 -4
- package/src/hooks/index.ts +5 -5
- package/src/hooks/knowledge-sync-hook.ts +19 -21
- package/src/hooks/recon-context-builder.ts +66 -0
- package/src/hooks/safe-create-hook.ts +9 -11
- package/src/hooks/system-prompt-hook.ts +128 -0
- package/src/hooks/tool-tracking-hook.ts +162 -29
- package/src/hooks/types.ts +2 -1
- package/src/index.ts +23 -13
- package/src/knowledge/retry.ts +53 -0
- package/src/knowledge/scvd-client.ts +103 -83
- package/src/knowledge/scvd-errors.ts +89 -0
- package/src/knowledge/scvd-index.ts +110 -62
- package/src/knowledge/scvd-sync.ts +223 -47
- package/src/knowledge/source-manifest.ts +102 -0
- package/src/managers/index.ts +1 -1
- package/src/managers/types.ts +19 -14
- package/src/plugin-interface.ts +19 -8
- package/src/shared/binary-utils.ts +44 -34
- package/src/shared/deep-merge.ts +55 -36
- package/src/shared/file-utils.ts +21 -19
- package/src/shared/index.ts +11 -5
- package/src/shared/jsonc-parser.ts +123 -28
- package/src/shared/logger.ts +91 -17
- package/src/shared/project-utils.ts +30 -0
- package/src/skills/analysis/cluster.ts +414 -0
- package/src/skills/analysis/gates.ts +227 -0
- package/src/skills/analysis/index.ts +33 -0
- package/src/skills/analysis/normalize.ts +217 -0
- package/src/skills/analysis/similarity.ts +224 -0
- package/src/skills/argus-skill-resolver.ts +237 -0
- package/src/skills/skill-schema.ts +99 -0
- package/src/solodit-lifecycle.ts +202 -0
- package/src/state/audit-state.ts +10 -8
- package/src/state/finding-store.ts +68 -55
- package/src/state/types.ts +96 -44
- package/src/tools/argus-skill-load-tool.ts +78 -0
- package/src/tools/contract-analyzer-tool.ts +60 -77
- package/src/tools/forge-coverage-tool.ts +226 -0
- package/src/tools/forge-fuzz-tool.ts +127 -127
- package/src/tools/forge-test-tool.ts +153 -157
- package/src/tools/gas-analysis-tool.ts +264 -0
- package/src/tools/pattern-checker-tool.ts +206 -167
- package/src/tools/pattern-loader.ts +77 -0
- package/src/tools/pattern-schema.ts +51 -0
- package/src/tools/proxy-detection-tool.ts +224 -0
- package/src/tools/report-generator-tool.ts +333 -142
- package/src/tools/slither-tool.ts +300 -210
- package/src/tools/solodit-search-tool.ts +255 -80
- package/src/tools/sync-knowledge-tool.ts +7 -11
- package/src/utils/audit-artifact-detector.ts +118 -0
- package/src/utils/dependency-scanner.ts +93 -0
- package/src/utils/project-detector.ts +175 -86
- package/src/utils/solidity-parser.ts +112 -67
- package/src/utils/solodit-health.ts +29 -0
- package/src/hooks/event-hook-v2.ts +0 -99
- package/src/state/plugin-state.ts +0 -14
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cross-chain-bridge-vulnerabilities
|
|
3
|
+
description: Cross-chain bridge vulnerabilities including missing chain ID validation, cross-chain replay attacks, unverified bridge messages, and hardcoded bridge addresses
|
|
4
|
+
category: vulnerability-pattern
|
|
5
|
+
pattern_category: logic-error
|
|
6
|
+
detection_rules:
|
|
7
|
+
- regex: '(abi\.encodePacked|keccak256)\s*\([^)]*(?!.*\b(block\.chainid|chainId)\b)[^)]*\)'
|
|
8
|
+
severity: High
|
|
9
|
+
confidence: Medium
|
|
10
|
+
description: Cross-chain message hash constructed without chain ID - signatures or proofs can be replayed on other chains where the contract is deployed at the same address
|
|
11
|
+
- regex: 'ecrecover\s*\([^)]*(?!.*\b(chainId|block\.chainid)\b)[^)]*\)'
|
|
12
|
+
severity: High
|
|
13
|
+
confidence: Medium
|
|
14
|
+
description: Signature recovery without chain-specific binding - ecrecover call does not reference chainId, allowing signed messages to be replayed across chain forks or L2 deployments
|
|
15
|
+
- regex: '(onMessageReceived|_processMessage|receiveMessage|handleBridgeMessage)\s*\('
|
|
16
|
+
severity: Critical
|
|
17
|
+
confidence: High
|
|
18
|
+
description: Bridge message receiver function detected - verify the caller is the authorized bridge contract and the source chain/sender are validated before processing
|
|
19
|
+
- regex: 'address\s+(constant|immutable)\s+\w*(bridge|Bridge|BRIDGE|relay|Relay|messenger|Messenger)\w*\s*='
|
|
20
|
+
severity: Medium
|
|
21
|
+
confidence: High
|
|
22
|
+
description: Hardcoded bridge or relay address - if the bridge contract is upgraded or redeployed, this contract cannot adapt without redeployment
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
# Cross-Chain Bridge Vulnerability Patterns
|
|
26
|
+
|
|
27
|
+
## Overview
|
|
28
|
+
|
|
29
|
+
Bridge systems expand trust boundaries across chains, consensus assumptions, and message formats. A single validation error in message authentication can mint unbacked assets, unlock escrowed collateral, or allow arbitrary calls on destination chains. Because bridges often custody large TVL, exploit impact is frequently catastrophic.
|
|
30
|
+
|
|
31
|
+
Two themes dominate bridge incidents: insufficient domain separation and weak message authenticity checks. Domain separation prevents a proof or signature from one context (chain, contract, epoch) from being reused in another. Authenticity checks ensure only approved bridge infrastructure and source identities can trigger state transitions.
|
|
32
|
+
|
|
33
|
+
Bridge security review should treat every inbound message as adversarial by default. Validation must bind the message to source chain, source sender, destination chain, destination contract, nonce, and replay state. Any omitted field becomes a likely replay or forgery surface.
|
|
34
|
+
|
|
35
|
+
## Key Attack Vectors
|
|
36
|
+
|
|
37
|
+
- Message hash construction that omits `chainId` or equivalent domain fields.
|
|
38
|
+
- Signature verification via `ecrecover` without chain-specific binding.
|
|
39
|
+
- Receiver handlers that trust `msg.sender` without verifying authorized bridge endpoint.
|
|
40
|
+
- Missing validation of source chain and source application address.
|
|
41
|
+
- Replayable messages due to absent nonce consumption or idempotency checks.
|
|
42
|
+
- Hardcoded bridge addresses that become stale after upgrades or migrations.
|
|
43
|
+
- Weak upgrade controls on bridge config, relayers, and validator sets.
|
|
44
|
+
- Message parsers that decode calldata but do not enforce strict schema/version.
|
|
45
|
+
|
|
46
|
+
### Typical Replay Attack Flow
|
|
47
|
+
|
|
48
|
+
1. Attacker observes a valid signed bridge message on Chain A -> Chain B.
|
|
49
|
+
2. Message does not include robust domain separation fields.
|
|
50
|
+
3. Attacker replays the same payload on another deployment or fork.
|
|
51
|
+
4. Destination contract accepts the message as valid.
|
|
52
|
+
5. Funds are minted or released multiple times.
|
|
53
|
+
6. Accounting diverges from source-chain lock state.
|
|
54
|
+
|
|
55
|
+
### Typical Authentication Bypass Flow
|
|
56
|
+
|
|
57
|
+
1. Bridge receiver exposes `handleBridgeMessage` style function.
|
|
58
|
+
2. Function checks payload structure but not trusted caller/source identity.
|
|
59
|
+
3. Attacker calls function directly with crafted message.
|
|
60
|
+
4. Contract executes privileged state change (mint, transfer, config update).
|
|
61
|
+
5. Attack completes without compromising bridge validators.
|
|
62
|
+
|
|
63
|
+
## Detection Heuristics
|
|
64
|
+
|
|
65
|
+
### Domain Separation Checks
|
|
66
|
+
|
|
67
|
+
- Search message hash construction for inclusion of `block.chainid` or canonical `chainId` field.
|
|
68
|
+
- Confirm hash binds destination contract address and source chain identifiers.
|
|
69
|
+
- Verify signatures use EIP-712 domain separators with `chainId` and `verifyingContract`.
|
|
70
|
+
- Flag ad-hoc `abi.encodePacked` payloads with ambiguous or incomplete fields.
|
|
71
|
+
|
|
72
|
+
### Signature Verification Checks
|
|
73
|
+
|
|
74
|
+
- Review `ecrecover` call sites for explicit domain-bound message digests.
|
|
75
|
+
- Ensure recovered signer is validated against current authorized signer set.
|
|
76
|
+
- Check for malleability handling and strict `s` value constraints where needed.
|
|
77
|
+
- Confirm nonce or message ID is consumed exactly once.
|
|
78
|
+
|
|
79
|
+
### Receiver Authorization Checks
|
|
80
|
+
|
|
81
|
+
- Require `msg.sender == trustedBridge` or equivalent allowlist enforcement.
|
|
82
|
+
- Validate source chain ID and source sender embedded in payload.
|
|
83
|
+
- Confirm message ordering and replay protection against duplicate IDs.
|
|
84
|
+
- Ensure receiver functions are `nonReentrant` if they trigger external calls.
|
|
85
|
+
|
|
86
|
+
### Configuration and Upgrade Checks
|
|
87
|
+
|
|
88
|
+
- Flag immutable or constant bridge addresses for systems that expect migrations.
|
|
89
|
+
- Validate admin setter functions are timelocked and role-gated.
|
|
90
|
+
- Check event emissions for all config changes (bridge, relayer, validator set).
|
|
91
|
+
- Review emergency pause controls and recovery workflows.
|
|
92
|
+
|
|
93
|
+
### Concrete Code Smells
|
|
94
|
+
|
|
95
|
+
```solidity
|
|
96
|
+
bytes32 digest = keccak256(abi.encodePacked(amount, recipient, nonce));
|
|
97
|
+
address signer = ecrecover(digest, v, r, s); // no chain binding
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```solidity
|
|
101
|
+
function handleBridgeMessage(bytes calldata payload) external {
|
|
102
|
+
// missing require(msg.sender == trustedBridge)
|
|
103
|
+
_process(payload);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```solidity
|
|
108
|
+
address immutable bridgeMessenger = 0x1234...; // no upgrade path
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Audit Checklist
|
|
112
|
+
|
|
113
|
+
- Is message identity globally unique across chains and contracts?
|
|
114
|
+
- Can the same proof be replayed on forks or sibling deployments?
|
|
115
|
+
- Are source app addresses validated against chain-scoped allowlists?
|
|
116
|
+
- Is every successful message marked consumed atomically?
|
|
117
|
+
- Can governance safely rotate bridge endpoints and signer sets?
|
|
118
|
+
|
|
119
|
+
## Prevention
|
|
120
|
+
|
|
121
|
+
### Message Schema Hardening
|
|
122
|
+
|
|
123
|
+
- Use typed message structs with explicit fields: source chain, destination chain, source app, destination app, nonce, payload hash.
|
|
124
|
+
- Hash using EIP-712 domain separation when signatures are involved.
|
|
125
|
+
- Reject unknown schema versions to avoid parsing ambiguity.
|
|
126
|
+
- Enforce strict decoding with size and range checks.
|
|
127
|
+
|
|
128
|
+
### Authentication and Replay Controls
|
|
129
|
+
|
|
130
|
+
- Verify caller is the designated bridge endpoint contract.
|
|
131
|
+
- Validate source chain ID and sender against immutable or governable allowlists.
|
|
132
|
+
- Consume message IDs in a replay map before external side effects.
|
|
133
|
+
- Make message execution idempotent where practical.
|
|
134
|
+
|
|
135
|
+
### Configurability with Safety
|
|
136
|
+
|
|
137
|
+
- Prefer configurable bridge addresses over hardcoded constants.
|
|
138
|
+
- Protect config updates with timelock and multi-sig governance.
|
|
139
|
+
- Emit detailed events on every trust-boundary change.
|
|
140
|
+
- Add two-step ownership transfer for bridge admin roles.
|
|
141
|
+
|
|
142
|
+
### Hardened Receiver Example
|
|
143
|
+
|
|
144
|
+
```solidity
|
|
145
|
+
function handleBridgeMessage(
|
|
146
|
+
uint256 sourceChainId,
|
|
147
|
+
address sourceApp,
|
|
148
|
+
uint256 nonce,
|
|
149
|
+
bytes calldata payload,
|
|
150
|
+
bytes calldata proof
|
|
151
|
+
) external nonReentrant {
|
|
152
|
+
require(msg.sender == trustedBridge, "Unauthorized bridge caller");
|
|
153
|
+
require(allowedSourceChains[sourceChainId], "Unsupported source chain");
|
|
154
|
+
require(allowedSourceApps[sourceChainId][sourceApp], "Unsupported source app");
|
|
155
|
+
|
|
156
|
+
bytes32 messageId = keccak256(
|
|
157
|
+
abi.encode(
|
|
158
|
+
block.chainid,
|
|
159
|
+
sourceChainId,
|
|
160
|
+
sourceApp,
|
|
161
|
+
address(this),
|
|
162
|
+
nonce,
|
|
163
|
+
keccak256(payload)
|
|
164
|
+
)
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
require(!consumed[messageId], "Replay");
|
|
168
|
+
require(verifyProof(messageId, proof), "Invalid proof");
|
|
169
|
+
|
|
170
|
+
consumed[messageId] = true;
|
|
171
|
+
_executePayload(payload);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Operational Defenses
|
|
176
|
+
|
|
177
|
+
- Continuously monitor duplicate message IDs across chains.
|
|
178
|
+
- Run chaos tests with forked deployments and stale bridge configs.
|
|
179
|
+
- Maintain emergency pause for inbound message processing.
|
|
180
|
+
- Reconcile bridge accounting between lock and mint sides on a schedule.
|
|
181
|
+
|
|
182
|
+
## Real-World Examples
|
|
183
|
+
|
|
184
|
+
### Wormhole (2022)
|
|
185
|
+
|
|
186
|
+
- Reference: https://rekt.news/wormhole-rekt/
|
|
187
|
+
- Forged verification path enabled minting of unbacked wrapped assets.
|
|
188
|
+
- Lesson: proof and signature validation must be strict, domain-separated, and invariant-tested.
|
|
189
|
+
|
|
190
|
+
### Nomad (2022)
|
|
191
|
+
|
|
192
|
+
- Reference: https://rekt.news/nomad-rekt/
|
|
193
|
+
- Message validation assumptions failed, enabling widespread unauthorized message replay/copycat draining.
|
|
194
|
+
- Lesson: receiver authenticity checks and replay protection are critical at every handler entry point.
|
|
195
|
+
|
|
196
|
+
### Additional Bridge Incident Patterns
|
|
197
|
+
|
|
198
|
+
- Bridge key-management failures (validator compromise).
|
|
199
|
+
- Config drift between source and destination chain deployments.
|
|
200
|
+
- Insufficient upgrade controls introducing unreviewed trust paths.
|
|
201
|
+
|
|
202
|
+
### Pattern-to-Impact Mapping
|
|
203
|
+
|
|
204
|
+
- `missing-chain-id-validation` -> cross-chain replay of otherwise valid messages.
|
|
205
|
+
- `replay-across-chains` -> signature reuse on forks/L2 mirrors.
|
|
206
|
+
- `unverified-bridge-message` -> direct unauthorized execution on destination chain.
|
|
207
|
+
- `hardcoded-bridge-address` -> operational failure or unsafe hotfix pressure during upgrades.
|
|
208
|
+
|
|
209
|
+
## References
|
|
210
|
+
|
|
211
|
+
- Rekt News Wormhole: https://rekt.news/wormhole-rekt/
|
|
212
|
+
- Rekt News Nomad: https://rekt.news/nomad-rekt/
|
|
213
|
+
- EIP-712 typed structured data hashing: https://eips.ethereum.org/EIPS/eip-712
|
|
214
|
+
- OpenZeppelin access control patterns: https://docs.openzeppelin.com/contracts/4.x/access-control
|
|
215
|
+
- Chainlink CCIP security overview: https://docs.chain.link/ccip
|
|
216
|
+
- NIST guidance on replay resistance concepts: https://csrc.nist.gov/
|
|
217
|
+
- Trail of Bits bridge security research: https://blog.trailofbits.com/
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: default-visibility
|
|
3
|
-
description: - Functions or state variables are declared without an explicit visibility specifier
|
|
3
|
+
description: '- Functions or state variables are declared without an explicit visibility specifier'
|
|
4
|
+
pattern_category: access-control
|
|
5
|
+
detection_rules:
|
|
6
|
+
- regex: 'function\s+\w+\s*\('
|
|
7
|
+
severity: Informational
|
|
8
|
+
confidence: Low
|
|
9
|
+
swc: SWC-100
|
|
10
|
+
description: Generic function declaration signal for manual default visibility review (legacy SWC-100/SWC-108 context)
|
|
11
|
+
- regex: 'function\s+\w+\s*\([^)]*\)\s*\{'
|
|
12
|
+
severity: Medium
|
|
13
|
+
confidence: Low
|
|
14
|
+
swc: SWC-100
|
|
15
|
+
description: Function without explicit visibility specifier — defaults to public in older Solidity versions
|
|
4
16
|
---
|
|
5
17
|
<!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
|
|
6
18
|
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: delegatecall-untrusted-callee
|
|
3
|
-
description:
|
|
3
|
+
description: "Contract uses delegatecall with potentially untrusted callee"
|
|
4
|
+
pattern_category: delegatecall
|
|
5
|
+
detection_rules:
|
|
6
|
+
- regex: 'delegatecall'
|
|
7
|
+
severity: High
|
|
8
|
+
confidence: High
|
|
9
|
+
swc: SWC-112
|
|
10
|
+
description: Delegatecall usage where callee trust boundary must be verified
|
|
4
11
|
---
|
|
5
12
|
<!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
|
|
6
13
|
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dos-gas-limit
|
|
3
|
-
description: - Contract iterates over a dynamic array or mapping whose size can grow unboundedly
|
|
3
|
+
description: '- Contract iterates over a dynamic array or mapping whose size can grow unboundedly'
|
|
4
|
+
pattern_category: dos
|
|
5
|
+
detection_rules:
|
|
6
|
+
- regex: 'for\s*\([^)]*\.length'
|
|
7
|
+
severity: Medium
|
|
8
|
+
confidence: Low
|
|
9
|
+
swc: SWC-128
|
|
10
|
+
description: Loop bounded by dynamic length may become unexecutable at scale
|
|
4
11
|
---
|
|
5
12
|
<!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
|
|
6
13
|
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dos-revert
|
|
3
|
-
description: -
|
|
3
|
+
description: Denial-of-service attacks through unexpected reverts in external calls
|
|
4
|
+
pattern_category: dos
|
|
5
|
+
source_url: https://github.com/kadenzipfel/smart-contract-vulnerabilities
|
|
6
|
+
source_license: MIT
|
|
7
|
+
imported_at: "2025-01-15T00:00:00Z"
|
|
8
|
+
detection_rules:
|
|
9
|
+
- regex: 'require\(.*\.send'
|
|
10
|
+
severity: Medium
|
|
11
|
+
confidence: Medium
|
|
12
|
+
description: Require-on-send pattern can cause full-transaction DoS
|
|
13
|
+
- regex: 'for\s*\('
|
|
14
|
+
severity: Low
|
|
15
|
+
confidence: Low
|
|
16
|
+
description: Loop construct that may combine with external calls for DoS risk
|
|
4
17
|
---
|
|
5
18
|
<!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
|
|
6
19
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: erc4626-exchange-rate-manipulation
|
|
3
|
+
description: "ERC-4626 integrations are exploited by manipulating share price or conversion state to mint, borrow, or redeem at distorted rates."
|
|
4
|
+
category: vulnerability-pattern
|
|
5
|
+
pattern_category: erc4626
|
|
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: "(convertToShares|convertToAssets|previewDeposit|previewWithdraw|totalAssets\\()"
|
|
11
|
+
severity: "High"
|
|
12
|
+
description: "Critical ERC-4626 conversion surfaces requiring manipulation resistance"
|
|
13
|
+
- regex: "flashLoan\\(|flash\\s*loan|donat(e|ion)"
|
|
14
|
+
severity: "High"
|
|
15
|
+
description: "Capital-amplified exchange-rate manipulation preconditions"
|
|
16
|
+
- regex: 'balanceOf.*address.*this.*totalAssets|asset\.balanceOf'
|
|
17
|
+
severity: High
|
|
18
|
+
confidence: Medium
|
|
19
|
+
description: Vault totalAssets derived from balanceOf — vulnerable to donation attack to inflate share price
|
|
20
|
+
- regex: 'mulDiv|roundUp|roundDown|FullMath'
|
|
21
|
+
severity: Medium
|
|
22
|
+
confidence: Medium
|
|
23
|
+
description: Custom rounding math in vault share calculations — potential rounding errors favoring attacker
|
|
24
|
+
- regex: 'shares\s*=\s*(assets|amount)\b'
|
|
25
|
+
severity: Critical
|
|
26
|
+
confidence: Medium
|
|
27
|
+
description: Direct asset-to-share mapping without virtual offset — first depositor can inflate share price
|
|
28
|
+
- regex: '\.transfer\(address\(this\)|\.safeTransfer\(address\(this\)'
|
|
29
|
+
severity: High
|
|
30
|
+
confidence: Medium
|
|
31
|
+
description: Direct token transfer to vault bypassing deposit accounting — enables donation attack
|
|
32
|
+
- regex: 'totalSupply\(\)\s*==\s*0|totalAssets\(\)\s*==\s*0'
|
|
33
|
+
severity: Medium
|
|
34
|
+
confidence: Medium
|
|
35
|
+
description: Empty vault state check without minimum deposit or dead share enforcement
|
|
36
|
+
---
|
|
37
|
+
<!-- Source: BailSec audit reports (CC0) -->
|
|
38
|
+
|
|
39
|
+
# ERC4626 Exchange Rate Manipulation Vulnerabilities
|
|
40
|
+
|
|
41
|
+
## Overview
|
|
42
|
+
This pattern targets vault systems that rely on ERC-4626 share/asset conversion, especially when those conversions are consumed by lending, collateral, or routing logic. Attackers manipulate the apparent exchange rate (or timing of its update) so victims mint too few shares, borrow against mispriced collateral, or absorb bad debt. The exploit usually combines one of: flash liquidity, share supply edge cases, stale accounting, rounding asymmetry, or permissive user-specified share parameters.
|
|
43
|
+
|
|
44
|
+
The core failure is trusting conversion outputs as if they were immutable and manipulation-resistant under adversarial flow ordering.
|
|
45
|
+
|
|
46
|
+
## Common Patterns
|
|
47
|
+
- User-facing functions accept shares as input without robust slippage/min-out protection.
|
|
48
|
+
- Vault share price can be inflated/deflated between preview and execution.
|
|
49
|
+
- First-user or low-liquidity states create nonlinear price jumps.
|
|
50
|
+
- Protocol treats ERC-4626 collateral as safe despite supply concentration and flash accessibility.
|
|
51
|
+
|
|
52
|
+
## Detection Heuristics
|
|
53
|
+
- Trace every use of `convertToShares/Assets` and `preview*` into borrow limits, liquidation, and accounting updates.
|
|
54
|
+
- Check for same-tx manipulability of `totalAssets` or effective share supply.
|
|
55
|
+
- Verify min-out controls for both assets and shares on deposit/withdraw flows.
|
|
56
|
+
- Stress-test empty, near-empty, and first-deposit states with fuzzed ordering.
|
|
57
|
+
|
|
58
|
+
## Examples from Audits
|
|
59
|
+
- Share-price inflation path where a victim specifying share quantity could be induced to supply more assets than intended.
|
|
60
|
+
- ERC-4626 collateral market where flash-loan control of share supply enabled bad-debt creation through exchange-rate distortion.
|
|
61
|
+
- Vault inflation scenario where fee accrual and conversion math created attacker-favorable rounding for later users.
|
|
62
|
+
|
|
63
|
+
## Remediation
|
|
64
|
+
Require explicit user slippage bounds on both assets and shares. Add anti-manipulation checks that compare pre/post conversion expectations and reject large deltas within the same transaction context. Introduce bootstrap protections for first deposits (seed shares, dead shares, or guarded initialization). For lending integrations, gate collateral eligibility, cap concentration, and add oracle or TWAP defenses around vault share pricing. Finally, test conversion invariants under adversarial ordering and flash-capital assumptions.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fee-on-transfer-tokens
|
|
3
|
+
description: Fee-on-transfer and deflationary token integration pitfalls that break protocol accounting.
|
|
4
|
+
category: vulnerability-pattern
|
|
5
|
+
pattern_category: token-standard
|
|
6
|
+
source_url: https://github.com/bailsec/BailSec
|
|
7
|
+
source_license: CC0
|
|
8
|
+
imported_at: "2026-02-20T00:00:00Z"
|
|
9
|
+
detection_rules:
|
|
10
|
+
- regex: 'transferFrom\('
|
|
11
|
+
severity: Medium
|
|
12
|
+
confidence: Medium
|
|
13
|
+
description: Token transfer that may receive less than expected with fee-on-transfer tokens
|
|
14
|
+
- regex: 'safeTransferFrom\('
|
|
15
|
+
severity: Medium
|
|
16
|
+
confidence: Medium
|
|
17
|
+
description: Safe token transfer that may receive less than expected with fee-on-transfer tokens
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
<!-- Source: BailSec audit reports (CC0) -->
|
|
21
|
+
<!-- Extracted via audit-ingest pipeline from 5 independent protocol audits -->
|
|
22
|
+
|
|
23
|
+
# Fee-on-Transfer Token Incompatibility
|
|
24
|
+
|
|
25
|
+
## Overview
|
|
26
|
+
|
|
27
|
+
Protocols that assume `transferFrom(sender, recipient, amount)` delivers exactly `amount` tokens to the recipient will break when interacting with fee-on-transfer (deflationary) tokens. These tokens deduct a fee during transfer, so the actual received amount is less than the specified amount. This creates accounting mismatches that can lead to insolvency, stuck funds, or exploitation.
|
|
28
|
+
|
|
29
|
+
**Severity:** Informational to Medium (depends on whether the protocol explicitly supports or excludes these tokens)
|
|
30
|
+
|
|
31
|
+
**Prevalence:** Found in 5 independent BailSec audits: Gamma UniswapV4, Gamma Vaults, Meuna, Moebius Finance, Terminal Finance DEX.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Vulnerable Pattern
|
|
36
|
+
|
|
37
|
+
```solidity
|
|
38
|
+
// VULNERABLE: Assumes amount received == amount transferred
|
|
39
|
+
function deposit(address token, uint256 amount) external {
|
|
40
|
+
IERC20(token).transferFrom(msg.sender, address(this), amount);
|
|
41
|
+
// If token has 2% fee, contract only received 0.98 * amount
|
|
42
|
+
// but records the full amount — accounting is now wrong
|
|
43
|
+
balances[msg.sender] += amount; // Overstated!
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Secure Pattern
|
|
48
|
+
|
|
49
|
+
```solidity
|
|
50
|
+
// SECURE: Measures actual received amount
|
|
51
|
+
function deposit(address token, uint256 amount) external {
|
|
52
|
+
uint256 balanceBefore = IERC20(token).balanceOf(address(this));
|
|
53
|
+
IERC20(token).transferFrom(msg.sender, address(this), amount);
|
|
54
|
+
uint256 received = IERC20(token).balanceOf(address(this)) - balanceBefore;
|
|
55
|
+
balances[msg.sender] += received; // Correct accounting
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Impact
|
|
60
|
+
|
|
61
|
+
- **Accounting mismatch**: Protocol records more tokens than it holds, leading to insolvency over time
|
|
62
|
+
- **Failed withdrawals**: Later users cannot withdraw because the contract has fewer tokens than expected
|
|
63
|
+
- **Vault share inflation**: In vault/pool contexts, shares are minted for a larger amount than actually deposited
|
|
64
|
+
- **Arbitrage opportunity**: Attackers can exploit the mismatch to extract value from the protocol
|
|
65
|
+
|
|
66
|
+
## Affected Token Examples
|
|
67
|
+
|
|
68
|
+
| Token | Fee Mechanism | Notes |
|
|
69
|
+
|-------|--------------|-------|
|
|
70
|
+
| SAFEMOON | 10% tax on transfer | Reflection + burn + liquidity |
|
|
71
|
+
| STA (Statera) | 1% deflationary burn | Destroyed on each transfer |
|
|
72
|
+
| PAXG | 0.02% transfer fee | Gold-backed, fee goes to Paxos |
|
|
73
|
+
| USDT (potential) | Configurable fee (currently 0) | Has fee infrastructure built-in |
|
|
74
|
+
|
|
75
|
+
## Detection Checklist
|
|
76
|
+
|
|
77
|
+
1. Does the contract call `transferFrom()` or `safeTransferFrom()` and then use the `amount` parameter directly?
|
|
78
|
+
2. Is there a `balanceOf(address(this))` check before and after the transfer?
|
|
79
|
+
3. Does the protocol documentation state support for fee-on-transfer tokens?
|
|
80
|
+
4. Are there any allowlists/denylists for supported tokens?
|
|
81
|
+
|
|
82
|
+
## Remediation
|
|
83
|
+
|
|
84
|
+
1. **Measure actual received**: Use before/after `balanceOf` to determine the actual amount received
|
|
85
|
+
2. **Document token support**: Explicitly state whether fee-on-transfer tokens are supported
|
|
86
|
+
3. **Token allowlist**: If the protocol only supports standard tokens, enforce an allowlist
|
|
87
|
+
4. **Revert on mismatch**: Add a check that reverts if received amount differs from expected
|
|
88
|
+
|
|
89
|
+
## References
|
|
90
|
+
|
|
91
|
+
- [Weird ERC20 Tokens — Fee on Transfer](https://github.com/d-xo/weird-erc20#fee-on-transfer)
|
|
92
|
+
- OpenZeppelin SafeERC20 documentation
|
|
93
|
+
- BailSec audit reports: Gamma, Meuna, Moebius Finance, Terminal Finance DEX
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: flash-loan-attacks
|
|
3
3
|
description: Flash-loan attack mechanics, exploit archetypes, and mitigations for capital-amplified threats.
|
|
4
|
+
pattern_category: flash-loan
|
|
5
|
+
source_url: https://github.com/kadenzipfel/smart-contract-vulnerabilities
|
|
6
|
+
source_license: MIT
|
|
7
|
+
imported_at: "2025-01-15T00:00:00Z"
|
|
8
|
+
detection_rules:
|
|
9
|
+
- regex: 'flashLoan\('
|
|
10
|
+
severity: High
|
|
11
|
+
confidence: High
|
|
12
|
+
description: Flash loan primitive usage that can amplify economic attacks
|
|
13
|
+
- regex: 'balanceOf\(address\(this\)\)'
|
|
14
|
+
severity: Medium
|
|
15
|
+
confidence: Medium
|
|
16
|
+
description: In-transaction balance checks often used in flash-loan-sensitive logic
|
|
4
17
|
---
|
|
5
18
|
|
|
6
19
|
<!-- Source: DeFiFoFum/fofum-solidity-skills (MIT) -->
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: floating-pragma
|
|
3
|
-
description: - Deployable contract uses a floating or range pragma (e.g., `pragma solidity ^0.8.0`, `pragma solidity >=0.8.0`)
|
|
3
|
+
description: '- Deployable contract uses a floating or range pragma (e.g., `pragma solidity ^0.8.0`, `pragma solidity >=0.8.0`)'
|
|
4
|
+
pattern_category: logic-error
|
|
5
|
+
detection_rules:
|
|
6
|
+
- regex: 'pragma solidity \^'
|
|
7
|
+
severity: Medium
|
|
8
|
+
confidence: High
|
|
9
|
+
swc: SWC-103
|
|
10
|
+
description: Floating pragma via caret version range
|
|
4
11
|
---
|
|
5
12
|
<!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
|
|
6
13
|
|