ClosedBit error docs

CB_ERR_UNDERFLOW

u256 underflow. A checked unsigned 256-bit subtraction or operation produced a negative result.

Why it happens

A checked unsigned 256-bit subtraction or operation produced a negative result.

How to fix it

Compare before subtracting, clamp to zero, or use a signed type when negative values are intentional.

Copy-paste fix pattern
library CB-Math

fn main() {
    u256 coins = 10
    u256 cost = 20
    u256 safe = CB-Math.max(coins, cost) - cost
    save safe
}
If the IDE reports a line number, fix that line first, then scan the previous line for an unclosed string, bracket, or block.