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.
- 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
- Report ID: #56465
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/AlchemistV3.sol
- Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
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
_mytSharesDepositedvariable is used to differentiate between tokens deposited and balance of the contract. - This means that
_mytSharesDepositedreflects the tokens deposited, and this is why it is increased indeposit()here - But, if we look at
getTotalDeposited(), we find that it returns the balance of the contract:
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
Proof of Concept
Proof of Concept
Put the following test under src/test/AlchemistV3.t.sol:
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
function getTotalDeposited() external view returns (uint256) {
return _mytSharesDeposited;
}
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
- Deposit tokens into the contract.
- Send additional tokens directly to the contract.
- 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.