Skip to content
Smart contracts Audit finding Advanced

yIntercept of public vaults can overflow

An unchecked addition when updating a public vault's yIntercept can overflow, making totalAssets report far less than the real balance. Liquidity providers are then unable to withdraw a large fraction of their deposited assets.

evan Follow

Originally disclosed on Code4rena

Submitted by evan

The yIntercept of a public vault can overflow due to an unchecked addition. As a result, totalAsset will be a lot lower than the actual amount, which prevents liquidity providers from withdrawing a large fraction of their assets.

https://github.com/code-423n4/2023-01-astaria/blob/main/src/PublicVault.sol#L323-L325

The amount of assets required for this to happen is barely feasible for a regular 18 decimal ERC20 token, but can happen with ease for tokens with higher precision.

Proof of Concept

pragma solidity =0.8.17;

import "forge-std/Test.sol";

import {Authority} from "solmate/auth/Auth.sol";
import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";
import {MockERC721} from "solmate/test/utils/mocks/MockERC721.sol";
import {
  MultiRolesAuthority
} from "solmate/auth/authorities/MultiRolesAuthority.sol";

import {ERC721} from "gpl/ERC721.sol";
import {SafeCastLib} from "gpl/utils/SafeCastLib.sol";

import {IAstariaRouter, AstariaRouter} from "../AstariaRouter.sol";
import {VaultImplementation} from "../VaultImplementation.sol";
import {PublicVault} from "../PublicVault.sol";
import {TransferProxy} from "../TransferProxy.sol";
import {WithdrawProxy} from "../WithdrawProxy.sol";

import {Strings2} from "./utils/Strings2.sol";

import "./TestHelpers.t.sol";
import {OrderParameters} from "seaport/lib/ConsiderationStructs.sol";

contract AstariaTest is TestHelpers {
  using FixedPointMathLib for uint256;
  using CollateralLookup for address;
  using SafeCastLib for uint256;

  event NonceUpdated(uint256 nonce);
  event VaultShutdown();

  function testYinterceptOverflow() public {

    address publicVault = _createPublicVault({
      strategist: strategistOne,
      delegate: strategistTwo,
      epochLength: 14 days
    });
    _lendToVault(
      Lender({addr: address(1), amountToLend: 309000000 ether}),
      publicVault
    );
    _lendToVault(
      Lender({addr: address(2), amountToLend: 10000000 ether}),
      publicVault
    );
    assertTrue(PublicVault(publicVault).totalAssets() < 10000000 ether);

  }
}

Tools Used

VSCode, Foundry

Recommended Mitigation Steps

Remove the unchecked block.


The original report as published on Code4rena, by evan. 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 an unchecked arithmetic addition when accumulating the vault's yIntercept, allowing the value to wrap around instead of reverting.

Impact

Liquidity providers could be unable to withdraw a large fraction of their assets because the vault under-reports its holdings; the text notes the required amount is barely feasible for a standard 18-decimal token but easy for higher-precision tokens.

What the attacker needed

A public vault; deposits large enough to overflow; higher-precision token makes it easier

The fix

The unchecked block around the addition should be removed so the operation reverts on overflow.

How it was found

  1. Create a public vault with a chosen epoch length.
  2. Lend a very large amount to the vault from one address.
  3. Lend a second large amount from another address.
  4. Observe that totalAssets is now lower than the second deposit.

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 vault is a shared pot where people deposit money. The code adds up deposits in a fixed-size number, and if the total gets too big the number wraps around to a small value, like an old car odometer rolling over. The vault then thinks it holds much less than it does, so people cannot take their money out.

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 evan

View all

11 more disclosed reports, best first.

More from Astaria contest

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.