Skip to content

fix(contracts): add DivisionByZero error variant for checked_div sites - #671

Open
cashmotor01 wants to merge 2 commits into
drydocs:mainfrom
cashmotor01:fix/division-by-zero-error-variant
Open

fix(contracts): add DivisionByZero error variant for checked_div sites#671
cashmotor01 wants to merge 2 commits into
drydocs:mainfrom
cashmotor01:fix/division-by-zero-error-variant

Conversation

@cashmotor01

Copy link
Copy Markdown

Distinguish divide-by-zero from genuine arithmetic overflow. Previously all checked_div calls mapped None to ContractError::Overflow, making it impossible to tell from the error code alone whether the failure was a real i128 overflow or a degenerate zero divisor (e.g. broken adapter reporting zero total_assets).

Changes:

  • vault: add DivisionByZero = 19 to ContractError; update 4 checked_div sites (deposit shares, withdraw adapter shares, principal_out, migrate_adapter slippage bound) to use it
  • blend-adapter: add DivisionByZero = 3 to its own ContractError; update checked_div(RATE_SCALAR) in b_tokens_to_usdc to use it

Overflow is now reserved exclusively for checked_mul/checked_add failures. No breaking change — new variants are appended.

Summary

Test plan

  • pnpm lint && pnpm typecheck && pnpm test pass locally
  • [ ]

Closes #570

Distinguish divide-by-zero from genuine arithmetic overflow. Previously
all checked_div calls mapped None to ContractError::Overflow, making it
impossible to tell from the error code alone whether the failure was a
real i128 overflow or a degenerate zero divisor (e.g. broken adapter
reporting zero total_assets).

Changes:
- vault: add DivisionByZero = 19 to ContractError; update 4 checked_div
  sites (deposit shares, withdraw adapter shares, principal_out,
  migrate_adapter slippage bound) to use it
- blend-adapter: add DivisionByZero = 3 to its own ContractError; update
  checked_div(RATE_SCALAR) in b_tokens_to_usdc to use it

Overflow is now reserved exclusively for checked_mul/checked_add failures.
No breaking change — new variants are appended.
@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

@cashmotor01 is attempting to deploy a commit to the Collins' projects Team on Vercel.

A member of the Team first needs to authorize it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant