Skip to content
Smart contracts Audit finding Intermediate

Vault Fee uses incorrect offset leading to wildly incorrect value, allowing strategists to steal all funds

The VAULT_FEE() function in a cloned contract reads from the wrong storage offset, returning a value about 1e16 times larger than intended. This inflated fee lets strategists claim shares far exceeding actual interest, enabling them to withdraw all vault funds.

zzykxx Follow with obront

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/19

Found by

zzykxx, obront

Summary

VAULT_FEE() uses an incorrect offset, returning a number ~1e16X greater than intended, providing strategists with unlimited access to drain all vault funds.

Vulnerability Detail

When using ClonesWithImmutableArgs, offset values are set so that functions representing variables can retrieve the correct values from storage.

In the ERC4626-Cloned.sol implementation, VAULT_TYPE() is given an offset of 172. However, the value before it is a uint8 at the offset 164. Since a uint8 takes only 1 byte of space, VAULT_TYPE() should have an offset of 165.

I put together a POC to grab the value of VAULT_FEE() in the test setup:

Solidity
function testVaultFeeIncorrectlySet() public {
  Dummy721 nft = new Dummy721();
  address tokenContract = address(nft);
  uint256 tokenId = uint256(1);
  address publicVault = _createPublicVault({
      strategist: strategistOne,
      delegate: strategistTwo,
      epochLength: 14 days
  });
  uint fee = PublicVault(publicVault).VAULT_FEE();
  console.log(fee)
  assert(fee == 5000); // 5000 is the value that was meant to be set
}

In this case, the value returned is > 3e20.

Impact

This is a highly critical bug. VAULT_FEE() is used in _handleStrategistInterestReward() to determine the amount of tokens that should be allocated to strategistUnclaimedShares.

Solidity
if (VAULT_FEE() != uint256(0)) {
    uint256 interestOwing = LIEN_TOKEN().getInterest(lienId);
    uint256 x = (amount > interestOwing) ? interestOwing : amount;
    uint256 fee = x.mulDivDown(VAULT_FEE(), 1000); //VAULT_FEE is a basis point
    strategistUnclaimedShares += convertToShares(fee);
  }

The result is that strategistUnclaimedShares will be billions of times higher than the total interest generated, essentially giving strategist access to withdraw all funds from their vaults at any time.

Code Snippet

https://github.com/sherlock-audit/2022-10-astaria/blob/main/lib/astaria-gpl/src/ERC4626-Cloned.sol#L113-L116

https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/PublicVault.sol#L518-L523

Tool used

Manual Review

Recommendation

Set the offset for VAULT_FEE() to 165. I tested this value in the POC I created and it correctly returned the value of 5000.

The original report as published on Sherlock, by zzykxx. 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 offset for VAULT_FEE() was set to 172 instead of 165 because the preceding uint8 variable occupies only one byte, not eight.

Impact

Strategists could withdraw all funds from their vaults because the inflated fee gives them shares far exceeding the actual interest generated.

What the attacker needed

Strategist role in a vault

The fix

The offset for VAULT_FEE() should be set to 165.

How it was found

  1. Create a public vault with specified strategist and delegate.
  2. Call VAULT_FEE() on the vault.
  3. Observe the returned fee value is over 3e20 instead of 5000.

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.

Smart contracts can be cloned with extra data appended to their code. The contract reads this data using offsets, like page numbers in a book. A wrong offset made the fee value read from the wrong spot, producing a huge number that let strategists take more money than they should.

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 zzykxx

View all

6 more disclosed reports, best first.

More from Astaria

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.