Skip to content
Business logic Audit finding Intermediate

Vault.settle(account=coordinator) will lose profitShares

The Vault.settle function credits profit shares to the coordinator by writing directly to storage, but does not update the in-memory [redacted].shares. If the settlement account is the coordinator, the final save overwrites the credited shares with the old value, causing the coordinator to lose profit shares.

0x1982us Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-01-perennial-v2-4-update-judging/issues/24

Found by

0x1982us

Summary

Vault.settle() turns a portion of the profit into profitShares for coordinator. Use method _credit() to save profitShares to storage. But it doesn't update the memory variable context.local.shares. It doesn't take into account the case where account == coordinator. This way, if you maliciously specify that the settlement account is coordinator, settle() will end up overwriting the new value with the old value in memory. Resulting in loss of profitShares.

Root Cause

/Vault.sol#L390 settle() call _credit()

Solidity
    function _settle(Context memory context, address account) private {
...
        while (
            context.global.current > context.global.latest &&
            context.latestTimestamp >= (nextCheckpoint = _checkpoints[context.global.latest + 1].read()).timestamp
        ) {
            // process checkpoint
            UFixed6 profitShares;
            (context.mark, profitShares) = nextCheckpoint.complete(
                context.mark,
                context.parameter,
                _checkpointAtId(context, nextCheckpoint.timestamp)
            );
            context.global.shares = context.global.shares.add(profitShares);
@=>         _credit(coordinator, profitShares);

in Vault.sol#L424 save to storage but don't update context.local.shares

Solidity
    function _credit(address account, UFixed6 shares) internal virtual {
        Account memory local = _accounts[account].read();
        local.shares = local.shares.add(shares);
@=>     _accounts[account].store(local);
    }

but at the last _saveContext() save context.local.shares to storage, it will override _credit() value if account == coordinator

Solidity
    function _saveContext(Context memory context, address account) private {
@=>     if (account != address(0)) _accounts[account].store(context.local);
        _accounts[address(0)].store(context.global);
        _checkpoints[context.currentId].store(context.currentCheckpoint);
        mark = context.mark;
    }

Internal Pre-conditions

No response

External Pre-conditions

No response

Attack Path

Example context[coordinator].local.shares = 0

  1. anyone call settle(account = coordinator)
  2. suppose profitShares = 10
  3. in _credit() save storage _accounts[coordinator].shares = profitShares = 10 , but context.local.shares still 0
  4. at last _saveContext() will overwrite _accounts[coordinator].shares = context.local.shares = 0
  5. coordinator lose 10 shares

Impact

coordinator lose profitShares

PoC

No response

Mitigation

like Market.sol#_credit(), if coordinator == context.account , only change context.local.shares

Diff
-   function _credit(address account, UFixed6 shares) internal virtual {
+   function _credit(Context memory context, address account, UFixed6 shares) internal virtual {
+     if (account == context.account)  context.local.shares = context.local.shares.add(shares)
+     else {
          Account memory local = _accounts[account].read();
          local.shares = local.shares.add(shares);
          _accounts[account].store(local);
+     }
    }

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/563

The original report as published on Sherlock, by 0x1982us. 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

The _credit function updates storage but not the in-memory [redacted].shares, and _saveContext later overwrites storage with the stale memory value when the account is the coordinator.

Impact

The coordinator loses the profit shares that should have been credited.

What the attacker needed

None

The fix

The protocol team fixed this issue by updating the _credit function to modify [redacted].shares when the account matches the context account, as shown in the mitigation diff.

How it was found

  1. Anyone calls settle with account set to the coordinator address.
  2. The _credit function writes the profit shares to storage for the coordinator.
  3. The in-memory [redacted].shares remains unchanged (e.g., zero).
  4. The final _saveContext call overwrites the coordinator's stored shares with the stale memory value, losing the profit shares.

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.

When the vault settles, it gives a share of the profit to a special account called the coordinator. The code saves this new share amount to the database but forgets to update a temporary copy in memory. Later, it saves that old temporary copy back to the database, wiping out the new shares. So the coordinator ends up with less than they should.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Perennial V2 Update #4

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.