Skip to content

Cost budget charges can overspend the remaining budget and use inexact floating point accounting #58

@nficano

Description

@nficano

CostBudgetAmount stores protocol decimal amounts as f64 in src/messages/permissions.rs:18, and BudgetTracker::charge in src/runtime/context.rs:120 checks only whether the remaining budget is already at or below zero before adding the new amount. A single call such as charging USD 100.0 against a remaining budget of 1.0 succeeds and returns a negative remaining value, so the operation that exceeded the lease is allowed to complete and the next charge is the one that fails. That contradicts the README's claim at README.md:108 that the runtime enforces the lease at every operation boundary, and binary floating point also makes boundary comparisons for decimal money or credits vulnerable to rounding artifacts.

Fix prompt: Represent cost budgets with an exact decimal or fixed-point type at the protocol boundary, preserving string serialization while avoiding binary floating point comparisons. Update BudgetTracker::charge to reject the charge that would exceed the remaining budget, optionally recording the attempted overspend for metrics without returning success, and add boundary tests for an oversized single charge, exact exhaustion, fractional decimal values such as 0.10 plus 0.20, and multi-currency accounting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingseverity:highHigh severity issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions