-
Notifications
You must be signed in to change notification settings - Fork 102
[Bug] Overflow error returned for a divide-by-zero condition #570
Copy link
Copy link
Closed
Labels
Stellar WaveIssues in the Stellar wave programIssues in the Stellar wave programbugSomething isn't workingSomething isn't workingcontractsInvolves writing or testing Rust/Soroban contracts in packages/contractsInvolves writing or testing Rust/Soroban contracts in packages/contractstrivialSelf-contained task, completable in < 2 hours with no deep protocol knowledge requiredSelf-contained task, completable in < 2 hours with no deep protocol knowledge required
Description
Activity
Metadata
Metadata
Assignees
Labels
Stellar WaveIssues in the Stellar wave programIssues in the Stellar wave programbugSomething isn't workingSomething isn't workingcontractsInvolves writing or testing Rust/Soroban contracts in packages/contractsInvolves writing or testing Rust/Soroban contracts in packages/contractstrivialSelf-contained task, completable in < 2 hours with no deep protocol knowledge requiredSelf-contained task, completable in < 2 hours with no deep protocol knowledge required
Description
Several
checked_divcall sites map aNoneresult (which for these particular divisions actually indicates a divide-by-zero, itself a symptom of a broken adapter reporting negative or zerototal_assets) to the sameContractError::Overflowvariant used for genuine multiplication/addition overflow. This misdiagnoses the failure for anyone debugging from the error code alone.Steps to Reproduce
checked_divcalls is zero (e.g. via a broken adapter reporting degenerate totals).ContractError::Overflow, indistinguishable from an actual arithmetic overflow elsewhere in the same function.Expected Behavior
Divide-by-zero and genuine overflow should be distinguishable error variants, since they point to different root causes and different fixes.
Actual Behavior
Both map to
ContractError::Overflow.Environment
Transaction Details (if on-chain)
Logs / Screenshots
Possible Cause / Fix
Add
DivisionByZero = 19and use it at everychecked_divsite, keepingOverflowreserved forchecked_mul/checked_addfailures only.Scope