solidity-argus 0.2.0 → 0.3.2
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 +93 -37
- package/package.json +34 -7
- package/skills/INVENTORY.md +88 -57
- package/skills/README.md +26 -23
- 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/manifests/smartbugs.json +1 -3
- package/skills/manifests/sunweb3sec.json +1 -3
- package/skills/vulnerability-patterns/access-control/SKILL.md +14 -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 +2 -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 +2 -1
- package/skills/vulnerability-patterns/dos-gas-limit/SKILL.md +8 -1
- package/skills/vulnerability-patterns/dos-revert/SKILL.md +1 -0
- 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 +1 -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 +9 -0
- package/skills/vulnerability-patterns/outdated-compiler-version/SKILL.md +8 -1
- package/skills/vulnerability-patterns/overflow-underflow/SKILL.md +1 -0
- package/skills/vulnerability-patterns/proxy-vulnerabilities/SKILL.md +209 -0
- package/skills/vulnerability-patterns/reentrancy/SKILL.md +9 -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 +2 -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 +2 -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 +34 -7
- package/src/agents/pythia-prompt.ts +13 -4
- package/src/agents/scribe-prompt.ts +20 -2
- package/src/agents/sentinel-prompt.ts +45 -5
- package/src/cli/cli-program.ts +29 -26
- package/src/cli/commands/check-skills.ts +135 -0
- package/src/cli/commands/doctor.ts +48 -26
- package/src/cli/commands/init.ts +5 -3
- package/src/cli/commands/install.ts +7 -5
- package/src/cli/commands/lint-skills.ts +16 -12
- package/src/cli/index.ts +5 -5
- 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 +145 -34
- package/src/create-managers.ts +10 -8
- package/src/create-tools.ts +13 -9
- 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 +12 -7
- package/src/features/index.ts +5 -5
- package/src/features/persistent-state/audit-state-manager.ts +143 -60
- 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/config-handler.ts +28 -11
- package/src/hooks/context-budget.ts +2 -5
- package/src/hooks/event-hook.ts +47 -23
- package/src/hooks/hook-system.ts +4 -4
- package/src/hooks/index.ts +5 -5
- package/src/hooks/knowledge-sync-hook.ts +18 -21
- package/src/hooks/recon-context-builder.ts +2 -2
- package/src/hooks/safe-create-hook.ts +6 -7
- package/src/hooks/system-prompt-hook.ts +18 -1
- package/src/hooks/tool-tracking-hook.ts +110 -51
- package/src/hooks/types.ts +2 -1
- package/src/index.ts +24 -37
- package/src/knowledge/retry.ts +22 -22
- package/src/knowledge/scvd-client.ts +88 -95
- package/src/knowledge/scvd-errors.ts +35 -35
- package/src/knowledge/scvd-index.ts +78 -80
- package/src/knowledge/scvd-sync.ts +106 -101
- package/src/managers/index.ts +1 -1
- package/src/managers/types.ts +19 -14
- package/src/plugin-interface.ts +7 -9
- package/src/shared/binary-utils.ts +44 -35
- 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 +16 -3
- 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 +17 -6
- package/src/skills/skill-schema.ts +11 -10
- package/src/solodit-lifecycle.ts +203 -0
- package/src/state/audit-state.ts +8 -8
- package/src/state/finding-store.ts +68 -55
- package/src/state/types.ts +88 -67
- package/src/tools/argus-skill-load-tool.ts +12 -7
- package/src/tools/contract-analyzer-tool.ts +142 -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 +201 -158
- package/src/tools/gas-analysis-tool.ts +264 -0
- package/src/tools/pattern-checker-tool.ts +203 -191
- package/src/tools/pattern-loader.ts +5 -111
- package/src/tools/pattern-schema.ts +3 -0
- package/src/tools/proxy-detection-tool.ts +224 -0
- package/src/tools/report-generator-tool.ts +305 -206
- package/src/tools/slither-tool.ts +266 -218
- package/src/tools/solodit-search-tool.ts +235 -119
- package/src/tools/sync-knowledge-tool.ts +7 -11
- package/src/utils/audit-artifact-detector.ts +28 -29
- package/src/utils/dependency-scanner.ts +37 -37
- package/src/utils/project-detector.ts +111 -124
- package/src/utils/solidity-parser.ts +175 -75
- package/skills/patterns/access-control.yaml +0 -31
- package/skills/patterns/erc4626.yaml +0 -29
- package/skills/patterns/flash-loan.yaml +0 -20
- package/skills/patterns/oracle.yaml +0 -30
- package/skills/patterns/proxy.yaml +0 -30
- package/skills/patterns/reentrancy.yaml +0 -30
- package/skills/patterns/signature.yaml +0 -31
- package/src/hooks/event-hook-v2.ts +0 -99
- package/src/state/plugin-state.ts +0 -14
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: rari-fuse
|
|
3
|
+
description: "Case study of the 2022 Rari Fuse exploit: reentrancy in Compound fork draining ~$80M"
|
|
4
|
+
category: reference
|
|
5
|
+
source_url: "https://rekt.news/rari-fuse-rekt/"
|
|
6
|
+
source_license: "CC0"
|
|
7
|
+
imported_at: "2025-02-20T00:00:00Z"
|
|
8
|
+
detection_rules:
|
|
9
|
+
- regex: 'CEther|CToken'
|
|
10
|
+
severity: "Medium"
|
|
11
|
+
description: "Detects usage of Compound-style lending tokens. Forks must ensure reentrancy guards are applied to all sensitive functions."
|
|
12
|
+
---
|
|
13
|
+
<!-- Source: rekt.news (CC0) -->
|
|
14
|
+
<!-- Source: SunWeb3Sec/DeFiHackLabs (Reference) -->
|
|
15
|
+
|
|
16
|
+
# Rari Fuse (2022)
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
In April 2022, several Rari Fuse lending pools were exploited for approximately $80 million. The attack targeted a reentrancy vulnerability in the protocol's `CEther` contract, which was a fork of Compound. The attacker was able to borrow assets against their collateral and then re-enter the contract to withdraw the collateral before the borrow was recorded.
|
|
20
|
+
|
|
21
|
+
## Root Cause
|
|
22
|
+
The vulnerability was a classic reentrancy bug in the `exitMarket` function of the `Comptroller` or the `redeem` function of the `CEther` contract. When a user withdrew ETH, the contract made an external call to the user's address before updating the internal state. Because Rari's fork of Compound did not have a reentrancy guard on these specific functions (or the guard was bypassed), the attacker could recursively call the contract to drain funds.
|
|
23
|
+
|
|
24
|
+
## Attack Flow
|
|
25
|
+
1. Attacker deposited collateral into a Rari Fuse pool.
|
|
26
|
+
2. Attacker initiated a withdrawal of their collateral (ETH).
|
|
27
|
+
3. The `CEther` contract sent ETH to the attacker's malicious contract via a low-level call.
|
|
28
|
+
4. The attacker's fallback function triggered a call to borrow other assets from the same pool.
|
|
29
|
+
5. Because the collateral withdrawal was not yet finalized in the state, the protocol still saw the attacker as having full collateral, allowing the borrow to succeed.
|
|
30
|
+
6. The attacker effectively withdrew their collateral AND borrowed assets against it, leaving the pool with bad debt.
|
|
31
|
+
|
|
32
|
+
## Impact
|
|
33
|
+
- **Loss**: ~$80M
|
|
34
|
+
- **Protocol**: Rari Capital (Fuse)
|
|
35
|
+
- **Chain**: Ethereum
|
|
36
|
+
- **Date**: 2022-04-30
|
|
37
|
+
|
|
38
|
+
## Key Transactions
|
|
39
|
+
- Attack tx: `0xab4860125185a341599c543974807217b3911714771725567b746761632a2939`
|
|
40
|
+
|
|
41
|
+
## Detection Heuristics
|
|
42
|
+
- Pattern 1: Compound forks that lack reentrancy guards on `redeem`, `borrow`, or `exitMarket` functions.
|
|
43
|
+
- Pattern 2: External calls (especially ETH transfers) made before state updates in lending protocols.
|
|
44
|
+
|
|
45
|
+
## Remediation
|
|
46
|
+
- Fix 1: Apply the `nonReentrant` modifier to all functions that involve external calls or state changes.
|
|
47
|
+
- Fix 2: Use the Checks-Effects-Interactions pattern to ensure state is updated before any external interaction.
|
|
48
|
+
|
|
49
|
+
## References
|
|
50
|
+
- [rekt.news/rari-fuse-rekt/](https://rekt.news/rari-fuse-rekt/)
|
|
51
|
+
- [twitter.com/BlockSecTeam/status/1520351351111651328](https://twitter.com/BlockSecTeam/status/1520351351111651328)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ronin-bridge
|
|
3
|
+
description: "Case study of the 2022 Ronin Bridge exploit: compromised validator keys draining ~$625M"
|
|
4
|
+
category: reference
|
|
5
|
+
source_url: "https://rekt.news/ronin-rekt/"
|
|
6
|
+
source_license: "CC0"
|
|
7
|
+
imported_at: "2025-02-20T00:00:00Z"
|
|
8
|
+
detection_rules:
|
|
9
|
+
- regex: 'onlyValidator'
|
|
10
|
+
severity: "Low"
|
|
11
|
+
description: "Detects validator-only functions. While not a bug, it highlights the critical trust points in the system."
|
|
12
|
+
---
|
|
13
|
+
<!-- Source: rekt.news (CC0) -->
|
|
14
|
+
<!-- Source: SunWeb3Sec/DeFiHackLabs (Reference) -->
|
|
15
|
+
|
|
16
|
+
# Ronin Bridge (2022)
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
In March 2022, the Ronin Network, an Ethereum-linked sidechain for the Axie Infinity game, was exploited for 173,600 ETH and 25.5M USDC (worth ~$625M). This was not a smart contract bug but a social engineering attack that led to the compromise of 5 out of 9 validator private keys.
|
|
20
|
+
|
|
21
|
+
## Root Cause
|
|
22
|
+
The Ronin bridge required 5 out of 9 validator signatures to authorize withdrawals. The attacker (Lazarus Group) used a fake job offer to compromise a developer's computer, gaining access to 4 validator keys held by Sky Mavis. They also gained access to a 5th validator key held by the Axie DAO, which had been granted a temporary "allowance" to sign on behalf of Sky Mavis during a period of high traffic and was never revoked.
|
|
23
|
+
|
|
24
|
+
## Attack Flow
|
|
25
|
+
1. Attacker used social engineering (fake job interview/PDF) to plant malware on a Sky Mavis engineer's laptop.
|
|
26
|
+
2. Attacker extracted 4 validator private keys from Sky Mavis infrastructure.
|
|
27
|
+
3. Attacker discovered an RPC backdoor to the Axie DAO validator, which had been authorized to sign for Sky Mavis months earlier.
|
|
28
|
+
4. With 5 keys, the attacker had the supermajority needed to sign withdrawal transactions.
|
|
29
|
+
5. Attacker submitted two withdrawal transactions to the Ronin bridge on Ethereum, draining the funds.
|
|
30
|
+
|
|
31
|
+
## Impact
|
|
32
|
+
- **Loss**: ~$625M
|
|
33
|
+
- **Protocol**: Ronin Bridge (Sky Mavis)
|
|
34
|
+
- **Chain**: Ronin / Ethereum
|
|
35
|
+
- **Date**: 2022-03-23 (Discovered 2022-03-29)
|
|
36
|
+
|
|
37
|
+
## Key Transactions
|
|
38
|
+
- Withdrawal tx 1: `0xc28fad5e8d5e0ce6a2eaf67b6687be5d58113e16be590824d6cfa1a691f6d7b3`
|
|
39
|
+
- Withdrawal tx 2: `0xed2c1225a57b6811c570930c7e9996a8a18b19a472f5502013f80f53c7a32730`
|
|
40
|
+
|
|
41
|
+
## Detection Heuristics
|
|
42
|
+
- Pattern 1: Low validator count (centralization risk).
|
|
43
|
+
- Pattern 2: Long-standing "temporary" permissions or allowances in governance/bridge contracts.
|
|
44
|
+
|
|
45
|
+
## Remediation
|
|
46
|
+
- Fix 1: Increase the number of validators and the threshold for consensus (Ronin moved to 21 validators).
|
|
47
|
+
- Fix 2: Implement strict security protocols for validator key management (HSMs, multi-party computation).
|
|
48
|
+
- Fix 3: Regular audits of off-chain infrastructure and social engineering training for employees.
|
|
49
|
+
|
|
50
|
+
## References
|
|
51
|
+
- [rekt.news/ronin-rekt/](https://rekt.news/ronin-rekt/)
|
|
52
|
+
- [roninchain.com/blog/posts/community-alert-ronin-bridge-exploit-post-mortem](https://roninchain.com/blog/posts/community-alert-ronin-bridge-exploit-post-mortem)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wormhole-bridge
|
|
3
|
+
description: "Case study of the 2022 Wormhole Bridge exploit: missing signature validation draining ~$320M"
|
|
4
|
+
category: reference
|
|
5
|
+
source_url: "https://rekt.news/wormhole-rekt/"
|
|
6
|
+
source_license: "CC0"
|
|
7
|
+
imported_at: "2025-02-20T00:00:00Z"
|
|
8
|
+
detection_rules:
|
|
9
|
+
- regex: 'load_instruction_at'
|
|
10
|
+
severity: "High"
|
|
11
|
+
description: "Detects usage of deprecated or dangerous instruction loading in Solana programs which can be used to spoof sysvars."
|
|
12
|
+
---
|
|
13
|
+
<!-- Source: rekt.news (CC0) -->
|
|
14
|
+
<!-- Source: SunWeb3Sec/DeFiHackLabs (Reference) -->
|
|
15
|
+
|
|
16
|
+
# Wormhole Bridge (2022)
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
In February 2022, the Wormhole bridge was exploited for 120,000 wETH (worth ~$320M) on the Solana side. The attacker was able to bypass the signature verification process and mint wETH without providing any collateral on the Ethereum side.
|
|
20
|
+
|
|
21
|
+
## Root Cause
|
|
22
|
+
The vulnerability existed in the Wormhole's Solana program. Specifically, the `verify_signatures` function used a deprecated Solana system function `load_instruction_at` to verify the `instructions` sysvar. The attacker provided a spoofed sysvar account that mimicked the real sysvar but contained fake data, allowing them to bypass the signature check.
|
|
23
|
+
|
|
24
|
+
## Attack Flow
|
|
25
|
+
1. Attacker identified that the `verify_signatures` function did not properly validate the `instructions` sysvar account.
|
|
26
|
+
2. Attacker created a malicious account that mimicked the `instructions` sysvar.
|
|
27
|
+
3. Attacker called `post_vaa` with the spoofed sysvar, which made the program believe the signatures were valid.
|
|
28
|
+
4. Attacker then called `complete_wrapped_eth` to mint 120,000 wETH on Solana.
|
|
29
|
+
5. Attacker bridged some of the wETH back to Ethereum and swapped the rest on Solana.
|
|
30
|
+
|
|
31
|
+
## Impact
|
|
32
|
+
- **Loss**: ~$320M
|
|
33
|
+
- **Protocol**: Wormhole Bridge
|
|
34
|
+
- **Chain**: Solana / Ethereum
|
|
35
|
+
- **Date**: 2022-02-02
|
|
36
|
+
|
|
37
|
+
## Key Transactions
|
|
38
|
+
- Solana Attack tx: `2thJ77y986Yfs4S6996Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9` (Example representation)
|
|
39
|
+
- Mint tx: `399986Yfs4S6996Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9Yv9`
|
|
40
|
+
|
|
41
|
+
## Detection Heuristics
|
|
42
|
+
- Pattern 1: Use of `load_instruction_at` or other deprecated sysvar loading methods in Solana without proper account validation.
|
|
43
|
+
- Pattern 2: Missing checks to ensure that system accounts (like `sysvar::instructions`) are actually the official system accounts.
|
|
44
|
+
|
|
45
|
+
## Remediation
|
|
46
|
+
- Fix 1: Use the modern `get_instruction_relative` or properly validate the sysvar account address.
|
|
47
|
+
- Fix 2: Ensure all system accounts passed to the program are checked against their known addresses.
|
|
48
|
+
|
|
49
|
+
## References
|
|
50
|
+
- [rekt.news/wormhole-rekt/](https://rekt.news/wormhole-rekt/)
|
|
51
|
+
- [jumpcrypto.com/wormhole-exploit-post-mortem/](https://jumpcrypto.com/wormhole-exploit-post-mortem/)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: access-control
|
|
3
3
|
description: Access-control exploit patterns and secure authorization approaches for privileged Solidity functions.
|
|
4
|
+
pattern_category: access-control
|
|
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,19 @@ detection_rules:
|
|
|
14
15
|
confidence: Medium
|
|
15
16
|
swc: SWC-105
|
|
16
17
|
description: Inline sender authorization check on sensitive paths
|
|
18
|
+
- regex: 'function\s+initialize'
|
|
19
|
+
severity: Critical
|
|
20
|
+
confidence: High
|
|
21
|
+
description: Initializer function detected — if missing initializer modifier, anyone can take ownership
|
|
22
|
+
- regex: 'selfdestruct\(|suicide\('
|
|
23
|
+
severity: High
|
|
24
|
+
confidence: High
|
|
25
|
+
description: Contract uses selfdestruct — can destroy contract and send ETH to arbitrary address
|
|
26
|
+
- regex: 'function\s+\w+\s*\([^)]*\)\s+(external|public)'
|
|
27
|
+
severity: High
|
|
28
|
+
confidence: Low
|
|
29
|
+
swc: SWC-105
|
|
30
|
+
description: External/public function — verify appropriate access control modifiers are applied
|
|
17
31
|
---
|
|
18
32
|
|
|
19
33
|
<!-- Source: DeFiFoFum/fofum-solidity-skills (MIT) -->
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: arbitrary-storage-location
|
|
3
|
-
description: - Contract has a dynamic array in storage
|
|
3
|
+
description: '- Contract has a dynamic array in storage'
|
|
4
|
+
pattern_category: logic-error
|
|
5
|
+
detection_rules:
|
|
6
|
+
- regex: 'assembly\s*\{'
|
|
7
|
+
severity: Medium
|
|
8
|
+
confidence: Low
|
|
9
|
+
swc: SWC-124
|
|
10
|
+
description: Inline assembly context where arbitrary storage writes may occur
|
|
11
|
+
- regex: 'sstore\('
|
|
12
|
+
severity: High
|
|
13
|
+
confidence: Low
|
|
14
|
+
swc: SWC-124
|
|
15
|
+
description: Direct storage slot writes require strict slot provenance checks
|
|
4
16
|
---
|
|
5
17
|
<!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
|
|
6
18
|
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: assert-violation
|
|
3
|
-
description: - Contract uses `assert()` statements
|
|
3
|
+
description: '- Contract uses `assert()` statements'
|
|
4
|
+
pattern_category: logic-error
|
|
5
|
+
detection_rules:
|
|
6
|
+
- regex: 'assert\('
|
|
7
|
+
severity: Low
|
|
8
|
+
confidence: Medium
|
|
9
|
+
swc: SWC-110
|
|
10
|
+
description: assert used in code path that may be user reachable
|
|
4
11
|
---
|
|
5
12
|
<!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
|
|
6
13
|
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: asserting-contract-from-code-size
|
|
3
|
-
description: - Contract uses `extcodesize` or `address.code.length` to check whether an address is an EOA vs. a contract
|
|
3
|
+
description: '- Contract uses `extcodesize` or `address.code.length` to check whether an address is an EOA vs. a contract'
|
|
4
|
+
pattern_category: logic-error
|
|
5
|
+
detection_rules:
|
|
6
|
+
- regex: 'extcodesize'
|
|
7
|
+
severity: Medium
|
|
8
|
+
confidence: Medium
|
|
9
|
+
swc: SWC-113
|
|
10
|
+
description: extcodesize-based contract detection can be bypassed in constructors
|
|
11
|
+
- regex: 'isContract\('
|
|
12
|
+
severity: Medium
|
|
13
|
+
confidence: Medium
|
|
14
|
+
description: isContract helper usage should not gate security decisions
|
|
4
15
|
---
|
|
5
16
|
<!-- Source: kadenzipfel/smart-contract-vulnerabilities (MIT) -->
|
|
6
17
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: authorization-txorigin
|
|
3
|
-
description:
|
|
3
|
+
description: "Contract uses tx.origin for authorization or access control checks (e.g., require(tx.origin == owner))"
|
|
4
|
+
pattern_category: access-control
|
|
4
5
|
detection_rules:
|
|
5
6
|
- regex: 'tx\.origin'
|
|
6
7
|
severity: High
|
|
@@ -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: 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,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dos-revert
|
|
3
3
|
description: Denial-of-service attacks through unexpected reverts in external calls
|
|
4
|
+
pattern_category: dos
|
|
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"
|
|
@@ -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.
|