Skip to content

[Bug] Overflow error returned for a divide-by-zero condition #570

Description

@collinsezedike

Description

Several checked_div call sites map a None result (which for these particular divisions actually indicates a divide-by-zero, itself a symptom of a broken adapter reporting negative or zero total_assets) to the same ContractError::Overflow variant used for genuine multiplication/addition overflow. This misdiagnoses the failure for anyone debugging from the error code alone.

Steps to Reproduce

  1. Reach a state where a divisor in one of the listed checked_div calls is zero (e.g. via a broken adapter reporting degenerate totals).
  2. The call returns 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

Field Value
Network testnet / mainnet
Wallet N/A (contract-level)
Protocol affected Blend
Browser (if frontend) N/A
Node.js version N/A
pnpm version N/A

Transaction Details (if on-chain)

  • Transaction hash: N/A — identified by static review
  • Ledger: N/A
  • Soroban RPC endpoint used: N/A

Logs / Screenshots

vault/src/lib.rs:186, 280, 312, 511
blend-adapter/src/lib.rs:43-44
.checked_div(...).ok_or(ContractError::Overflow)?   // also covers divide-by-zero

Possible Cause / Fix

Add DivisionByZero = 19 and use it at every checked_div site, keeping Overflow reserved for checked_mul/checked_add failures only.

Scope

Field Value
Area Contracts
Protocol affected Blend
Network testnet, mainnet
Breaking change? No — new error variant, appended

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingcontractsInvolves writing or testing Rust/Soroban contracts in packages/contractstrivialSelf-contained task, completable in < 2 hours with no deep protocol knowledge required

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions