# First depositor reward and share capture

Empty-pool first deposit paths where share or reward math skips an offset, floor, or path-independent formula

_Area: DeFi accounting and math bugs. Seen in 4 disclosed reports; latest 2024-05-02. Updated 2026-11-16._

## How it works
Share and reward accounting assumes the pool already has shares and rewards when a deposit arrives. On an empty pool that assumption breaks: the first depositor sets the initial ratio, and any formula that divides by `total_shares`, subtracts a `virtualRewards` offset, or mints shares from a path-dependent formula can be driven to a state where the first staker captures rewards funded by later depositors, or later depositors' shares are diluted. The root cause is a missing floor or guard on the zero-shares branch, or a share formula that is not path-independent.

## Where it shows up
- Reward accrual that divides by `total_shares` with integer truncation, e.g. `deposit*total_reward/total_shares` reaching 0 [E1](https://bugbountylibrary.com/r/c4%3A2024-03-acala%3AH-02.md).
- A `virtualRewards` (or similar offset) computed only when `existingTotalShares != 0`, leaving the first depositor with zero offset [E2](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-02.md).
- `ceilDiv(totalRewards * amount, existingTotalShares)` cast to `uint128`, overflowable by donation [E3](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-04.md).
- Initial liquidity minted as `x + y` instead of `sqrt(x*y)`, making shares path-dependent [E4](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AM-28.md).
- No minimum liquidity or share floor in the pool contract [E1](https://bugbountylibrary.com/r/c4%3A2024-03-acala%3AH-02.md).

## How to review
Check the invariant: for any deposit into an empty or near-empty pool, the shares minted and the reward offset applied must leave the depositor unable to claim rewards accrued before their deposit, and must not let a prior deposit change the shares a later deposit receives for the same token ratio. Verify: (1) a minimum liquidity/share floor exists [E1](https://bugbountylibrary.com/r/c4%3A2024-03-acala%3AH-02.md); (2) the zero-shares branch applies the same offset logic as the non-zero branch [E2](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-02.md); (3) ratio computations cannot overflow their storage type under donation [E3](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-04.md); (4) initial share minting is path-independent, i.e. `sqrt(x*y)` [E4](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AM-28.md).

## How finders spotted it
- Read the `reward_inflation` formula and noticed integer division truncates to 0 when `total_reward < total_shares`, then checked for a minimum liquidity guard [E1](https://bugbountylibrary.com/r/c4%3A2024-03-acala%3AH-02.md).
- Read `_increaseUserShare` and saw the `existingTotalShares != 0` guard skips `virtualRewards` for the first depositor; cross-referenced `userRewardForPool` and the upkeep timer to confirm rewards exist before the first LP [E2](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-02.md).
- Read `virtualRewardsToAdd` using `ceilDiv` and a `uint128` cast, then reasoned a first-depositor donation inflates the ratio past `uint128` max [E3](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-04.md).
- Compared Salty's `x+y` initial liquidity formula against Uniswap v2's `sqrt(x*y)` and recognized only the latter is path-independent [E4](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AM-28.md).

## Variants seen
- Truncating reward division to zero via share inflation [E1](https://bugbountylibrary.com/r/c4%3A2024-03-acala%3AH-02.md).
- Skipped virtual-rewards offset on the first deposit [E2](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-02.md).
- Overflow of a virtual-rewards ratio via donation [E3](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-04.md).
- Path-dependent initial share minting defeating slippage limits [E4](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AM-28.md).

## Impact and severity
First depositor captures pool rewards funded by later users [E1](https://bugbountylibrary.com/r/c4%3A2024-03-acala%3AH-02.md)[E2](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-02.md), breaks staking accounting so claims revert [E3](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-04.md), or loses most tokens to a frontrunner despite `minShares` [E4](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AM-28.md). Severity is high where rewards are already accrued before the first deposit [E2](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-02.md) or where accounting breaks entirely [E3](https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-04.md); impact scales with pool size and reward emissions.

## Evidence
- E1: https://bugbountylibrary.com/r/c4%3A2024-03-acala%3AH-02.md
- E2: https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-02.md
- E3: https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AH-04.md
- E4: https://bugbountylibrary.com/r/c4%3A2024-01-salty%3AM-28.md
