Severity: LOW · Contract · boundless-profile + boundless-events
Surfaced by the Almanax scan of e1f17937. Closes Earnings overflow silently clamps to i128 max and Saturating event-id counter can freeze at u64 max.
Files
contracts/profile/src/earnings.rs:28-30 — register earnings saturating_add
contracts/events/src/idempotency.rs:33-38 — next_event_id double saturating_add
Problem
- Earnings accumulate with
saturating_add, which silently pins a (user, token) value at i128::MAX forever on overflow → irrecoverable accounting drift; later increments are no-ops.
next_event_id saturating at u64::MAX freezes the counter, returning the same id forever → id collisions / event-state aliasing.
Fix
Use checked arithmetic that reverts with a typed error:
current.checked_add(amount).ok_or(Error::EarningsOverflow)?
id.checked_add(1).ok_or(Error::EventIdOverflow)? (and the stored next-id)
This aligns with the repo hard rule ("no unwrap on host Option/Result; return a typed Error"). Reverting is the correct failure mode for both.
Tests
- Overflow inputs return the typed error rather than clamping.
Severity: LOW · Contract ·
boundless-profile+boundless-eventsSurfaced by the Almanax scan of
e1f17937. ClosesEarnings overflow silently clamps to i128 maxandSaturating event-id counter can freeze at u64 max.Files
contracts/profile/src/earnings.rs:28-30—registerearningssaturating_addcontracts/events/src/idempotency.rs:33-38—next_event_iddoublesaturating_addProblem
saturating_add, which silently pins a(user, token)value ati128::MAXforever on overflow → irrecoverable accounting drift; later increments are no-ops.next_event_idsaturating atu64::MAXfreezes the counter, returning the same id forever → id collisions / event-state aliasing.Fix
Use checked arithmetic that reverts with a typed error:
current.checked_add(amount).ok_or(Error::EarningsOverflow)?id.checked_add(1).ok_or(Error::EventIdOverflow)?(and the stored next-id)This aligns with the repo hard rule ("no unwrap on host
Option/Result; return a typedError"). Reverting is the correct failure mode for both.Tests