fix(contracts): add DivisionByZero error variant for checked_div sites - #671
Open
cashmotor01 wants to merge 2 commits into
Open
fix(contracts): add DivisionByZero error variant for checked_div sites#671cashmotor01 wants to merge 2 commits into
cashmotor01 wants to merge 2 commits into
Conversation
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.
|
@cashmotor01 is attempting to deploy a commit to the Collins' projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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 testpass locallyCloses #570