Skip to content

fix(payroll): use checked arithmetic for cumulative milestone total (#502)#691

Closed
jjb9707 wants to merge 4 commits into
Stellopay:mainfrom
jjb9707:fix/502-milestone-total-overflow
Closed

fix(payroll): use checked arithmetic for cumulative milestone total (#502)#691
jjb9707 wants to merge 4 commits into
Stellopay:mainfrom
jjb9707:fix/502-milestone-total-overflow

Conversation

@jjb9707

@jjb9707 jjb9707 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #502

add_milestone accumulated MilestoneKey::TotalAmount with a raw total + amount, which can silently wrap i128 if a caller supplies a large amount while the running total is near the type bound.

Changes

  • Replaced total + amount with total.checked_add(amount).ok_or(PayrollError::MilestoneTotalOverflow)? in add_milestone
  • Added PayrollError::MilestoneTotalOverflow = 44 to the error enum (append-only)
  • Updated the debug-only post-invariant assertion to compare against new_total

Security

Prevents a silent integer wrap of the cumulative milestone total, keeping escrow accounting consistent with the per-milestone sums asserted in debug builds.

jjb9707 added 3 commits July 2, 2026 15:32
…tellopay#502)

Cumulative milestone total in `add_milestone` was computed with a raw
`total + amount` that could silently wrap `i128` on maliciously large
inputs. Switch to `checked_add` and reject with a new
`PayrollError::MilestoneTotalOverflow` (code 44) on overflow.
@jjb9707
jjb9707 requested a review from Jagadeeshftw as a code owner July 7, 2026 01:04
@Jagadeeshftw

Copy link
Copy Markdown
Contributor

Closing since this PR isn't linked to an issue you're assigned to. Please get assigned to an open issue first, then feel free to open a fresh PR referencing it. Thanks for understanding!

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.

Use checked arithmetic for cumulative milestone totals in add_milestone to prevent silent i128 wrap

2 participants