Mitigation Audit | Folks Finance-logo

Mitigation Audit | Folks Finance

|

Folks Finance is a leading DeFi platform providing innovative tools for lending, borrowing, trading and managing digital assets, all in one place.

Status

Finished
Rewards Pool
$25,000
Vault TVL
To be determined
Started
27 August 2024
Ended
05 September 2024
Rewards Token
USDC
nSLOC
500
  • Triaged by Immunefi

  • PoC required

  • Vault program

Select the category you'd like to explore

Assets in Scope

Target
Type
Smart Contract - refactor: add extra checks to the math library
Added on
27 August 2024
Target
Type
Smart Contract - fix: check the available liquidity when withdrawing
Added on
27 August 2024
Target
Type
Smart Contract - fix: scale down the repay borrow amount by the liquidation bonus
Added on
27 August 2024
Target
Type
Smart Contract - fix: stable borrow balance increases
Added on
27 August 2024
Target
Type
Smart Contract - fix: reduce the loan type collateral used in by the liquidation fee
Added on
27 August 2024
Target
Type
Smart Contract - fix: cannot rebalance up to a lower stable rate
Added on
27 August 2024
Target
Type
Smart Contract - fix: cannot mix borrows when liquidating
Added on
27 August 2024
Target
Type
Smart Contract - fix: don’t use cached chainlink node decimals
Added on
27 August 2024
Target
Type
Smart Contract - fix: hanlde PythNode exponent which is less than -18
Added on
27 August 2024
Target
Type
Smart Contract - fix: outdated deposit interest rate
Added on
27 August 2024
Target
Type
Smart Contract - fix: check the loan is over-collateralised in the switch borrow type operation
Added on
27 August 2024
Target
Type
Smart Contract - fix: make retry and reverse message permissioned retry + can override the return message params
Added on
27 August 2024

Impacts in Scope

Proof of Concept (PoC) Requirements

A PoC, demonstrating the bug's impact, is required for this program and has to comply with the Immunefi PoC Guidelines and Rules.

Whitehat Educational Resources & Technical Info

  1. Design Overview for Cross-chain Lending Protocol: Link to Google Docs

  2. Operation lifecycle in cross-chain lending protocol: Link to Google Docs

  3. Formulae Used in Cross-chain Lending Protocol: Link to Google Docs

  4. Testnet for Cross-chain Lending Protocol: Link to Testnet

  5. Smart Contract README for Cross-chain Lending Protocol: Link to GitHub README

  6. Docs for Existing Folks Finance Products: Link to Folks Finance Docs

  7. Medium Articles: Link to Medium Articles

Is this an upgrade of an existing system? If so, which? And what are the main differences?

This is a new cross chain lending protocol that follows a similar model to our existing Algorand lending protocol. The loans and economic structure are the same with the only difference being how liquidations work. All the cross chain infrastructure is new.

The cross chain lending protocol also uses an oracle design from Synthetix which takes up less than 5% of the total codebase. The codebase language is fully Solidity.

Where do you suspect there may be bugs? Useful aspects of this question are:

Which parts of the code are you most concerned about? What attack vectors are you most concerned about? Which part(s) of the system do you want whitehats to attempt to break the most? Are there any assumed invariants that you want whitehats to attempt to break?

In general all parts of the code should be checked and attack vectors explored. We write here some areas to look at in particular but this is not to discount any other areas.

One area to explore is the communication between chains. Messages are relayed between the spoke chain and the hub chain via Chainlink CCIP and Wormhole Messaging. In addition, Circle CCTP is used for USDC transfers. It is important to verify that we are using these protocols as intended and have correctly reasoned about the lifecycle of a message.

We have a contract named “HubAdapter” which mimics the behaviour of the Chainlink CCIP and Wormhole messaging, without actually relaying anything. Its purpose is to have a common interface for interacting with the protocol through the spoke contracts regardless of whether on the hub chain or not.

We also have a new process for liquidations which should be checked both economically and codewise. The oracle integration is also new and should be checked for resistance against tampering.

One invariant to ensure that there is sufficient funds such that if all borrowers repaid their loans, all depositors can withdraw their tokens. Not an invariant, but the average stable interest rate should be closely tracking the weighted average of all the stable borrows for a given pool.

What ERC20 / ERC721 / ERC777 / ERC1155 token standards are supported? Which are not?

ERC20 and ERC777 are the only two supported. The modular design allows ERC1155 to be supported in the future too if needed.

What emergency actions may you want to use as a reason to invalidate or downgrade an otherwise valid bug report?

We have rate limiting which sets the maximum amount which can be withdrawn or deposited. If the limit is consumed through a denial of service attack, we have the ability to temporarily boost the capacity.

Other mitigating actions we can take involve removing/adding an adapter, lowering rate limits, lowering pool caps and deprecating a pool. If the bug report’s impact is small in the scope of the protocol as a whole, considering the possible mitigations, then that could be reason to invalidate or downgrade the severity.

What addresses would you consider any bug report requiring their involvement to be out of scope, as long as they operate within the privileges attributed to them?

E.g An ‘Operator’ address with the ability to pause smart contracts who could use their privileged functions to exploit a bug and steal funds

All admin and role addresses, as well as 3rd party infrastructure the project relies on.

What external dependencies are there?

  • Chainlink Price Feeds
  • Pyth Price Feeds
  • Folks Finance Centralised Fallback Oracle
  • Wormhole’s Messaging
  • Chainlink’s CCIP
  • Circle’s CCTP

WWhat are some of the most significant changes to the protocol from the fixes made?

Most of the fixes were errors in the logic that don’t change the protocol intention. These should be checked to ensure they correctly fix the underlying issue.

Some more significant changes were:

  • The retry and reverse message operations are permissioned so only the relevant user can call these. In addition, you can now override the return message parameters if need be.
  • The account id and loan id are generated on-chain for front-running protection.
  • We no longer save the entire failed message but rather a hash of the failed message, significantly reducing gas consumption.
  • In the account management, you can override an existing invite and no longer unregister all connected addresses.

Where might whitehats confuse out-of-scope code to be in-scope?

The external services such as the WormholeRelayer, Chainlink CCIP RouterClient and external oracle services.

Are there any unusual points about your protocol that may confuse whitehats?

We have our own standard of sending and receiving messages. Certain operations require finality as they involve a value transfer while the others can be immediately relayed. There is the “HubAdapter” too which is mentioned above.

We split tokens into two categories in our lending protocol. The first are tokens which are not bridged and remain on the spoke chain e.g. ETH, Link. The second are tokens which are bridged and reside on the hub chain e.g. USDC.

Our lending protocol also is different from others in that a user can have multiple loans, and that a loan can have multiple collaterals and borrows within it. We also define various loan types which have their own respective parameters. One of these is the “deposit” loan type which has borrow caps of zero for every token.

What is the test suite setup information?

If this is already provided in Github, then linking that resource is enough.

It will be in the GitHub report with the rest of the code.

Public Disclosure of Known Issues

Bug reports covering previously-discovered bugs (listed below) are not eligible for a reward within this program. This includes known issues that the project is aware of but has consciously decided not to “fix”, necessary code changes, or any implemented operational mitigating procedures that can lessen potential risk.

  • Griefing through consuming external rate limits of tokens e.g. Circle CCTP rate limits for USDC
  • Griefing through consuming internal rate limits where we have the ability to respond by temporarily boosting capacity
  • Dust positions not being liquidated because of gas fees
  • Manipulation of stable borrow rate to get cheaper borrow
  • Liquidation leading to bad debt when we are prioritising the certainty of a lesser amount of bad debt against the risk of incurring a larger amount of bad debt
  • LiquidationLogic::getMaxRepayBorrowValue can panic if privileged address sets certain parameters

Previous Audits

Severity
Critical
Title
Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield
Severity
Critical
Title
Permanent freezing of funds
Severity
Critical
Title
Protocol insolvency
Severity
High
Title
Theft of unclaimed yield
Severity
High
Title
Theft of unclaimed royalties
Severity
High
Title
Permanent freezing of unclaimed yield
Severity
High
Title
Permanent freezing of unclaimed royalties
Severity
High
Title
Temporary freezing of funds of at least 24h
Severity
Medium
Title
Smart contract unable to operate due to lack of token funds
Severity
Medium
Title
Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
Severity
Medium
Title
Theft of gas
Severity
Medium
Title
Unbounded gas consumption

Out of scope

Program's Out of Scope information

Only the following impacts are accepted within this bug bounty program. All other impacts are not considered as in-scope, even if they affect something in the assets in scope table.