Skip to content
Business logic Audit finding Intermediate

Base tokens like USDT, USDC having different decimals on different chains can have their TVL updated incorrectly

When a manager on a non-base chain triggers a TVL update, the value is sent to the base chain without adjusting for the token's decimals on that chain, so an 18-decimal token is recorded as if it were 6-decimal. The inflated TVL then feeds totalAssets() and breaks share minting and other vault accounting.

MrPotatoMagic Follow with KupiaSec and Weed0607

Originally disclosed on Code4rena

Submitted by MrPotatoMagic, also found by KupiaSec and Weed0607

Impact

Tokens like USDT, USDC on the BSC chain have 18 decimals while the “Base” blockchain which is being used as the root/base chain uses 6 decimals (see here).

The issue is that when the TVL is updated on the base chain by sending a cross-chain message call from OmnichainManagerNormalChain.sol contract to OmnichainManagerBaseChain.sol contract, the TVL is recorded in the holding position with 18 decimals instead of scaling it down to 6 decimals.

Due to this, whenever the accounting manager retrieves the TVL() through function totalAssets() (overriden from ERC4626), the TVLHelper contract would loop through all holding positions and sum them up in order to be used in vault operations like minting shares etc. This would be problematic since the tvl is 1e12 decimals more than the actual of 1e6. This breaks the accounting in the accounting manager contract.

Proof of Concept

Here’s the whole process:

  1. Manager calls function updateTVLInfo() on the OmnichainManagerNormalChain.sol contract on the BSC chain.
  2. On Line 29, it calls the getTVL() function that loops through all the holding positions for the base token and vaultId.
  3. The value is returned (in 18 decimals since we’re on BSC) and stored in tvl on Line 29.

Line 30 calls the updateTVL() function on the lzhelper contract, which sends the cross-chain message with the tvl update.

File: OmnichainManagerNormalChain.sol
19:     function getTVL() public view returns (uint256) {
20:         (, address baseToken) = registry.getVaultAddresses(vaultId);
21:         return TVLHelper.getTVL(vaultId, registry, baseToken);
22:     }
23:     /**
24:      * Triggers an update of the vault's TVL information, sending the latest data to the base chain via the LZHelperSender contract.
25:      * This function is restricted to be called by managers only, ensuring that TVL updates are controlled and authorized.
26:      */
27:
28:     function updateTVLInfo() external onlyManager {
29:         uint256 tvl = getTVL();
30:         LZHelperSender(lzHelper).updateTVL(vaultId, tvl, block.timestamp);
31:     }
  1. The call arrives on the base chain by LZ calling the _lzReceive() function, which calls the updateTVL() function on the OmnichainManagerBaseChain.sol contract.
  2. On Line 39, the tvl variable is stored as is with the 18 decimals incorrectly.
File: OmnichainManagerBaseChain.sol
32:     function updateTVL(uint256 chainId, uint256 tvl, uint256 updateTime) external nonReentrant {
33:         if (msg.sender != lzHelper) revert IConnector_InvalidSender();
34:
35:         registry.updateHoldingPostionWithTime(
36:             vaultId,
37:             registry.calculatePositionId(address(this), OMNICHAIN_POSITION_ID, abi.encode(chainId)),
38:             "",
39:             abi.encode(tvl),
40:             tvl <= DUST_LEVEL,
41:             updateTime
42:         );
43:     }
  1. Now when the totalAssets() function in the accounting manager calls the TVL() function, it loops through the holding positions in the TVLHelper contract and sums up the TVL incorrectly.
    function getTVL(uint256 vaultId, PositionRegistry registry, address baseToken) public view returns (uint256) {
        uint256 totalTVL;
        uint256 totalDebt;
        HoldingPI[] memory positions = registry.getHoldingPositions(vaultId);
        for (uint256 i = 0; i < positions.length; i++) {
            if (positions[i].calculatorConnector == address(0)) {
                continue;
            }
            uint256 tvl = IConnector(positions[i].calculatorConnector).getPositionTVL(positions[i], baseToken);
            bool isPositionDebt = registry.isPositionDebt(vaultId, positions[i].positionId);
            if (isPositionDebt) {
                totalDebt += tvl;
            } else {
                totalTVL += tvl;
            }
        }
        if (totalTVL < totalDebt) {
            return 0;
        }
        return (totalTVL - totalDebt);
    }

Through this we observe how incorrect tvl is reported from the normal chain to the base chain, which hugely affects the value retrieved by function totalAssets() for ERC4626 vault operations.

Recommended Mitigation Steps

Keep track of the decimals of tokens on other chains in a mapping. If they are more or less, consider scaling them once the tvl update is received on the base chain.

HadiEsna (NOYA) confirmed and commented:

Fix in commit 58537ef76afa048745f85a31cb7a0aa3eb6b300b.


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

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

Likely the cross-chain TVL update stores the raw amount from the source chain without converting it to the base chain token's decimals.

Impact

The reported TVL could be about a trillion times too large, which breaks accounting and vault operations such as minting shares.

What the attacker needed

Manager role on the vault; vault uses a token with differing decimals

The fix

The project fixed it in a commit by tracking token decimals across chains and scaling the TVL when the update is received on the base chain.

How it was found

  1. A manager calls updateTVLInfo() on the normal-chain manager contract.
  2. The contract reads the TVL of the base token's holding positions, which is in 18 decimals on that chain.
  3. The value is sent through the cross-chain helper to the base chain.
  4. The receiver calls updateTVL() on the base-chain manager, which stores the value unchanged.
  5. totalAssets() later sums the stored positions and returns an inflated TVL.

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.

Different blockchains can store the same token with different precision, called decimals. Here a token worth 1 unit on one chain is written as 1,000,000,000,000 units on another, so the vault thinks it holds far more money than it does. That wrong total is then used to decide how many vault shares to give people.

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 MrPotatoMagic

View all

17 more disclosed reports, best first.

More from NOYA

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.