Fix critical security issues #3, #5, #17, #20 - #234
Merged
chonilius merged 2 commits intoAug 30, 2026
Merged
Conversation
…i#20 This commit addresses four critical security and testing issues: Issue MergeFi#3: Token Accounting Protection - Implemented balance-delta measurement in measure_transfer_delta() - Protects against fee-on-transfer, rebasing, and malicious tokens - Updated fund() and contribute() in escrow and milestones contracts - Prevents accounting desync between bookkeeping and actual holdings Issue MergeFi#5: State Machine Bug Fix - Added milestone.closed check to release_issue() - Blocks release after cancel_milestone is called - Updated deallocate() workflow documentation for proper cancellation - Prevents inconsistent state transitions Issue MergeFi#20: Fee Update Mechanism - Added set_fee_bps() to escrow and milestones contracts - Implemented validate_fee_change() with 5% max change limit - Point-in-time fee locking: sponsors know fee when committing funds - Prevents accidental or malicious fee spikes Issue MergeFi#17: Property-Based Fuzz Testing - Added proptest dependency to workspace - Created test_fuzz.rs with 7 property tests + 3 edge case tests - Tests verify mathematical invariants: sum preservation, proportionality, monotonicity, bounds checking across wide input ranges - Catches edge cases that unit tests might miss Testing: - All 131 tests pass (58 escrow, 40 milestones, 23 maintenance-pool, 10 fuzz) - Fixed MockPanicToken in tests to support balance tracking - Fixed doctest examples Closes MergeFi#3, MergeFi#5, MergeFi#17, MergeFi#20
|
Someone is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@gideononiru Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
This PR addresses four critical security and testing issues identified in the MergeFi contracts audit.
Changes
Issue #3: Token Accounting Protection
Problem: Trusting caller-supplied amounts could lead to accounting desync with fee-on-transfer, rebasing, or malicious tokens.
Solution:
measure_transfer_delta()in common lib to measure actual balance changesfund()andcontribute()in both escrow and milestones contractsFiles Changed:
contracts/common/src/lib.rscontracts/escrow/src/lib.rscontracts/milestones/src/lib.rsIssue #5: State Machine Bug Fix
Problem:
release_issue()could be called aftercancel_milestone(), leading to inconsistent state.Solution:
milestone.closedcheck torelease_issue()Error::MilestoneClosedif milestone is already closeddeallocate()documentation for proper cancellation workflowFiles Changed:
contracts/milestones/src/lib.rsIssue #20: Fee Update Mechanism with Safety Limits
Problem: No mechanism to update protocol fees, and unlimited changes could harm sponsors.
Solution:
set_fee_bps()admin function to escrow and milestones contractsvalidate_fee_change()with 5% (500 bps) max change per callFiles Changed:
contracts/common/src/lib.rs(validation logic)contracts/escrow/src/lib.rscontracts/milestones/src/lib.rsIssue #17: Property-Based Fuzz Testing Infrastructure
Problem: Need more rigorous testing to catch edge cases in split calculations.
Solution:
proptestdependency to workspacetest_fuzz.rswith comprehensive property testsFiles Changed:
Cargo.tomlcontracts/common/Cargo.tomlcontracts/common/src/lib.rscontracts/common/src/test_fuzz.rs(new)Testing
MockPanicTokenin test files to support balance trackingCloses
cancel_milestonedoes not blockrelease_issuefor already-allocated, not-yet-released issues — budget/accounting invariant violation #5compute_splitcovering adversarial recipient vectors #17fee_bpsis immutable afterinitialize— design and implement a secure, bounded update mechanism #20