H-1: Single ramping bucket lets hooks distort voting weight
Description:
WeightAggregator and YBCWeightAggregator track each account's immature stake with a single (ramping, time) bucket. On every increment, _update_staked() decays the existing ramping value, adds the incoming amount, and then sets time = block.timestamp for the entire combined remainder.
This means any increment hook can rewrite the ramp schedule for stake that was already immature. The newly added amount should start ramping from the current timestamp, but the account's previous immature balance should keep its existing ramp schedule. Zero or net-neutral hooks should not refresh prior ramping state at all.
This creates two related attack vectors:
- Same-epoch self-inflation: a user can trigger a zero-amount deposit/mint, or stake and unstake dust in the same epoch. If the user's net stake is not greater than the epoch-start stake,
weight()uses the refreshed current packed state, allowing post-snapshot ramp progress to increase current-epoch voting weight. - Future-epoch dust griefing: a third party can transfer dust staking shares to a victim before maturation. The victim cannot reject the inbound transfer, and the hook refreshes the timestamp for the victim's whole remaining immature balance, delaying future voting-weight maturation.
Example:
- Alice has
100 YFIstill ramping. - Alice can use a zero or net-neutral hook after the epoch snapshot to inflate her current-epoch weight.
- Bob can instead transfer
1 weiof staking shares to Alice before later snapshots, resetting the remaining ramp for Alice's existing immature balance and suppressing her future weight.
Affected paths:
WeightAggregator.on_transfer()andon_stake()call_update_staked(..., INCREMENT)for recipients and stakers.WeightAggregator._update_staked()rewritestime = block.timestampfor the combined ramping amount.YBCWeightAggregator.on_transfer()andon_stake()repeat the same pattern for YBC voting weight.
Impact:
High. Voting weight can be distorted without a meaningful stake change. Users can increase their own current-epoch weight above the intended snapshot, while third parties can suppress a victim's future global or YBC voting weight with dust transfers.
Recommendation:
Do not collapse all immature stake into one timestamped bucket. Track new inflows separately from previously immature stake, for example with per-epoch or per-deposit ramp buckets, and compute weight as the sum of those buckets. This ensures an inbound transfer only ramps the transferred amount and cannot reset prior vesting progress.
Also ignore zero-amount hooks before mutating aggregator state, and add regression tests for same-epoch zero/net-neutral hooks and dust transfers into both aggregators.
Developer Response:
Because of this and other issues independently found with the ramping mechanism we have opted to replace it entirely and store weights for 4 sequential epochs instead, see commit 0f0f779