Skip to content
Smart contracts Audit finding Beginner

Gettotaldeposited doesn t reflect the correct total deposited

The getTotalDeposited function returns the contract's token balance instead of the tracked deposited shares, so a direct token transfer inflates the reported total. An attacker could send tokens directly to the contract to make the reported total deposited incorrect.

j3x Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

56465 sc low gettotaldeposited doesn t reflect the correct total deposited

Submitted on Oct 16th 2025 at 11:06:05 UTC by @j3x for Audit Comp | Alchemix V3

Description

Brief/Intro

AlchemistV3::getTotalDeposited doesn't reflect the correct total deposited. It returns the balance of the contract, but that contradicts with the purpose of the presence of the variable _mytSharesDeposited, which is present to differentiate between the contract's balance and the amount deposited.

Vulnerability Details

  • In this comment, it is said that the _mytSharesDeposited variable is used to differentiate between tokens deposited and balance of the contract.
  • This means that _mytSharesDeposited reflects the tokens deposited, and this is why it is increased in deposit() here
  • But, if we look at getTotalDeposited(), we find that it returns the balance of the contract:
Solidity
    function getTotalDeposited() external view returns (uint256) {
        return IERC20(myt).balanceOf(address(this));
    }
  • This contradicts the comment above, as the balance is not always equal the total deposited amount (due to direct token transfers for example).

Impact Details

getTotalDeposited() fails to deliver promised returns, as it fails to return the correct total amount deposited.

References

https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/interfaces/IAlchemistV3.sol#L771

Proof of Concept

Proof of Concept

Put the following test under src/test/AlchemistV3.t.sol:

Solidity
    function test_getTotalDeposited_FailsToDeliver() public {
        uint256 amount = 100e18;
        vm.startPrank(address(0xbeef));
        SafeERC20.safeApprove(address(vault), address(alchemist), amount + 100e18);
        alchemist.deposit(amount, address(0xbeef), 0);
        console.log("alchemist.getTotalDeposited()", alchemist.getTotalDeposited());
        // transfer some tokens to break the correct getTotalDeposited
        deal(address(vault), address(0xbeef), 1e18);
        SafeERC20.safeTransfer(address(vault), address(alchemist), 1e18);
        assertNotEq(alchemist.getTotalDeposited(), amount);
        console.log("alchemist.getTotalDeposited()", alchemist.getTotalDeposited());
    }

You will see that the correct amount deposited is 100, but the getTotalDeposited() returns 101 due to the direct token transfer that happened.

Mitigation

Solidity
    function getTotalDeposited() external view returns (uint256) {
        return _mytSharesDeposited;
    }

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

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 reads the contract's token balance instead of the internal accounting variable that tracks deposits.

What the attacker needed

Ability to transfer tokens directly to the contract

The fix

The function should return the internal variable that tracks deposited shares instead of the contract's token balance.

How it was found

  1. Deposit tokens into the contract.
  2. Send additional tokens directly to the contract.
  3. Observe that getTotalDeposited returns a value larger than the deposited amount.

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 keeps a record of how many tokens users have deposited. The function that reports the total deposited should use that record, but instead it checks the contract's current token balance. If someone sends tokens directly to the contract, the balance goes up and the reported total becomes wrong.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by j3x

View all

3 more disclosed reports, best first.

More from Alchemix V3

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.