Title
[BFT-A][R9] Replace curve arithmetic with 18-decimal U256 fixed-point math and deterministic integer sqrt
Category
- R9 Negative Spec Enforcement
Authoritative Inputs
CBE Bonding Curve — Rust Implementation Specification sections 1, 3, and 4
Problem
The current issue understated the arithmetic requirements. The new docs fix the arithmetic contract tightly:
- all values stored as 18-decimal fixed-point
u128
U256 intermediates for widened multiplication
- floor-only division
- checked overflow rejection
- deterministic integer square root
- fixed operation order
Current Behavior
Curve-adjacent code still contains mixed scales, float usage, saturating arithmetic, and duplicate sqrt helpers. There is no single canonical U256 arithmetic layer for the documented curve engine.
Required Behavior
All consensus-reachable curve arithmetic, and any branch code that directly feeds documented curve execution, must follow the new rules exactly:
SCALE = 10^18
- widen
u128 -> U256 before multiplication
- floor division only
- overflow = reject with zero mutation
- deterministic
integer_sqrt(U256) satisfying the documented invariants
- fixed evaluation order matching the spec
- flat-band special case support:
delta_s = reserve_credit * SCALE / intercept
This issue no longer claims general oracle cleanup beyond code that directly feeds the documented curve path.
Safety Impact
If the arithmetic layer differs from the new spec, nodes can diverge on price, mint amount, redemption value, fee calculation, and graduation timing.
Proposed Fix
Add one canonical curve-math module and migrate all consensus-reachable curve arithmetic to it.
Dependencies
Acceptance Criteria
Test Plan
- Overflow rejection vectors
- Floor-division vectors
integer_sqrt property tests
- Large discriminant vectors
- Operation-order regression vectors for
cost_single_band and inverse_mint
- Flat-band mint vectors
Cleanup After
- Remove or isolate old Newton/float helpers from consensus curve paths
- Remove stale
1e8 pricing assumptions where they still feed documented curve behavior
Title
[BFT-A][R9] Replace curve arithmetic with 18-decimal U256 fixed-point math and deterministic integer sqrt
Category
Authoritative Inputs
CBE Bonding Curve — Rust Implementation Specificationsections 1, 3, and 4Problem
The current issue understated the arithmetic requirements. The new docs fix the arithmetic contract tightly:
u128U256intermediates for widened multiplicationCurrent Behavior
Curve-adjacent code still contains mixed scales, float usage, saturating arithmetic, and duplicate sqrt helpers. There is no single canonical
U256arithmetic layer for the documented curve engine.Required Behavior
All consensus-reachable curve arithmetic, and any branch code that directly feeds documented curve execution, must follow the new rules exactly:
SCALE = 10^18u128 -> U256before multiplicationinteger_sqrt(U256)satisfying the documented invariantsdelta_s = reserve_credit * SCALE / interceptThis issue no longer claims general oracle cleanup beyond code that directly feeds the documented curve path.
Safety Impact
If the arithmetic layer differs from the new spec, nodes can diverge on price, mint amount, redemption value, fee calculation, and graduation timing.
Proposed Fix
Add one canonical curve-math module and migrate all consensus-reachable curve arithmetic to it.
Dependencies
Acceptance Criteria
scaled_mul/scaled_divhelpers exist on top ofU256integer_sqrt(U256)exists and is used by curve inversioncost_single_bandandinverse_mintmatches the specTest Plan
integer_sqrtproperty testscost_single_bandandinverse_mintCleanup After
1e8pricing assumptions where they still feed documented curve behavior