Skip to content

[STF] Saturate balances on incoming deferred transfers - #378

Merged
0xjunha merged 1 commit into
mainfrom
saturate-balance
Nov 20, 2026
Merged

0xjunha merged 1 commit into
mainfrom
saturate-balance

Conversation

@0xjunha

@0xjunha 0xjunha commented Nov 20, 2026

Copy link
Copy Markdown
Member

Summary

Saturates a service balance at 2^64−1 when the deferred transfers it receives in one accumulation would take it higher. No GP version defines this case. FastRoll follows the 0.8.0 fuzz campaign here.

Deviation from GP 0.8.0

  • The 0.8.0 fuzz campaign saturates at 2^64−1, listed in the Deviations of jam-fuzzing#212. GP doesn't describe this.
  • Previously, FastRoll failed the accumulation with AccountBalanceOverflow, so the block was rejected. In release builds the amounts were also summed with a wrapping .sum() before that check.

Changes

  • receive_deferred_transfer (Psi_A) uses the new AccumulatePartialState::saturating_add_account_balance.
  • AccumulateInputs::new sums the transfer amounts with saturation.
  • add_account_balance, subtract_account_balance and the new method share update_account_balance.
  • eject keeps add_account_balance and its AccountBalanceOverflow error, since the deviation covers only received transfers.

Tests

  • Unit tests for the saturating sum of transfer amounts, the saturating add, and add_account_balance (the eject path) still failing with AccountBalanceOverflow.

- caps a balance at `2^64-1` when the deferred transfers received in one `Ψ_A` take it above that value, following Polkajam in the 0.8.0 fuzz campaign since no GP version defines this case
- adds `saturating_add_account_balance` for `receive_deferred_transfer`, while `eject` keeps the `AccountBalanceOverflow` error
- sums the amounts in `AccumulateInputs::new` with saturation, which silently wrapped in release builds before
- shares `update_account_balance` among the balance helpers and tests both saturations and the kept overflow error
@0xjunha
0xjunha merged commit 2e97169 into main Nov 20, 2026
@0xjunha
0xjunha deleted the saturate-balance branch November 20, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant