Fix/fee distribution rounding error#82
Fix/fee distribution rounding error#82caxtonacollins wants to merge 3 commits intoTrustless-Work:single-release-develop_v2from
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@armandocodecr please review |
|
@techrebelgit please review |
|
@techrebelgit hellooo |
Pull Request | Trustless Work
1. Issue Link
2. Brief Description of the Issue
A critical accounting vulnerability was identified in the
withdraw_remaining_fundsandresolve_disputefunctions. The contract transferred total fees upfront and then calculated each recipient's share using floor division. Due to rounding, the sum of individual fee shares was often less than the total fees transferred, leading to the contract attempting to distribute more funds than were actually available in its balance. This caused transaction reverts and potentially locked funds.Solution
Implemented Strategy 1: Deduct Individual Fees First.
Instead of transferring the total estimated fees upfront, the contract now:
actual_trustless_feesandactual_platform_fees.net_amountfor each recipient by subtracting their individual fee shares.This ensures that
actual_fees + sum(net_amounts)exactly equals the total amount being distributed, maintaining perfect accounting balance.Changes
contracts/escrow/src/core/dispute.rs: Refactoredwithdraw_remaining_fundsandresolve_disputeto use the new fee accumulation logic.contracts/escrow/src/tests/dispute_tests.rs: Addedtest_dispute_resolution_rounding_edge_caseto verify the fix with small amounts (2i128) that previously triggered reverts.Verification
cargo test): Passed (19 tests).Branch
fix/fee-distribution-rounding-error