Boost _ Folks Finance 33893 - [Smart Contract - Medium] Malicious users can DoS loan creations and deposits causing temporary funds freezing and additional costs incurred for message reversals
Submitted on Thu Aug 01 2024 07:57:41 GMT-0400 (Atlantic Standard Time) by @iamandreiski for Boost | Folks Finance
Report ID: #33893
Report type: Smart Contract
Report severity: Medium
Target: https://testnet.snowtrace.io/address/0x2cAa1315bd676FbecABFC3195000c642f503f1C9
Impacts:
Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
Description
Brief/Intro
Since both accountIds and loanIds are created by the users (as opposed to a hash from different parameters), when a user initiates a loan creation and deposit into one transaction, that deposit can be DoSd by frontrunning it with a loan creation transaction with the same ID. Since the user has also deposited (besides initiating a loan creation), they would then have to "reverse" the message in order to get their money back, which would cost additional funds in terms of gas costs, besides temporarily freezing their funds. This "attack" can be repeated an indefinite amount of times. Since all checks on whether an account exists happen on the Hub chain, a user's message won't fail until it has reached the Hub chain.
Vulnerability Details
When a user wants to create a loan and deposit in the same transaction, the user path which they can take is through the Spoke chain's token contract calling the createLoanAndDeposit
function:
The problem is that the loanId
argument is determined by the user and can be arbitrary. Since loans with "same IDs" can't exist, the problem arises if a malicious user frontruns the createLoanAndDeposit
transaction with a createLoan
transaction with the same loan ID.
Since the checks whether the loan exists or not are performed on the Hub chain, once the transaction is initiated on the spoke chain, it will be relayed through the desired adapter (CCIP, Wormhole).
Once the data/token transfer is relayed to the Hub chain, the _receiveMessage
function on Hub.sol will be invoked with the Message.Action.CreateLoanAndDeposit
:
When loanManager.createUserLoan
is first called, the transaction will revert due to the following check:
Since the transaction was frontrunned by the malicious user, and such a loanId already exists, this action will fail and store the message as a failed one due to the following check whether the loan is active:
Since this message is non-executable (it will keep failing due to the loanId being active), as explained above, and as it will always revert, the only plausible solution is for the user to reverse their message and get back the funds.
This is an action that will cost additional funds in terms of gas + the temporary freezing of funds until the message is reversed and the funds relayed back.
Impact Details
All createLoanAndDeposit
transactions can be DoSd by frontrunning them with a loan creation transaction with the same loan id as the unsuspecting user(victim) who wants to create it. Once this is acheived, the user whose transaction was DoSd on the destination chain (HUB) would have to reverse their message in order to get their funds back. This will cause additional gas costs, as well as a temporary freezing of funds until they're relayed back. The attack can be repeated an indefinite amount of times.
References
PoC uses Foundry and the MockLoanManager contract was modified to include a mapping called _userLoans which will store the id of the loan with a boolean whether that loan is created. To simulate the real Loan Manager's isUserLoanActive() function which reverts if the loan has been created - a condition was added which reverts if the loan was added to the mapping.
Proof of concept
Proof of Concept
Last updated