Skip to content
Business logic Audit finding Intermediate

MultiAccount `depositAndAllocateForAccount` function doesn't scale the allocated amount correctly, failing to allocate enough funds

The MultiAccount.depositAndAllocateForAccount function uses the same amount value for deposit and allocate, but deposit amounts use the collateral token's decimals while allocate amounts use 18 decimals. For a token like USDC with 6 decimals, this causes the allocated amount to be 1e12 times smaller than intended, leaving the user with only a dust allocation.

panprog Follow with tvdung94 and xiaoming90

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-08-symmetrical-judging/issues/15

Found by

panprog, tvdung94, xiaoming90

This is an issue very similar to issue 222 from previous audit contest, but in a MultiAccount smart contract.

MultiAccount.depositAndAllocateForAccount uses the same amount value both for depositFor and for allocate. However, deposit amount decimals are from the collateral token while allocate amount decimals = 18. This means that for USDC (decimals = 6), depositAndAllocateForAccount will deposit correct amount, but allocate amount which is 1e12 times smaller (dust amount).

Vulnerability Detail

Internal accounting (allocatedBalances) are tracked as fixed numbers with 18 decimals, while collateral tokens can have different amount of decimals. This is correctly accounted for in AccountFacet.depositAndAllocate:

Solidity
    AccountFacetImpl.deposit(msg.sender, amount);
    uint256 amountWith18Decimals = (amount * 1e18) /
        (10 ** IERC20Metadata(GlobalAppStorage.layout().collateral).decimals());
    AccountFacetImpl.allocate(amountWith18Decimals);

But it is treated incorrectly in MultiAccount.depositAndAllocateForAccount:

Solidity
    ISymmio(symmioAddress).depositFor(account, amount);
    bytes memory _callData = abi.encodeWithSignature(
        "allocate(uint256)",
        amount
    );
    innerCall(account, _callData);

This leads to incorrect allocated amounts.

Impact

Similar to 222 from previous audit contest, the user expects to have full amount deposited and allocated, but ends up with only dust amount allocated, which can lead to unexpected liquidations (for example, user is at the edge of liquidation, calls depositAndAllocate to improve account health, but is liquidated instead). For consistency reasons, since this is almost identical to 222, it should also be high.

Code Snippet

The same amount is used for depositFor and allocate: https://github.com/sherlock-audit/2023-08-symmetrical/blob/main/symmio-core/contracts/multiAccount/MultiAccount.sol#L167-L173

Tool used

Manual Review

Recommendation

Scale amount correctly before allocating it:

Solidity
    ISymmio(symmioAddress).depositFor(account, amount);
+   uint256 amountWith18Decimals = (amount * 1e18) /
+       (10 ** IERC20Metadata(collateral).decimals());
    bytes memory _callData = abi.encodeWithSignature(
        "allocate(uint256)",
-       amount
+       amountWith18Decimals
    );
    innerCall(account, _callData);

Discussion

sherlock-admin

1 comment(s) were left on this issue during the judging contest.

0xyPhilic commented:

invalid because internally the depositAndAllocateForAccount calls the allocate function which does not use scaled amount but the actual input amount

MoonKnightDev

No funds will be lost. The user simply needs to reallocate their balance. Therefore, the severity is not high since there's no loss of funds.

nevillehuang

Relating to this comment in the previous contest, it has the same root cause and potential same consequence, so could be valid H.

MoonKnightDev

Relating to this comment in the previous contest, it has the same root cause and potential same consequence, so could be valid H.

The root cause differs. Here, you can easily rectify the allocatedBalance by allocating again. Moreover, no funds are lost

nevillehuang

Relating to this comment in the previous contest, it has the same root cause and potential same consequence, so could be valid H.

The root cause differs. Here, you can easily rectify the allocatedBalance by allocating again. Moreover, no funds are lost

Ok can be valid M according to Impact mentioned in the submission.

MoonKnightDev

Fixed Code PR: https://github.com/SYMM-IO/symmio-core/pull/35

xiaoming9090

Verified. Fixed in PR 35.

The original report as published on Sherlock, by panprog. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The function failed to scale the deposit amount from the collateral token's decimals to the 18-decimal internal accounting format before passing it to the allocate function.

Impact

A user expecting to deposit and allocate a full amount ends up with only a dust amount allocated, which could lead to unexpected liquidations if the user was near the liquidation threshold.

What the attacker needed

User calls depositAndAllocateForAccount; Collateral token has decimals other than 18

The fix

The amount should be scaled to 18 decimals before being passed to the allocate function, as was done in the fix.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you deposit money into a smart contract, the amount is often stored with a fixed number of decimal places (like 18). But different tokens have different decimal places (USDC has 6). The function forgot to convert the deposit amount to the 18-decimal format before using it to allocate funds, so the allocated amount ended up being much smaller than intended. This could leave a user's account under-collateralised and at risk of liquidation.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by panprog

View all

66 more disclosed reports, best first.

More from Symmetrical Update

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.