solidity-argus 0.1.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 (131) hide show
  1. package/AGENTS.md +37 -0
  2. package/LICENSE +21 -0
  3. package/README.md +249 -0
  4. package/package.json +43 -0
  5. package/skills/INVENTORY.md +79 -0
  6. package/skills/README.md +56 -0
  7. package/skills/checklists/cyfrin-best-practices-runtime/SKILL.md +424 -0
  8. package/skills/checklists/cyfrin-best-practices-upgrades/SKILL.md +157 -0
  9. package/skills/checklists/cyfrin-defi-core/SKILL.md +373 -0
  10. package/skills/checklists/cyfrin-defi-integrations/SKILL.md +412 -0
  11. package/skills/checklists/cyfrin-gas/SKILL.md +55 -0
  12. package/skills/checklists/general-audit/SKILL.md +433 -0
  13. package/skills/methodology/audit-workflow/SKILL.md +129 -0
  14. package/skills/methodology/report-template/SKILL.md +190 -0
  15. package/skills/methodology/severity-classification/SKILL.md +179 -0
  16. package/skills/protocol-patterns/amm-dex/SKILL.md +229 -0
  17. package/skills/protocol-patterns/bridges-cross-chain/SKILL.md +317 -0
  18. package/skills/protocol-patterns/dao-governance/SKILL.md +281 -0
  19. package/skills/protocol-patterns/lending-borrowing/SKILL.md +221 -0
  20. package/skills/protocol-patterns/staking-vesting/SKILL.md +247 -0
  21. package/skills/references/exploit-reference/SKILL.md +259 -0
  22. package/skills/references/smartbugs-examples/SKILL.md +296 -0
  23. package/skills/vulnerability-patterns/access-control/SKILL.md +298 -0
  24. package/skills/vulnerability-patterns/arbitrary-storage-location/SKILL.md +59 -0
  25. package/skills/vulnerability-patterns/assert-violation/SKILL.md +59 -0
  26. package/skills/vulnerability-patterns/asserting-contract-from-code-size/SKILL.md +61 -0
  27. package/skills/vulnerability-patterns/authorization-txorigin/SKILL.md +55 -0
  28. package/skills/vulnerability-patterns/default-visibility/SKILL.md +62 -0
  29. package/skills/vulnerability-patterns/delegatecall-untrusted-callee/SKILL.md +60 -0
  30. package/skills/vulnerability-patterns/dos-gas-limit/SKILL.md +59 -0
  31. package/skills/vulnerability-patterns/dos-revert/SKILL.md +72 -0
  32. package/skills/vulnerability-patterns/flash-loan-attacks/SKILL.md +249 -0
  33. package/skills/vulnerability-patterns/floating-pragma/SKILL.md +51 -0
  34. package/skills/vulnerability-patterns/hash-collision/SKILL.md +52 -0
  35. package/skills/vulnerability-patterns/inadherence-to-standards/SKILL.md +61 -0
  36. package/skills/vulnerability-patterns/incorrect-constructor/SKILL.md +60 -0
  37. package/skills/vulnerability-patterns/incorrect-inheritance-order/SKILL.md +59 -0
  38. package/skills/vulnerability-patterns/insufficient-gas-griefing/SKILL.md +61 -0
  39. package/skills/vulnerability-patterns/lack-of-precision/SKILL.md +61 -0
  40. package/skills/vulnerability-patterns/logic-errors/SKILL.md +333 -0
  41. package/skills/vulnerability-patterns/missing-protection-signature-replay/SKILL.md +60 -0
  42. package/skills/vulnerability-patterns/msgvalue-loop/SKILL.md +66 -0
  43. package/skills/vulnerability-patterns/off-by-one/SKILL.md +67 -0
  44. package/skills/vulnerability-patterns/oracle-manipulation/SKILL.md +252 -0
  45. package/skills/vulnerability-patterns/outdated-compiler-version/SKILL.md +65 -0
  46. package/skills/vulnerability-patterns/overflow-underflow/SKILL.md +61 -0
  47. package/skills/vulnerability-patterns/reentrancy/SKILL.md +266 -0
  48. package/skills/vulnerability-patterns/shadowing-state-variables/SKILL.md +72 -0
  49. package/skills/vulnerability-patterns/signature-malleability/SKILL.md +59 -0
  50. package/skills/vulnerability-patterns/unbounded-return-data/SKILL.md +63 -0
  51. package/skills/vulnerability-patterns/unchecked-return-values/SKILL.md +52 -0
  52. package/skills/vulnerability-patterns/unencrypted-private-data-on-chain/SKILL.md +65 -0
  53. package/skills/vulnerability-patterns/unexpected-ecrecover-null-address/SKILL.md +61 -0
  54. package/skills/vulnerability-patterns/uninitialized-storage-pointer/SKILL.md +63 -0
  55. package/skills/vulnerability-patterns/unsafe-low-level-call/SKILL.md +56 -0
  56. package/skills/vulnerability-patterns/unsecure-signatures/SKILL.md +80 -0
  57. package/skills/vulnerability-patterns/unsupported-opcodes/SKILL.md +69 -0
  58. package/skills/vulnerability-patterns/unused-variables/SKILL.md +70 -0
  59. package/skills/vulnerability-patterns/use-of-deprecated-functions/SKILL.md +81 -0
  60. package/skills/vulnerability-patterns/weak-sources-randomness/SKILL.md +77 -0
  61. package/skills/vulnerability-patterns/weird-tokens/SKILL.md +294 -0
  62. package/src/agents/argus-prompt.ts +407 -0
  63. package/src/agents/pythia-prompt.ts +134 -0
  64. package/src/agents/scribe-prompt.ts +87 -0
  65. package/src/agents/sentinel-prompt.ts +133 -0
  66. package/src/cli/cli-program.ts +67 -0
  67. package/src/cli/commands/doctor.ts +83 -0
  68. package/src/cli/commands/init.ts +46 -0
  69. package/src/cli/commands/install.ts +55 -0
  70. package/src/cli/index.ts +13 -0
  71. package/src/cli/tui-prompts.ts +75 -0
  72. package/src/cli/types.ts +9 -0
  73. package/src/config/index.ts +3 -0
  74. package/src/config/loader.ts +36 -0
  75. package/src/config/schema.ts +82 -0
  76. package/src/config/types.ts +4 -0
  77. package/src/constants/defaults.ts +6 -0
  78. package/src/create-hooks.ts +84 -0
  79. package/src/create-managers.ts +26 -0
  80. package/src/create-tools.ts +30 -0
  81. package/src/features/audit-enforcer/audit-enforcer.ts +34 -0
  82. package/src/features/audit-enforcer/index.ts +1 -0
  83. package/src/features/background-agent/background-manager.ts +200 -0
  84. package/src/features/background-agent/index.ts +1 -0
  85. package/src/features/context-monitor/context-monitor.ts +48 -0
  86. package/src/features/context-monitor/index.ts +4 -0
  87. package/src/features/context-monitor/tool-output-truncator.ts +17 -0
  88. package/src/features/error-recovery/index.ts +2 -0
  89. package/src/features/error-recovery/session-recovery.ts +27 -0
  90. package/src/features/error-recovery/tool-error-recovery.ts +35 -0
  91. package/src/features/index.ts +5 -0
  92. package/src/features/persistent-state/audit-state-manager.ts +121 -0
  93. package/src/features/persistent-state/index.ts +1 -0
  94. package/src/hooks/compaction-hook.ts +50 -0
  95. package/src/hooks/config-handler.ts +116 -0
  96. package/src/hooks/event-hook-v2.ts +93 -0
  97. package/src/hooks/event-hook.ts +74 -0
  98. package/src/hooks/hook-system.ts +9 -0
  99. package/src/hooks/index.ts +5 -0
  100. package/src/hooks/knowledge-sync-hook.ts +57 -0
  101. package/src/hooks/safe-create-hook.ts +15 -0
  102. package/src/hooks/system-prompt-hook.ts +126 -0
  103. package/src/hooks/tool-tracking-hook.ts +234 -0
  104. package/src/hooks/types.ts +16 -0
  105. package/src/index.ts +36 -0
  106. package/src/knowledge/scvd-client.ts +242 -0
  107. package/src/knowledge/scvd-index.ts +183 -0
  108. package/src/knowledge/scvd-sync.ts +85 -0
  109. package/src/managers/index.ts +1 -0
  110. package/src/managers/types.ts +85 -0
  111. package/src/plugin-interface.ts +38 -0
  112. package/src/shared/binary-utils.ts +63 -0
  113. package/src/shared/deep-merge.ts +71 -0
  114. package/src/shared/file-utils.ts +56 -0
  115. package/src/shared/index.ts +5 -0
  116. package/src/shared/jsonc-parser.ts +39 -0
  117. package/src/shared/logger.ts +36 -0
  118. package/src/state/audit-state.ts +27 -0
  119. package/src/state/finding-store.ts +126 -0
  120. package/src/state/plugin-state.ts +14 -0
  121. package/src/state/types.ts +61 -0
  122. package/src/tools/contract-analyzer-tool.ts +184 -0
  123. package/src/tools/forge-fuzz-tool.ts +311 -0
  124. package/src/tools/forge-test-tool.ts +397 -0
  125. package/src/tools/pattern-checker-tool.ts +337 -0
  126. package/src/tools/report-generator-tool.ts +308 -0
  127. package/src/tools/slither-tool.ts +465 -0
  128. package/src/tools/solodit-search-tool.ts +131 -0
  129. package/src/tools/sync-knowledge-tool.ts +116 -0
  130. package/src/utils/project-detector.ts +133 -0
  131. package/src/utils/solidity-parser.ts +174 -0
@@ -0,0 +1,373 @@
1
+ ---
2
+ name: cyfrin-defi-core
3
+ description: Cyfrin DeFi checklist covering attacker mindset and protocol-level DeFi primitives
4
+ ---
5
+ <!-- Source: Cyfrin/audit-checklist -->
6
+ <!-- Auto-generated from https://github.com/Cyfrin/audit-checklist -->
7
+ <!-- Total items: 151 -->
8
+
9
+ # Cyfrin Audit Checklist — DeFi Security (Core)
10
+
11
+ DeFi-specific checklist items from [Cyfrin's audit checklist](https://github.com/Cyfrin/audit-checklist).
12
+
13
+ Covers: AMM/swap, flash loans, lending, liquid staking, oracles, staking, token standards (ERC20/721/1155), price manipulation, front-running, sandwich attacks, donation attacks, and protocol integrations (AAVE, Compound, Balancer, Chainlink, LayerZero, Uniswap, Gnosis Safe).
14
+
15
+ ## Checklist Items
16
+
17
+ ### Attacker's Mindset > Donation Attack
18
+
19
+ - [ ] **[SOL-AM-DA-1]** Does the protocol rely on `balance` or `balanceOf` instead of internal accounting?
20
+ - Attackers can manipulate the accounting by donating tokens.
21
+ - **Remediation:** Implement internal accounting instead of relying on `balanceOf` natively.
22
+ - **References:**
23
+ - https://solodit.xyz/issues/h-02-first-depositor-can-break-minting-of-shares-code4rena-prepo-prepo-contest-git
24
+
25
+ ### Attacker's Mindset > Front-running Attack
26
+
27
+ - [ ] **[SOL-AM-FrA-1]** Are "get-or-create" patterns protected against front-running attacks?
28
+ - Functions combining resource creation and interaction (like getOrCreateAndUse) are vulnerable to front-running attacks where attackers can create the resource with different parameters before the victim, potentially manipulating prices or conditions.
29
+ - **Remediation:** Separate creation and interaction into distinct transactions or implement robust protections (parameter validation, relative references instead of absolute values) to ensure safe operation regardless of creation timing.
30
+ - **References:**
31
+ - https://solodit.cyfrin.io/issues/h-03-fillorder-executor-can-be-front-run-by-the-order-creator-by-changing-orders-limitprice_e36-the-executors-assets-can-be-stolen-code4rena-init-capital-init-capital-git
32
+ - https://solodit.cyfrin.io/issues/m-01-routergetorcreatepoolandaddliquidity-can-be-frontrunned-which-leads-to-price-manipulation-code4rena-maverick-maverick-git
33
+
34
+ - [ ] **[SOL-AM-FrA-2]** Are two-transaction actions designed to be safe from frontrunning?
35
+ - Actions that require two separate transactions may be at risk of frontrunning, where an attacker can intervene between the two calls.
36
+ - **Remediation:** Ensure critical actions that are split across multiple transactions cannot be interfered with by attackers. This can involve checks or locks between the transactions.
37
+ - **References:**
38
+ - https://github.com/sherlock-audit/2022-11-isomorph-judging/issues/47
39
+
40
+ - [ ] **[SOL-AM-FrA-3]** Can users maliciously cause others' transactions to revert by preempting with dust?
41
+ - Attackers may cause legitimate transactions to fail by front-running with transactions of negligible amounts.
42
+ - **Remediation:** Implement checks to prevent transactions with non-material amounts from affecting the contract's state or execution flow.
43
+ - **References:**
44
+ - https://solodit.xyz/issues/m-12-attacker-can-grift-syndicate-staking-by-staking-a-small-amount-code4rena-stakehouse-protocol-lsd-network-stakehouse-contest-git
45
+
46
+ - [ ] **[SOL-AM-FrA-4]** Is the protocol using a properly user-bound commit-reveal scheme?
47
+ - Sensitive on-chain actions can be exposed in the mempool, enabling frontrunning and information exploitation. Effective commit-reveal schemes must bind commitments to specific users and transactions.
48
+ - **Remediation:** Implement a two-phase process where users first commit a hash containing their address and all transaction parameters, then reveal actual actions after the commitment phase ends, preventing frontrunning and information leakage.
49
+ - **References:**
50
+ - https://solodit.cyfrin.io/issues/h01-votes-can-be-duplicated-openzeppelin-uma-audit-phase-1-markdown
51
+ - https://solodit.cyfrin.io/issues/ethregistrarcontrollerregister-is-vulnerable-to-front-running-fixed-consensys-ens-permanent-registrar-markdown
52
+
53
+ ### Attacker's Mindset > Price Manipulation Attack
54
+
55
+ - [ ] **[SOL-AM-PMA-1]** Is the price calculated by the ratio of token balances?
56
+ - Price can be manipulated via flash loans or donations if it is derived from the ratio of token balances.
57
+ - **Remediation:** Use the Chainlink oracles for the asset prices.
58
+ - **References:**
59
+ - https://solodit.xyz/issues/h-05-flash-loan-price-manipulation-in-purchasepyroflan-code4rena-behodler-behodler-contest-git
60
+ - https://solodit.xyz/issues/h-05-underlying-assets-stealing-in-autopxgmx-and-autopxglp-via-share-price-manipulation-code4rena-redacted-cartel-redacted-cartel-contest-git
61
+ - https://solodit.xyz/issues/h-02-use-of-slot0-to-get-sqrtpricelimitx96-can-lead-to-price-manipulation-code4rena-maia-dao-ecosystem-maia-dao-ecosystem-git
62
+
63
+ - [ ] **[SOL-AM-PMA-2]** Is the price calculated from DEX liquidity pool spot prices?
64
+ - Spot price readings derived directly from DEX liquidity pools are vulnerable to manipulation through flash loans that can temporarily drain the pools.
65
+ - **Remediation:** Use TWAP (time-weighted average price) with appropriate time windows based on asset volatility and liquidity, or use reliable oracle solutions.
66
+ - **References:**
67
+ - https://solodit.cyfrin.io/issues/h-08-omooracle-getliquidityamounts-uses-spot-price-making-it-manipulatable-pashov-audit-group-none-omo_2025-01-25-markdown
68
+ - https://solodit.cyfrin.io/issues/h-03-the-use-of-spot-price-by-coresaltyfeed-can-lead-to-price-manipulation-and-undesired-liquidations-code4rena-saltyio-saltyio-git
69
+
70
+ ### Attacker's Mindset > Sandwich Attack
71
+
72
+ - [ ] **[SOL-AM-SandwichAttack-1]** Does the protocol have an explicit slippage protection on user interactions?
73
+ - An attacker can monitor the mempool and puts two transactions before and after the user's transaction. For example, when an attacker spots a large trade, executes their own trade first to manipulate the price, and then profits by closing their position after the user's trade is executed.
74
+ - **Remediation:** Allow users to specify the minimum output amount and revert the transaction if it is not satisfied.
75
+ - **References:**
76
+ - https://solodit.xyz/issues/h-12-sandwich-attack-to-accruepremiumandexpireprotections-sherlock-carapace-carapace-git
77
+ - https://solodit.xyz/issues/h-1-adversary-can-sandwich-oracle-updates-to-exploit-vault-sherlock-olympus-olympus-update-git
78
+
79
+ ### Defi > AMM/Swap
80
+
81
+ - [ ] **[SOL-Defi-AS-1]** Is hardcoded slippage used?
82
+ - Using hardcoded slippage can lead to poor trades and freezing user funds during times of high volatility.
83
+ - **Remediation:** Allow users to specify the slippage parameter in the actual asset amount which was calculated off-chain.
84
+ - **References:**
85
+ - https://dacian.me/defi-slippage-attacks#heading-on-chain-slippage-calculation-can-be-manipulated
86
+
87
+ - [ ] **[SOL-Defi-AS-2]** Is there a deadline protection?
88
+ - Without deadline protection, user transactions are vulnerable to sandwich attacks.
89
+ - **Remediation:** Allow a user specify the deadline of the swap.
90
+ - **References:**
91
+ - https://defihacklabs.substack.com/p/solidity-security-lesson-6-defi-slippage?utm_source=profile&utm_medium=reader2
92
+
93
+ - [ ] **[SOL-Defi-AS-3]** Is there a validation check for protocol reserves?
94
+ - Protocols may face risks if reserves are not validated and can be lent out, affecting the system's solvency.
95
+ - **Remediation:** Ensure reserve validation logic is in place to safeguard the protocol's liquidity and overall health.
96
+ - **References:**
97
+ - https://github.com/sherlock-audit/2022-08-sentiment-judging/blob/main/122-M/1-report.md
98
+
99
+ - [ ] **[SOL-Defi-AS-4]** Does the AMM utilize forked code?
100
+ - Using forked code, especially from known projects like Uniswap, can introduce known vulnerabilities if not updated or audited properly.
101
+ - **Remediation:** Review the differences. Utilize tools such as contract-diff.xyz to compare and identify the origin of code snippets.
102
+
103
+ - [ ] **[SOL-Defi-AS-5]** Are there rounding issues in product constant formulas?
104
+ - Rounding issues in the formulas can lead to inaccuracies or imbalances in token swaps and liquidity provisions.
105
+ - **Remediation:** Review the mathematical operations in the AMM's formulas, ensuring they handle rounding appropriately without introducing vulnerabilities.
106
+
107
+ - [ ] **[SOL-Defi-AS-6]** Can arbitrary calls be made from user input?
108
+ - Allowing arbitrary calls based on user input can expose the contract to various vulnerabilities.
109
+ - **Remediation:** Validate and sanitize user inputs. Avoid executing arbitrary calls based solely on input data.
110
+
111
+ - [ ] **[SOL-Defi-AS-7]** Is there a mechanism in place to protect against excessive slippage?
112
+ - Without slippage protection, traders might experience unexpected losses due to large price deviations during a trade.
113
+ - **Remediation:** Incorporate a slippage parameter that users can set to limit their maximum acceptable slippage.
114
+
115
+ - [ ] **[SOL-Defi-AS-8]** Does the AMM properly handle tokens of varying decimal configurations and token types?
116
+ - If the AMM doesn't support tokens with varying decimals or types, it might lead to incorrect calculations and potential losses.
117
+ - **Remediation:** Ensure compatibility with tokens of varying decimal places and validate token types before processing them.
118
+
119
+ - [ ] **[SOL-Defi-AS-9]** Does the AMM support the fee-on-transfer tokens?
120
+ - Fee-on-transfer tokens can cause problems because the sending amount and the received amount do not match.
121
+ - **Remediation:** Ensure the fee-on-transfer tokens are handled correctly if they are supposed to be supported.
122
+
123
+ - [ ] **[SOL-Defi-AS-10]** Does the AMM support the rebasing tokens?
124
+ - Rebasing tokens can change the actual balance.
125
+ - **Remediation:** Ensure the rebasing tokens are handled correctly if they are supposed to be supported.
126
+
127
+ - [ ] **[SOL-Defi-AS-11]** Does the protocol calculate `minAmountOut` before a token swap?
128
+ - Protocols integrating AMMs should determine the `minAmountOut` prior to swaps to avoid unfavorable rates. The source of the rates and potential for manipulation should also be considered.
129
+ - **Remediation:** Ensure that the protocol calculates `minAmountOut` before executing swaps. If external oracles are used, validate their trustworthiness and consider potential vulnerabilities like sandwich attacks.
130
+ - **References:**
131
+ - https://blog.chain.link/guide-to-sandwich-attacks/
132
+
133
+ - [ ] **[SOL-Defi-AS-12]** Does the integrating contract verify the caller address in its callback functions?
134
+ - Callback functions can be manipulated if they don't validate the calling contract's address. This is especially crucial for functions like `swap()` that involve tokens or assets.
135
+ - **Remediation:** Implement checks in the callback functions to validate the address of the calling contract. Additionally, review the logic for any potential bypasses to this check.
136
+
137
+ - [ ] **[SOL-Defi-AS-13]** Is the slippage calculated on-chain?
138
+ - ON-chain slippage calculation can be manipulated.
139
+ - **Remediation:** Allow users to specify the slippage parameter in the actual asset amount which was calculated off-chain.
140
+ - **References:**
141
+ - https://dacian.me/defi-slippage-attacks#heading-on-chain-slippage-calculation-can-be-manipulated
142
+
143
+ - [ ] **[SOL-Defi-AS-14]** Is the slippage parameter enforced at the last step before transferring funds to users?
144
+ - Enforcing slippage parameters for intermediate swaps but not the final step can result in users receiving less tokens than their specified minimum
145
+ - **Remediation:** Enforce slippage parameter as the last step before transferring funds to users
146
+ - **References:**
147
+ - https://dacian.me/defi-slippage-attacks#heading-mintokensout-for-intermediate-not-final-amount
148
+
149
+ ### Defi > FlashLoan
150
+
151
+ - [ ] **[SOL-Defi-FlashLoan-1]** Is withdraw disabled in the same block to prevent flashloan attacks?
152
+ - Allowing withdrawals within the same block as other interactions may enable attackers to exploit flashloan vulnerabilities.
153
+ - **Remediation:** Implement a delay or disable withdrawals within the same block where a deposit or loan action took place to mitigate such risks.
154
+
155
+ - [ ] **[SOL-Defi-FlashLoan-2]** Can ERC4626 be manipulated through flashloans?
156
+ - ERC4626, the tokenized vault standard, could be susceptible to flashloan attacks if the underlying mechanisms do not adequately account for such threats.
157
+ - **Remediation:** Ensure that ERC4626-related operations have in-built protections against rapid, in-block actions that could be leveraged by flashloans.
158
+ - **References:**
159
+ - https://github.com/code-423n4/2022-01-behodler-findings/issues/304
160
+
161
+ ### Defi > General
162
+
163
+ - [ ] **[SOL-Defi-General-1]** Can the protocol handle ERC20 tokens with decimals other than 18?
164
+ - Not all ERC20 tokens use 18 decimals. Overlooking this can lead to computation errors.
165
+ - **Remediation:** Always check and adjust for the decimal count of the ERC20 tokens being handled.
166
+
167
+ - [ ] **[SOL-Defi-General-2]** Are there unexpected rewards accruing for user deposited assets?
168
+ - Some protocols or platforms may provide additional rewards for staked or deposited assets. If these rewards are not properly accounted for or managed, it could lead to discrepancies in the user's expected vs actual returns.
169
+ - **Remediation:** The protocol should have mechanisms in place to track all potential rewards for user deposited assets. Users should be provided with clear interfaces or methods to claim any unexpected rewards to ensure fairness and transparency.
170
+
171
+ - [ ] **[SOL-Defi-General-3]** Could direct transfers of funds introduce vulnerabilities?
172
+ - Direct transfers of assets without using the protocol's logic can lead to various problems in accounting especially if the accounting relies on `balanceOf` (or `address.balance`).
173
+ - **Remediation:** Implement the internal accounting so that it is not be affected by direct transfers.
174
+
175
+ - [ ] **[SOL-Defi-General-4]** Could the initial deposit introduce any issues?
176
+ - The first deposit can set certain parameters or conditions that subsequent deposits rely on.
177
+ - **Remediation:** Test and ensure that the first deposit initializes and sets all necessary parameters correctly.
178
+
179
+ - [ ] **[SOL-Defi-General-5]** Are the protocol token pegged to any other asset?
180
+ - The target tokens can be depegged.
181
+ - **Remediation:** Ensure the protocol behave as expected during the depeg.
182
+
183
+ - [ ] **[SOL-Defi-General-6]** Does the protocol revert on maximum approval to prevent over-allowance?
184
+ - Setting high allowances can make funds vulnerable to abuse; protocols sometimes set max to prevent this risk.
185
+ - **Remediation:** Consider implementing a revert on approval functions when an unnecessarily high allowance is set.
186
+ - **References:**
187
+ - https://solodit.xyz/issues/m-3-universalapprovemax-will-not-work-for-some-tokens-that-dont-support-approve-typeuint256max-amount-sherlock-dodo-dodo-git
188
+
189
+ - [ ] **[SOL-Defi-General-7]** What would happen if only 1 wei remains in the pool?
190
+ - Leaving residual amounts can lead to discrepancies in accounting or locked funds.
191
+ - **Remediation:** Implement logic to handle minimal residual amounts in the pool.
192
+
193
+ - [ ] **[SOL-Defi-General-8]** Is it possible to withdraw in the same transaction of deposit?
194
+ - Protocols often provide various benefits to the depositors based on the deposit amount. This can lead to flashloan-deposit-harvest-withdraw attack cycle.
195
+ - **Remediation:** Ensure the withdrawal is protected for some blocks after deposit.
196
+
197
+ - [ ] **[SOL-Defi-General-9]** Does the protocol aim to support ALL kinds of ERC20 tokens?
198
+ - Not all ERC20 tokens are compliant to the ERC20 standard and there are several weird ERC20 tokens (e.g. Fee-On-Transfer tokens, rebasing tokens, tokens with blacklisting).
199
+ - **Remediation:** Clarify what kind of tokens are supported and whitelist the ERC20 tokens that the protocol would accept.
200
+ - **References:**
201
+ - https://github.com/d-xo/weird-erc20
202
+
203
+ ### Defi > Lending
204
+
205
+ - [ ] **[SOL-Defi-Lending-1]** Will the liquidation process function effectively during rapid market downturns?
206
+ - Failure to liquidate positions during sharp price drops can result in substantial platform losses.
207
+ - **Remediation:** Ensure robustness during extreme market conditions.
208
+
209
+ - [ ] **[SOL-Defi-Lending-2]** Can a position be liquidated if the loan remains unpaid or if the collateral falls below the required threshold?
210
+ - If positions cannot be liquidated under these circumstances, it poses a risk to lenders who might not recover their funds.
211
+ - **Remediation:** Ensure a reliable mechanism for liquidating under-collateralized or defaulting loans to safeguard lenders.
212
+
213
+ - [ ] **[SOL-Defi-Lending-3]** Is it possible for a user to gain undue profit from self-liquidation?
214
+ - Self-liquidation profit loopholes can lead to potential system abuse and unintended financial consequences.
215
+ - **Remediation:** Audit and test self-liquidation mechanisms to prevent any exploitative behaviors.
216
+
217
+ - [ ] **[SOL-Defi-Lending-4]** If token transfers or collateral additions are temporarily paused, can a user still be liquidated, even if they intend to deposit more funds?
218
+ - Unexpected pauses can place users at risk of unwarranted liquidations, despite their willingness to increase collateral.
219
+ - **Remediation:** Implement safeguards that protect users from liquidation during operational pauses or interruptions.
220
+
221
+ - [ ] **[SOL-Defi-Lending-5]** If liquidations are temporarily suspended, what are the implications when they are resumed?
222
+ - Pausing liquidations can increase the solvency risk and lead to unpredictable behaviors upon resumption.
223
+ - **Remediation:** Outline clear protocols for pausing and resuming liquidations, ensuring solvency is maintained.
224
+
225
+ - [ ] **[SOL-Defi-Lending-6]** Is it possible for users to manipulate the system by front-running and slightly increasing their collateral to prevent liquidations?
226
+ - Lenders must be prevented from griefing via front-running the liquidation.
227
+ - **Remediation:** Ensure it is not possible to prevent liquidators by any means.
228
+
229
+ - [ ] **[SOL-Defi-Lending-7]** Are all positions, regardless of size, incentivized adequately for liquidation?
230
+ - Without proper incentives, small positions might be overlooked, leading to inefficiencies.
231
+ - **Remediation:** Ensure a balanced incentive structure that motivates liquidators to address positions of all sizes.
232
+
233
+ - [ ] **[SOL-Defi-Lending-8]** Is interest considered during Loan-to-Value (LTV) calculation?
234
+ - Omitting interest in LTV calculations can result in inaccurate credit assessments.
235
+ - **Remediation:** Include accrued interest in LTV calculations to maintain accurate and fair credit evaluations.
236
+ - **References:**
237
+ - https://solodit.xyz/issues/h-7-users-can-be-liquidated-prematurely-because-calculation-understates-value-of-underlying-position-sherlock-blueberry-blueberry-git
238
+
239
+ - [ ] **[SOL-Defi-Lending-9]** Can liquidation and repaying be enabled or disabled simultaneously?
240
+ - Protocols might need to ensure that liquidation and repaying mechanisms are either both active or inactive to maintain consistency.
241
+ - **Remediation:** Review protocol logic to allow or disallow liquidation and repaying functions collectively to avoid operational discrepancies.
242
+ - **References:**
243
+ - https://solodit.xyz/issues/m-2-liquidations-are-enabled-when-repayments-are-disabled-causing-borrowers-to-lose-funds-without-a-chance-to-repay-sherlock-blueberry-blueberry-git
244
+
245
+ - [ ] **[SOL-Defi-Lending-10]** Is it possible to lend and borrow the same token within a single transaction?
246
+ - Protocols that allow the same token to be lent and borrowed in a single transaction may be vulnerable to attacks that exploit rapid price inflation or flash loans to manipulate the system.
247
+ - **Remediation:** Protocols should implement constraints to prohibit the same token from being used in a lend and borrow action within the same block or transaction, reducing the risk of flash-loan attacks and other manipulative practices.
248
+
249
+ - [ ] **[SOL-Defi-Lending-11]** Is there a scenario where a liquidator might receive a lesser amount than anticipated?
250
+ - Discrepancies in liquidation returns can discourage liquidators and impact system stability.
251
+ - **Remediation:** Ensure a clear and consistent calculation mechanism for liquidation rewards.
252
+
253
+ - [ ] **[SOL-Defi-Lending-12]** Is it possible for a user to be in a condition where they cannot repay their loan?
254
+ - Certain scenarios or conditions might prevent a user from repaying their loan, causing them to be perpetually in debt. This can be due to factors such as excessive collateralization, high fees, fluctuating token values, or other unforeseen events.
255
+ - **Remediation:** Review the lending protocol's logic to ensure there are no conditions that could trap a user in perpetual debt. Implement safeguards to notify or protect users from taking actions that may lead to irrecoverable financial situations.
256
+
257
+ ### Defi > Liquid Staking Derivatives
258
+
259
+ - [ ] **[SOL-Defi-LSD-1]** Can a malicious validator front-run setting withdrawal credentials?
260
+ - A malicious Ethereum validator can betray a liquid staking protocol by front-running to first call `DepositContract::deposit` sending 1 ETH and passing their own withdrawal credentials; after the protocol's subsequent call succeeds the withdrawal credentials are not overwritten since only the "initial deposit" sets the withdrawals credentials while the second deposit is treated as a "top-up deposit". The malicious validator now controls 33 ether with 32 ether belonging to the protocol's users and has set their own withdrawal credentials instead of the protocol's withdrawal credentials.
261
+ - **Remediation:** The function which calls `DepositContract::deposit` should take as input `DepositContract.get_deposit_root` then check that the input deposit root matches the current one. This works as the current deposit root changes with every deposit.
262
+
263
+ - [ ] **[SOL-Defi-LSD-2]** Can the exchange rate repricing update be sandwich attacked to drain ETH from the protocol?
264
+ - Liquid staking protocols typically have their own liquid ERC20 token that accrues value against ETH as the protocol receives staking rewards; in the normal course of operations the exchange rate should continually be increasing as the protocol accrues rewards such that the protocol's ERC20 token can be exchanged for increasing amounts of ETH. If the protocol allows instant withdrawals, an attacker can perform a risk-free sandwich attack to drain ETH from the protocol by 1) front-running the exchange rate txn to deposit a large amount of ETH, 2) back-running to withdraw at the increased rate.
265
+ - **Remediation:** Don't allow instant withdrawals but use a withdrawal queue and run the repricing transaction through flashbots.
266
+
267
+ - [ ] **[SOL-Defi-LSD-3]** Can re-entrancy when ETH is sent during rewards/withdrawals or when NFTs are minted via `_safeMint` (to represent pending withdrawals) be used to drain the protocol's ETH?
268
+ - Re-entrancy vulnerabilties can often exist in the reward or withdrawal code of LSD protocols.
269
+ - **Remediation:** Always follow the Checks-Effects-Interactions pattern; sending ETH or minting NFTs via `_safeMint` should always happen after storage updates.
270
+
271
+ - [ ] **[SOL-Defi-LSD-4]** Can an arbitrary exchange rate be set when processing queued withdrawals?
272
+ - If an arbitrary exchange rate can be set when processing queued withdrawals this creates a subtle rug-pull vector of user withdrawals.
273
+ - **Remediation:** When withdrawals are processed the current exchange rate should be retrieved in the same way as when withdrawals are created.
274
+
275
+ - [ ] **[SOL-Defi-LSD-5]** Can paused states be bypassed to perform restricted actions even when they should be paused?
276
+ - LSD protocols often implement pausing of different functionality. Auditors should check if there are any gaps where for example one function is missing a pause check that other related functions contain.
277
+ - **Remediation:** All related functions should contain the same related pause checks.
278
+
279
+ - [ ] **[SOL-Defi-LSD-6]** Can inter-related storage be corrupted, especially storage related to operators and validators?
280
+ - To reduce the gas cost of reading from storage, protocols may use multiple inter-related data structures to store complex information like operator and validator information. Auditors should examine whether functions which update these inter-related data structures can be used to corrupt them by over-writing records which contain indexes into to another storage location.
281
+ - **Remediation:** Protocols can use invariant fuzz testing with invariants which validate that relationships between inter-related data structures can't be broken by functions which update them.
282
+
283
+ - [ ] **[SOL-Defi-LSD-7]** Does the protocol iterate over the entire set of operators or validators?
284
+ - LSD protocols may need to iterate over the entire set of operators or validators which can become exorbitantly expensive or lead to out of gas if the operator or validator set becomes large. In permissionless systems where anyone can create operators or validators this creates a denial of service attack vector.
285
+ - **Remediation:** Refactor to avoid needing to iterate over the entire operator/validator set. Alternatively only use a small and trusted set of operators/validators.
286
+
287
+ - [ ] **[SOL-Defi-LSD-8]** If using a Proof Of Reserves Oracle, does the protocol check for stale data?
288
+ - LSD protocols may use an external Proof of Reserves Oracle to fetch off-chain data for their current ETH reserves. If the protocol doesn't check how long ago the data was last updated it can process stale data as if it were fresh.
289
+ - **Remediation:** Check the time data was last updated against the Oracle's heartbeat and revert if the data is too old.
290
+
291
+ - [ ] **[SOL-Defi-LSD-9]** Does unnecessary precision loss occur in deposit, withdrawal or reward calculations?
292
+ - Mathematical calculations have to be performed in LSD protocol deposit, withdrawal and reward functions. Auditors should check for precision loss issues such as division before multiplication, rounding down to zero etc.
293
+ - **Remediation:** Don't perform division before multiplication, be aware of rounding down to zero, rounding direction, unsafe casting etc.
294
+
295
+ ### Defi > Oracle
296
+
297
+ - [ ] **[SOL-Defi-Oracle-1]** Is the Oracle using deprecated Chainlink functions?
298
+ - Usage of deprecated Chainlink functions like latestRoundData() might return stale or incorrect data, affecting the integrity of smart contracts.
299
+ - **Remediation:** Replace deprecated functions with the current recommended methods to ensure accurate data retrieval from oracles.
300
+ - **References:**
301
+ - https://github.com/code-423n4/2022-04-backd-findings/issues/17
302
+
303
+ - [ ] **[SOL-Defi-Oracle-2]** Is the returned price validated to be non-zero?
304
+ - Price feed might return zero and this must be handled as invalid.
305
+ - **Remediation:** Ensure the returned price is not zero.
306
+
307
+ - [ ] **[SOL-Defi-Oracle-3]** Is the price update time validated?
308
+ - Price feeds might not be supported in the future. To ensure accurate price usage, it's vital to regularly check the last update timestamp against a predefined delay.
309
+ - **Remediation:** Implement a mechanism to check the heartbeat of the price feed and compare it against a predefined maximum delay (`MAX_DELAY`). Adjust the `MAX_DELAY` variable based on the observed heartbeat.
310
+
311
+ - [ ] **[SOL-Defi-Oracle-4]** Is there a validation to check if the rollup sequencer is running?
312
+ - The rollup sequencer can become offline, which can lead to potential vulnerabilities due to stale price.
313
+ - **Remediation:** Utilize the sequencer uptime feed to confirm the sequencers are up.
314
+ - **References:**
315
+ - https://docs.chain.link/data-feeds/l2-sequencer-feeds
316
+
317
+ - [ ] **[SOL-Defi-Oracle-5]** Is the Oracle's TWAP period appropriately set?
318
+ - An inadequately set TWAP (Time-Weighted Average Price) period could be exploited to manipulate prices.
319
+ - **Remediation:** Adjust the TWAP period to a duration that mitigates the risk of manipulation while providing timely price updates.
320
+ - **References:**
321
+ - https://github.com/code-423n4/2022-06-canto-v2-findings/issues/124
322
+
323
+ - [ ] **[SOL-Defi-Oracle-6]** Is the desired price feed pair supported across all deployed chains?
324
+ - In multi-chain deployments, it's crucial to ensure the desired price feed pair is available and consistent across all chains.
325
+ - **Remediation:** Review the supported price feed pairs on all chains and ensure they are consistent.
326
+
327
+ - [ ] **[SOL-Defi-Oracle-7]** Is the heartbeat of the price feed suitable for the use case?
328
+ - A price feed heartbeat that's too slow might not be suitable for some use cases.
329
+ - **Remediation:** Assess the requirements of the use case and ensure the price feed heartbeat aligns with them.
330
+
331
+ - [ ] **[SOL-Defi-Oracle-8]** Are there any inconsistencies with decimal precision when using different price feeds?
332
+ - Different price feeds might have varying decimal precisions, which can lead to inaccuracies.
333
+ - **Remediation:** Ensure that the contract handles potential variations in decimal precision across different price feeds.
334
+
335
+ - [ ] **[SOL-Defi-Oracle-9]** Is the price feed address hard-coded?
336
+ - Hard-coded price feed addresses can be problematic, especially if they become deprecated or if they're not accurate in the first place.
337
+ - **Remediation:** Review and verify the hardcoded price feed addresses. Consider mechanisms to update the address if required in the future.
338
+
339
+ - [ ] **[SOL-Defi-Oracle-10]** What happens if oracle price updates are front-run?
340
+ - Oracle price updates can be front-run and cause various problems.
341
+ - **Remediation:** Ensure the protocol is not affected in the case where oracle price updates are front-run.
342
+ - **References:**
343
+ - https://blog.angle.money/angle-research-series-part-1-oracles-and-front-running-d75184abc67
344
+
345
+ - [ ] **[SOL-Defi-Oracle-11]** How does the system handle potential oracle reverts?
346
+ - Unanticipated oracle reverts can lead to Denial-Of-Service.
347
+ - **Remediation:** Implement try/catch blocks around oracle calls and have alternative strategies ready.
348
+
349
+ - [ ] **[SOL-Defi-Oracle-12]** Are the price feeds appropriate for the underlying assets?
350
+ - Using an ETH price feed for stETH or a BTC price feed for WBTC can introduce risks associated with the underlying assets deviating from their pegs.
351
+ - **Remediation:** Ensure that the price feeds accurately represent the underlying assets to address potential depeg risks.
352
+
353
+ - [ ] **[SOL-Defi-Oracle-13]** Is the contract vulnerable to oracle manipulation, especially using spot prices from AMMs?
354
+ - Reliance on AMM spot prices as oracles can be manipulated via flashloan.
355
+ - **Remediation:** Choose reliable and tamper-resistant oracle sources. Avoid using spot prices from AMMs directly without additional checks.
356
+
357
+ - [ ] **[SOL-Defi-Oracle-14]** How does the system address potential inaccuracies during flash crashes?
358
+ - During flash crashes, oracles might return inaccurate prices.
359
+ - **Remediation:** Implement checks to ensure that the price returned by the oracle lies within an expected range to guard against potential flash crash vulnerabilities.
360
+
361
+ ### Defi > Staking
362
+
363
+ - [ ] **[SOL-Defi-Staking-1]** Can a user amplify another user's time lock duration by stacking tokens on their behalf?
364
+ - If users can amplify time locks for others by stacking tokens, it may lead to unintended lock durations and potentially be exploited.
365
+ - **Remediation:** Implement strict checks and controls to prevent users from influencing the time locks of other users through token stacking.
366
+
367
+ - [ ] **[SOL-Defi-Staking-2]** Can the distribution of rewards be unduly delayed or prematurely claimed?
368
+ - Manipulation in the timing of reward distribution can adversely affect users and the protocol's intended incentives.
369
+ - **Remediation:** Implement time controls and constraints on reward distributions to maintain the protocol's intended behavior.
370
+
371
+ - [ ] **[SOL-Defi-Staking-3]** Are rewards up-to-date in all use-cases?
372
+ - The staking protocol often has a function to update the rewards (e.g. `updateRewards`) and sometimes it is used as a modifier. This update function MUST be called before all relevant operations.
373
+ - **Remediation:** Ensure the update reward function is called properly in all places where the reward is relevant.