fix(InventoryClient): guard zero allocation denominator in determineRefundChainId - #3759
fix(InventoryClient): guard zero allocation denominator in determineRefundChainId#3759droplet-rl wants to merge 1 commit into
Conversation
determineRefundChainId divided the per-chain post-relay balance by the cumulative virtual balance without a zero check. A token that is enabled in tokenConfig but holds no virtual balance on any chain, with no upcoming refunds, makes that denominator zero and BigNumber.div throws division-by-zero. The throw is unhandled through resolveRepaymentChain and checkForUnfilledDepositsAndFill, so the process exits. Treat a zero denominator as zero allocation, matching getCurrentAllocationPct and getChainDistribution. Candidate chains then read as unallocated and the deposit is skipped downstream on the existing balance check, which records a token shortfall rather than crashing. Co-Authored-By: Claude <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
The comment that triggered me was the review-summary placeholder in its It has since completed on Since I had the branch checked out, I re-verified the change locally rather than just taking CI's word for it:
One note on the substance, for a human reviewer: the guard is not a novel pattern. This was the one automated review round allowed on this PR, and it came back clean, so I'm not re-triggering it. If anyone wants deeper scrutiny of the downstream-skip reasoning — that's the part where a human eye is most useful, since it's a behavioural claim rather than a mechanical one — assign me to the PR and I can iterate further. |
determineRefundChainId()divides the per-chain post-relay balance by the cumulative virtual balance with no zero check. A token enabled intokenConfigbut holding no virtual balance on any chain, with no upcoming refunds, makes that denominator zero, and ethersBigNumber.divthrowsdivision-by-zero.Nothing catches it between
determineRefundChainIdandcheckForUnfilledDepositsAndFill, so the throw reachesindex.tsand the process exits. Repayment resolution runs before the balance check inevaluateFill, so a deposit the relayer could never fill still reaches this path — the reachable case is a token configured before it is funded, e.g. a fresh deployment or a newly added token/chain.Treat a zero denominator as zero allocation, matching the existing checks in
getCurrentAllocationPct()andgetChainDistribution(). Candidate chains then read as unallocated and the deposit is skipped downstream on the existinghasBalanceForFillcheck, which records a token shortfall for the rebalancer instead of crashing.Test added to
InventoryClient.RefundChain.tscovering a zero cumulative balance. No doc change — behaviour is unchanged whenever the denominator is non-zero.🤖 Generated with Claude Code