Skip to content
Business logic Audit finding Intermediate

Asking for `balanceOf()` in the wrong address

The sendFundsToVault function retrieves the underlying token address for a specified chain, but when the chain is Optimism (L2), it calls balanceOf on that L2 token address while the contract is on Mainnet, which is invalid. This prevents the protocol from rebalancing the vault.

Ch_301 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/170

Found by

Ch_301

Summary

Vulnerability Detail

on sendFundsToVault() this logic

Solidity
address underlying = getUnderlyingAddress(_vaultNumber, _chain);
uint256 balance = IERC20(underlying).balanceOf(address(this));

in case _chainId is Optimism the underlying address is for Optimism (L2) but XChainController is on Mainnet you can't invoke balanceOf() like this!!!

Impact

Asking for balanceOf() in the wrong address The protocol will be not able to rebalance the vault

Code Snippet

Tool used

Manual Review

Recommendation

getUnderlyingAddress(_vaultNumber, _chain); should just be getUnderlyingAddress(_vaultNumber); so the underlying here

Solidity
uint256 balance = IERC20(underlying).balanceOf(address(this));

will be always on the Mainnet

Discussion

Ch-301

Escalate for 10 USDC

This one was confirmed by the Sponsor check the discussion for more details

sherlock-admin

Escalate for 10 USDC

This one was confirmed by the Sponsor check the discussion for more details

You've created a valid escalation for 10 USDC!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

Theezr

Valid medium issue

hrishibhat

Escalation accepted

Considering this issue a valid medium

sherlock-admin

Escalation accepted

Considering this issue a valid medium

This issue's escalations have been accepted!

Contestants' payouts and scores will be updated according to the changes made on this issue.

The original report as published on Sherlock, by Ch_301. 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

Likely the function uses a chain-specific underlying token address without accounting for the fact that the contract only operates on Mainnet, leading to an invalid cross-chain balance query.

Impact

The protocol will be unable to rebalance the vault.

What the attacker needed

None

The fix

The function should use the Mainnet underlying token address by calling getUnderlyingAddress without the chain parameter.

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.

A smart contract on one blockchain (Mainnet) cannot directly ask for the balance of a token that exists on a different blockchain (Optimism). The code mistakenly uses the address of the Optimism token when checking the balance on Mainnet, so the check fails and the vault cannot be rebalanced.

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 Ch_301

View all

39 more disclosed reports, best first.

More from Derby

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.