DeFiHardhat
35,000 USDC
View results
Submission Details
Severity: low
Invalid

Inconsistent Internal Balance Adjustment Endangers Deposit Function Integrity in Silo Protocol

Summary

The flawed implementation of the receiveToken function within the LibTransfer contract, which inaccurately adjusts internal balances before confirming successful token transfers, jeopardizes the integrity of the deposit function in the Silo protocol, potentially leading to financial losses for users due to misrepresentation of deposited token balances.

Vulnerability Details

This inconsistency in the receiveToken function within the LibTransfer contract directly impacts the functionality of the deposit function within the SiloFacet contract, which is within the scope of the audit. The deposit function is a critical component of the Silo protocol, allowing users to deposit ERC20 tokens into the Silo system. However, due to the flawed implementation of receiveToken, the integrity of the deposit function is compromised.

The deposit function calls the receiveToken function to handle the transfer of tokens from the user to the Silo system. However, since the receiveToken function decreases the internal balance of the sender before confirming the success of the token transfer, there's a risk of inaccurate balance updates within the Silo system. If the token transfer fails for any reason (such as insufficient allowance or balance), the internal balance will still be reduced, leading to an incorrect state.

function deposit(
address token,
uint256 _amount,
LibTransfer.From mode
)
external
payable
nonReentrant
mowSender(token)
returns (uint256 amount, uint256 _bdv, int96 stem)
{
amount = LibTransfer.receiveToken(
IERC20(token),
_amount,
msg.sender,
mode
);
(_bdv, stem) = _deposit(msg.sender, token, amount);
}

The receiveToken function serves as a critical component for managing token transfers within the Silo protocol. When a token transfer is initiated, this function is responsible for handling the transfer process, including adjusting the internal balances accordingly. However, a flaw arises in how the internal balance adjustment is executed. Specifically, the function attempts to decrease the internal balance of the sender before verifying the success of the token transfer operation. This introduces a vulnerability wherein the internal balance may be erroneously updated, leading to inconsistent state management.

function receiveToken(
IERC20 token,
uint256 amount,
address sender,
From mode
) internal returns (uint256 receivedAmount) {
if (amount == 0) return 0;
if (mode != From.EXTERNAL) {
receivedAmount = LibBalance.decreaseInternalBalance(
sender,
token,
amount,
mode != From.INTERNAL
);
if (amount == receivedAmount || mode == From.INTERNAL_TOLERANT)
return receivedAmount;
}
uint256 beforeBalance = token.balanceOf(address(this));
token.safeTransferFrom(sender, address(this), amount - receivedAmount);
return
receivedAmount.add(
token.balanceOf(address(this)).sub(beforeBalance)
);
}

In this snippet, after determining that the transfer mode is not external, the function attempts to decrease the internal balance of the sender. However, this action is performed before the token transfer operation itself. If the transfer operation fails (e.g., due to insufficient allowance or balance), the internal balance is still reduced, leading to an inconsistent state.

Impact

The primary impact of this vulnerability on the deposit function is the risk of financial losses for users. Due to the inconsistency in updating internal balances, users may mistakenly believe that their deposited tokens are securely held within the Silo system when, in reality, they remain in their possession.

Tools Used

Manual

Recommendations

Ensure that the internal balance adjustment within the receiveToken function occurs only after confirming the success of the token transfer operation. In the context of the deposit function, this means restructuring the flow to first execute the token transfer and then update the internal balances accordingly.

Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

Informational/Invalid

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.