Skip to content

Fix sub-cent fee rounding in YeetfulStaking (closes #1) - #3

Open
nategeier wants to merge 2 commits into
mainfrom
fix/staking-fee-precision
Open

Fix sub-cent fee rounding in YeetfulStaking (closes #1)#3
nategeier wants to merge 2 commits into
mainfrom
fix/staking-fee-precision

Conversation

@nategeier

Copy link
Copy Markdown
Member

What

Fixes the High finding from the pre-publish security review (#1): per-call USDC fees rounded to zero and stranded in the vault.

Why

accFeePerShare += amount * ACC_PRECISION / totalStaked with ACC_PRECISION = 1e18 is too coarse when the stake token is an 18-dec Flaunch memecoin (~1e29 supply) and the payout is 6-dec USDC at fraction-of-a-cent granularity. At ~1e27 staked, any deposit under ~$1000 rounded the increment to zero, so accFeePerShare never moved and the routed USDC piled up unclaimable.

Change

  • ACC_PRECISION 1e18 → 1e30 — keeps even a 1-micro-USDC route non-zero at full supply.
  • Add feeRemainder: carry the truncation remainder (scaled USDC) into the next route's numerator so dust accrues across routes instead of stranding. The matching USDC stays in the contract until it converts — solvency preserved.
  • Overflow stays safe: staked * accFeePerShare reconstructs earned * 1e30, bounded by total-routed-USDC × 1e30 ≪ 2^256.

Tests (19/19 green)

  • test_subCentFee_atFullSupply_notStranded — a single $0.001 route against a 100B (1e29) stake stays fully claimable (was 0 under 1e18).
  • test_remainderCarry_losslessOverManyRoutes — 50 non-share-aligned tiny routes accrue losslessly (within 1 micro).
  • All pre-existing staking + factory + adapter tests still pass.

Also renames the README H1 to match the Yeetful/contracts repo name (separate commit).

Medium finding #2 (permissionless launch()) is left as a separate issue per the publish plan.

Closes #1

nategeier and others added 2 commits June 25, 2026 11:33
ACC_PRECISION 1e18 was too small: an 18-dec memecoin stake (Flaunch supply
~1e29) against 6-dec USDC meant any sub-$1000 routeFees rounded the per-share
increment to zero, stranding the USDC in the vault. Bump to 1e30 and carry the
truncation remainder forward across routes so dust accrues instead of stranding.

Adds regression tests: a single $0.001 route at 100B supply stays claimable,
and 50 non-share-aligned tiny routes accrue losslessly (within 1 micro).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High: fee-per-share rounding strands per-call USDC fees (ACC_PRECISION too small)

1 participant