Skip to content

[BFT-A][R8] Collapse CBE curve math to one canonical piecewise-linear engine #1925

@umwelt

Description

@umwelt

Title

[BFT-A][R8] Collapse CBE curve math to one canonical piecewise-linear engine

Category

  • R8 Invariants & Observability

Authoritative Inputs

  • CBE Bonding Curve — Complete Formula Reference
  • CBE Bonding Curve — Rust Implementation Specification section 4
  • Team decision: represent each band with p_start, not signed intercept b

Problem

The current issue incorrectly excluded sell-path math. The new docs require one canonical piecewise-linear engine that supports:

  • price_at
  • cost_single_band
  • multi-band mint traversal
  • inverse_mint
  • redemption-value computation for SELL_CBE
  • flat-band special-case minting

Current Behavior

The branch still carries duplicate curve implementations, approximation paths, and inconsistent band logic across canonical.rs, pricing.rs, and token.rs.

Required Behavior

Create exactly one canonical curve math engine with:

  • one band table
  • one lookup rule
  • one marginal price function using band-local form m_i * (S - S_start_i) + p_start_i
  • one exact single-band cost integral using the documented factored form in band-local coordinates
  • one exact multi-band traversal algorithm for buys
  • one exact multi-band redemption traversal for sells
  • one exact inverse mint function
  • one flat-band special-case path

The engine must be pure math only. No state access, no transaction parsing, no runtime dependencies.

Safety Impact

Multiple curve engines or mismatched buy/sell math create deterministic replay risk and break solvency/accounting invariants.

Proposed Fix

Replace the current parallel curve math paths with a single pure module built directly from the p_start-based band/cost/inverse formulas.

Dependencies

Acceptance Criteria

  • Exact piecewise-linear price lookup is implemented in p_start form
  • Exact cost_single_band implementation matches the documented order of operations and band-local factored formula
  • Exact multi-band mint traversal is implemented
  • Exact multi-band redemption-value math for SELL_CBE is implemented
  • Flat-band special-case mint logic is implemented
  • Duplicate native curve tables and approximation paths are non-authoritative

Test Plan

  • Band continuity tests
  • Band boundary lookup tests
  • Cross-band mint-cost equality tests
  • Inverse normalization vectors
  • Multi-band sell/redemption vectors
  • Flat-band vectors

Cleanup After

  • Remove native authority from duplicate curve math in pricing.rs and token.rs
  • Remove comments/tests that still describe spot-price minting shortcuts or signed intercept storage

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions