|
| 1 | +# Instadapp Fluid Liquidity Layer Security Audit Report |
| 2 | + |
| 3 | +###### tags: `instadapp`, `Fluid` |
| 4 | + |
| 5 | +## 1. INTRODUCTION |
| 6 | + |
| 7 | +### 1.1 Disclaimer |
| 8 | +The audit makes no statements or warranties regarding the utility, safety, or security of the code, the suitability of the business model, investment advice, endorsement of the platform or its products, the regulatory regime for the business model, or any other claims about the fitness of the contracts for a particular purpose or their bug-free status. |
| 9 | + |
| 10 | + |
| 11 | +### 1.2 Executive Summary |
| 12 | + |
| 13 | +Instadapp Fluid Liquidity Layer is a core DeFi protocol that serves as the central liquidity hub for the Fluid ecosystem. The protocol combines sophisticated liquidity management, interest rate calculations, and multi-protocol integration capabilities, enabling seamless interaction between various DeFi protocols including lending (fTokens), vaults, flashloans, and DEX operations. The system utilizes advanced mathematical libraries for precise calculations and implements a modular architecture with separate admin and user modules, all built on top of the Instadapp Infinite proxy pattern. |
| 14 | + |
| 15 | +The audit specifically examined changes made between commits `23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf` and `f5a07116967103946791dffd1fbafa71e0a60828` within the liquidity layer. The initial commit `f5a07116967103946791dffd1fbafa71e0a60828` wasn't audited by MixBytes. Vaults ZIRCUIT and ZtakingPool were out of scope. |
| 16 | + |
| 17 | +Key changes and attack vectors: |
| 18 | +* **New variables read/write correctness**: new storage variables were added: `usesConfigs2` in `_exchangePricesAndConfig`, `decayAmount` in `_userSupplyData`, `decayDurationCPs` in `_userSupplyData`, `maxUtilization` in `_configs2`: |
| 19 | + - We verified that the maximum size of the variables does not exceed their allocated slot boundaries, and that the variables are correctly read and written back via respective bit operations. |
| 20 | + - Additionally, it was verified that new variable storage writes are not overwritten by subsequent function calls. For example, in `updateTokenConfigs()`, the `usesConfigs2` is updated in `_exchangePricesAndConfig` storage slot, and then the function `_updateExchangePricesAndRates()` is called, which also modifies `_exchangePricesAndConfig` and it is correctly does not nullify the `usesConfigs2` slot in the storage. |
| 21 | +* **Reentrancy protection and DoS**: A new `safeTransferNative()` function was added with a gas limit of `20,000` for native token transfers. This amount should be sufficient for standard receive/fallback functions with event logging, but insufficient for heavy operations, providing partial protection against reentrancy attacks. This also means that integrations with the liquidity layer must avoid implementing complex logic in their receive/fallback functions, as this could lead to DoS where legitimate transfers fail due to gas exhaustion. |
| 22 | +* **Negative borrow rate checks**: The `calcRateV1()` and `calcRateV2()` functions were modified to change the `slope_` variable from `uint256` to `int256`. However, negative `slope_` cases (negative borrow rates) are prevented by a specific check. All calculations are wrapped in `unchecked` blocks, which is safe due to the limited size of variables participating in the calculations. There are some `int(uint(x)-uint(y))` subtractions, which would work the same as `int(int(x)-int(y))` due to `unchecked{}` clause. |
| 23 | +* **No storage collisions**: The new `maxUtilization` field in `TokenConfig` poses no risk, as the struct is not stored in contract storage, so no collisions can occur when the implementation is upgraded. |
| 24 | +* **Token decimals and code validation**: New validation functions `_checkIsContract()` and `_checkTokenDecimalsRange()` were added to the admin module. We verified that these functions are properly utilized across all admin functions where contract address validation and token decimal range validation are required. Note that these validations are not present in `updateTokenConfigs()`, however, this function cannot be called for a token that hasn't had `updateRateDataV1s()` or `updateRateDataV2s()` called first, which do contain these validation checks. |
| 25 | +* **Utilization above 100%**: A new validation was added to `updateTokenConfigs()` in `adminModule` for the case `maxUtilization > FOUR_DECIMALS` (i.e., prohibition on maximum utilization above 100%). |
| 26 | +* **Bit function correctness**: The `leastSignificantBit()` function was added to the `bigMathMinified` library. We verified it reverts on zero input, correctly counts trailing zeros using binary search with shifts and masks, and returns the 1-based bit position (1–256). Edge cases were validated (e.g., 1→1, 2→2, 2^255→256). |
| 27 | +* **User withdrawal limit validation**: The new `updateUserWithdrawalLimit()` function was tested for correct validation of arguments and the new limit and input parameters. |
| 28 | +* **Withdraw-decay mechanism:** verified arithmetic correctness, dust handling, linear decay across checkpoints (partial/full decay, off-by-one effect at boundaries), limit push-down on withdrawals (never exceeds remaining decay, correct handling of `notPushedDown` in max-expansion cases), addition of new decay on deposits (weighted duration blending, proper min/cap enforcement), edge cases (`before==0`, `withdrawLimitAfter==0`). |
| 29 | + |
| 30 | +Key notes and recommendations: |
| 31 | +* We recommend adding more tests for the new features — negative slopes in rate calculations, net transfers, etc. |
| 32 | + |
| 33 | +### 1.3 Project Overview |
| 34 | + |
| 35 | +#### Summary |
| 36 | + |
| 37 | +Title | Description |
| 38 | +--- | --- |
| 39 | +Client Name| Instadapp |
| 40 | +Project Name| Fluid Liquidity Layer |
| 41 | +Type| Solidity |
| 42 | +Platform| EVM |
| 43 | +Timeline| 09.09.2025 - 10.12.2025 |
| 44 | + |
| 45 | +#### Scope of Audit |
| 46 | + |
| 47 | +File | Link |
| 48 | +--- | --- |
| 49 | +contracts/libraries/bigMathMinified.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/libraries/bigMathMinified.sol |
| 50 | +contracts/libraries/liquidityCalcs.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/libraries/liquidityCalcs.sol |
| 51 | +contracts/libraries/liquiditySlotsLink.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/libraries/liquiditySlotsLink.sol |
| 52 | +contracts/libraries/safeTransfer.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/libraries/safeTransfer.sol |
| 53 | +contracts/liquidity/adminModule/main.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/adminModule/main.sol |
| 54 | +contracts/liquidity/adminModule/structs.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/adminModule/structs.sol |
| 55 | +contracts/liquidity/adminModule/events.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/adminModule/events.sol |
| 56 | +contracts/liquidity/common/variables.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/common/variables.sol |
| 57 | +contracts/liquidity/common/helpers.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/common/helpers.sol |
| 58 | +contracts/liquidity/userModule/main.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/userModule/main.sol |
| 59 | +contracts/liquidity/userModule/events.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/userModule/events.sol |
| 60 | +contracts/liquidity/errorTypes.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/errorTypes.sol |
| 61 | +contracts/liquidity/proxy.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/proxy.sol |
| 62 | +contracts/liquidity/dummyImpl.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/dummyImpl.sol |
| 63 | +contracts/liquidity/error.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/error.sol |
| 64 | +contracts/liquidity/interfaces/iLiquidity.sol | https://github.com/Instadapp/fluid-contracts/blob/23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf/contracts/liquidity/interfaces/iLiquidity.sol |
| 65 | + |
| 66 | +*** |
| 67 | +#### Versions Log |
| 68 | + |
| 69 | +Date | Commit Hash | Note |
| 70 | +-------------------------------------------| --- | --- |
| 71 | +09.09.2025 | 23692b02dc20aa87aa59f2bcd8bb8ec4ad9234bf | Initial Commit |
| 72 | +09.12.2025 | 298c84e3daa9505457cf22265e5c4a8927d7e8c9 | Commit for re-audit |
| 73 | +10.12.2025 | 5bd3d775f67d8f8d731c58a3852cdf044b86795b | Commit for re-audit |
| 74 | + |
| 75 | +#### Mainnet Deployments |
| 76 | + |
| 77 | +File| Address | Blockchain | Comment |
| 78 | +--- | --- | --- | --- |
| 79 | +(userModule) main.sol | [0xF1167F851509CA5Ef56f8521fB1EE07e4e5C92C8](https://etherscan.io/address/0xF1167F851509CA5Ef56f8521fB1EE07e4e5C92C8) | Ethereum Mainnet | L1 and L2 were introduced |
| 80 | +(adminModule) main.sol | [0x53EFFA0e612d88f39Ab32eb5274F2fae478d261C](https://etherscan.io/address/0x53EFFA0e612d88f39Ab32eb5274F2fae478d261C) | Ethereum Mainnet | L1 and L2 were introduced |
| 81 | + |
| 82 | + |
| 83 | +### 1.4 Security Assessment Methodology |
| 84 | + |
| 85 | +#### Project Flow |
| 86 | + |
| 87 | +| **Stage** | **Scope of Work** | |
| 88 | +|-----------|------------------| |
| 89 | +| **Interim Audit** | **Project Architecture Review:**<br> - Review project documentation <br> - Conduct a general code review <br> - Perform reverse engineering to analyze the project’s architecture based solely on the source code <br> - Develop an independent perspective on the project’s architecture <br> - Identify any logical flaws in the design <br> **Objective:** Understand the overall structure of the project and identify potential security risks. | |
| 90 | +| **Interim Audit** | **Core Review with a Hacker Mindset:**<br> - Each team member independently conducts a manual code review, focusing on identifying unique vulnerabilities. <br> - Perform collaborative audits (pair auditing) of the most complex code sections, supervised by the Team Lead. <br> - Develop Proof-of-Concepts (PoCs) and conduct fuzzing tests using tools like Foundry, Hardhat, and BOA to uncover intricate logical flaws. <br> - Review test cases and in-code comments to identify potential weaknesses. <br> **Objective:** Identify and eliminate the majority of vulnerabilities, including those unique to the industry. | |
| 91 | +| **Interim Audit** | **Code Review with a Nerd Mindset:**<br> - Conduct a manual code review using an internally maintained checklist, regularly updated with insights from past hacks, research, and client audits. <br> - Utilize static analysis tools (e.g., Slither, Mythril) and vulnerability databases (e.g., Solodit) to uncover potential undetected attack vectors. <br> **Objective:** Ensure comprehensive coverage of all known attack vectors during the review process. | |
| 92 | +| **Interim Audit** | **Consolidation of Auditors' Reports:**<br> - Cross-check findings among auditors <br> - Discuss identified issues <br> - Issue an interim audit report for client review <br> **Objective:** Combine interim reports from all auditors into a single comprehensive document. | |
| 93 | +| **Re-Audit** | **Bug Fixing & Re-Audit:**<br> - The client addresses the identified issues and provides feedback. <br> - Auditors verify the fixes and update their statuses with supporting evidence. <br> - A re-audit report is generated and shared with the client. <br> **Objective:** Validate the fixes and reassess the code to ensure all vulnerabilities are resolved and no new vulnerabilities are added. | |
| 94 | +| **Final Audit** | **Final Code Verification & Public Audit Report:**<br> - Verify the final code version against recommendations and their statuses. <br> - Check deployed contracts for correct initialization parameters. <br> - Confirm that the deployed code matches the audited version. <br> - Issue a public audit report, published on our official GitHub repository. <br> - Announce the successful audit on our official X account. <br> **Objective:** Perform a final review and issue a public report documenting the audit. | |
| 95 | + |
| 96 | +### 1.5 Risk Classification |
| 97 | + |
| 98 | +#### Severity Level Matrix |
| 99 | + |
| 100 | +| Severity | Impact: High | Impact: Medium | Impact: Low | |
| 101 | +|-----------|-------------|---------------|-------------| |
| 102 | +| **Likelihood: High** | Critical | High | Medium | |
| 103 | +| **Likelihood: Medium** | High | Medium | Low | |
| 104 | +| **Likelihood: Low** | Medium | Low | Low | |
| 105 | + |
| 106 | +#### Impact |
| 107 | + |
| 108 | +- **High** – Theft from 0.5% OR partial/full blocking of funds (>0.5%) on the contract without the possibility of withdrawal OR loss of user funds (>1%) who interacted with the protocol. |
| 109 | +- **Medium** – Contract lock that can only be fixed through a contract upgrade OR one-time theft of rewards or an amount up to 0.5% of the protocol's TVL OR funds lock with the possibility of withdrawal by an admin. |
| 110 | +- **Low** – One-time contract lock that can be fixed by the administrator without a contract upgrade. |
| 111 | + |
| 112 | +#### Likelihood |
| 113 | + |
| 114 | +- **High** – The event has a 50-60% probability of occurring within a year and can be triggered by any actor (e.g., due to a likely market condition that the actor cannot influence). |
| 115 | +- **Medium** – An unlikely event (10-20% probability of occurring) that can be triggered by a trusted actor. |
| 116 | +- **Low** – A highly unlikely event that can only be triggered by the owner. |
| 117 | + |
| 118 | +#### Action Required |
| 119 | + |
| 120 | +- **Critical** – Must be fixed as soon as possible. |
| 121 | +- **High** – Strongly advised to be fixed to minimize potential risks. |
| 122 | +- **Medium** – Recommended to be fixed to enhance security and stability. |
| 123 | +- **Low** – Recommended to be fixed to improve overall robustness and effectiveness. |
| 124 | + |
| 125 | +#### Finding Status |
| 126 | + |
| 127 | +- **Fixed** – The recommended fixes have been implemented in the project code and no longer impact its security. |
| 128 | +- **Partially Fixed** – The recommended fixes have been partially implemented, reducing the impact of the finding, but it has not been fully resolved. |
| 129 | +- **Acknowledged** – The recommended fixes have not yet been implemented, and the finding remains unresolved or does not require code changes. |
| 130 | + |
| 131 | +### 1.6 Summary of Findings |
| 132 | + |
| 133 | +#### Findings Count |
| 134 | + |
| 135 | +| Severity | Count | |
| 136 | +|-----------|-------| |
| 137 | +| **Critical** | 0 | |
| 138 | +| **High** | 0 | |
| 139 | +| **Medium** | 0 | |
| 140 | +| **Low** | 2 | |
| 141 | + |
| 142 | +## 2. Findings Report |
| 143 | + |
| 144 | +### 2.1 Critical |
| 145 | + |
| 146 | +Not found. |
| 147 | + |
| 148 | +--- |
| 149 | + |
| 150 | +### 2.2 High |
| 151 | + |
| 152 | +Not found. |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +### 2.3 Medium |
| 157 | + |
| 158 | +Not found. |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | + |
| 163 | +### 2.4 Low |
| 164 | + |
| 165 | +#### 1. Potential ETH Loss Risk due to `MAX_INPUT_AMOUNT_EXCESS` Increase to 1000% in the Liquidity Layer |
| 166 | +##### Status |
| 167 | +Acknowledged |
| 168 | + |
| 169 | +##### Description |
| 170 | +`MAX_INPUT_AMOUNT_EXCESS` in the liquidity layer was increased from 1% to 1000%, which creates a risk of ETH loss for the user: |
| 171 | +- https://github.com/Instadapp/fluid-contracts/blob/298c84e3daa9505457cf22265e5c4a8927d7e8c9/contracts/liquidity/userModule/main.sol#L637 |
| 172 | +<br/> |
| 173 | +##### Recommendation |
| 174 | +We recommend refunding excess ETH to the user. |
| 175 | + |
| 176 | +> **Client's Commentary:** |
| 177 | +> Indeed, but note that this only happens for DEX V2 net transfers, where DEX V2 handles the interaction so that excess shouldn’t be possible in the first place. Any excess from the user is sent back to the user at the DEX V2 protocol level. |
| 178 | +
|
| 179 | +--- |
| 180 | + |
| 181 | + |
| 182 | +#### 2. Missed `preTransferOut()` |
| 183 | +##### Status |
| 184 | +Fixed in https://github.com/Instadapp/fluid-contracts/commit/5bd3d775f67d8f8d731c58a3852cdf044b86795b |
| 185 | + |
| 186 | +##### Description |
| 187 | + |
| 188 | +The `preTransferOut()` hook was missed for two safe transfers: |
| 189 | +- https://github.com/Instadapp/fluid-contracts/blob/298c84e3daa9505457cf22265e5c4a8927d7e8c9/contracts/liquidity/userModule/main.sol#L1092 |
| 190 | +- https://github.com/Instadapp/fluid-contracts/blob/298c84e3daa9505457cf22265e5c4a8927d7e8c9/contracts/liquidity/userModule/main.sol#L1115 |
| 191 | +<br/> |
| 192 | +##### Recommendation |
| 193 | + |
| 194 | +We recommend calling the hook in the aforementioned cases. |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +## 3. About MixBytes |
| 199 | + |
| 200 | +MixBytes is a leading provider of smart contract audit and research services, helping blockchain projects enhance security and reliability. Since its inception, MixBytes has been committed to safeguarding the Web3 ecosystem by delivering rigorous security assessments and cutting-edge research tailored to DeFi projects. |
| 201 | + |
| 202 | +Our team comprises highly skilled engineers, security experts, and blockchain researchers with deep expertise in formal verification, smart contract auditing, and protocol research. With proven experience in Web3, MixBytes combines in-depth technical knowledge with a proactive security-first approach. |
| 203 | + |
| 204 | +#### Why MixBytes? |
| 205 | + |
| 206 | +- **Proven Track Record:** Trusted by top-tier blockchain projects like Lido, Aave, Curve, and others, MixBytes has successfully audited and secured billions in digital assets. |
| 207 | +- **Technical Expertise:** Our auditors and researchers hold advanced degrees in cryptography, cybersecurity, and distributed systems. |
| 208 | +- **Innovative Research:** Our team actively contributes to blockchain security research, sharing knowledge with the community. |
| 209 | + |
| 210 | +#### Our Services |
| 211 | +- **Smart Contract Audits:** A meticulous security assessment of DeFi protocols to prevent vulnerabilities before deployment. |
| 212 | +- **Blockchain Research:** In-depth technical research and security modeling for Web3 projects. |
| 213 | +- **Custom Security Solutions:** Tailored security frameworks for complex decentralized applications and blockchain ecosystems. |
| 214 | + |
| 215 | +MixBytes is dedicated to securing the future of blockchain technology by delivering unparalleled security expertise and research-driven solutions. Whether you are launching a DeFi protocol or developing an innovative dApp, we are your trusted security partner. |
| 216 | + |
| 217 | + |
| 218 | +### Contact Information |
| 219 | + |
| 220 | +- [**Website**](https://mixbytes.io/) |
| 221 | +- [**GitHub**](https://github.com/mixbytes/audits_public) |
| 222 | +- [**X**](https://x.com/MixBytes) |
| 223 | + |
0 commit comments