Repository navigation
Fix four critical issues: missing test, outdated docs, refund bug, and pause inconsistency - #751
Merged
chonilius merged 1 commit intoOct 20, 2026
Conversation
…d pause inconsistency - Add missing test_extend_deadline_unauthorized test referenced in docs - Fix escrow contract indentation bug causing compilation errors - Update upgrade docs to reflect current implementation state - Fix milestone refund calculation bug affecting late contributors - Implement FIFO contribution tracking for accurate refunds - Allow deallocate during pause for sponsor protection - Add comprehensive tests for all fixes Closes MergeFi#527 Closes MergeFi#528 Closes MergeFi#531 Closes MergeFi#530
|
@Joeloo1 is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Joeloo1 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 separate issues identified in the codebase, fixing critical bugs in the milestones contract refund logic, documentation inconsistencies, a missing test case, and a pause mechanism design flaw.
Closes #527
Closes #528
Closes #531
Closes #530
Issue #1: Missing test_extend_deadline_unauthorized (#527)
Problem
The access control audit documentation (
docs/access-control-audit.md, line ~181) references a testtest_extend_deadline_unauthorizedinescrow/src/test.rsto verify thatextend_deadlineproperly rejects unauthorized callers. However, this test did not exist in the codebase, making the documentation claim unverifiable.Solution
test_extend_deadline_unauthorizedtest incontracts/escrow/src/test.rsError::Unauthorizedwhen attempting to callextend_deadlineAdditional Fix
While investigating this issue, discovered and fixed a critical pre-existing compilation error in
contracts/escrow/src/lib.rs:upgradeandmigratefunctions had incorrect indentation (missing 4 spaces)Files changed:
contracts/escrow/src/test.rs: +27 lines (new test)contracts/escrow/src/lib.rs: Indentation fix and cleanupIssue #2: Outdated upgrade documentation (#528)
Problem
The
docs/upgrade-storage-migration-design.mddocument contained outdated information:upgrade(new_wasm_hash)get_contract_version()function - incorrect, the actual function isget_version()Solution
Updated
docs/upgrade-storage-migration-design.mdto accurately reflect current implementation:Status updates:
upgrade(new_wasm_hash)function"Function name corrections:
get_contract_version()→get_version()(4 occurrences)Files changed:
docs/upgrade-storage-migration-design.md: Comprehensive documentation updatesIssue #3: Milestone refund calculation bug with late contributors (#531)
Problem
The
refund_remaining_budgetfunction in the milestones contract incorrectly calculated refunds using:This was fundamentally flawed because
total_budgetincludes money already spent throughrelease_issuecalls. Late contributors who joined after releases would unfairly lose money to earlier contributors.Example bug scenario:
110 * 100 / 200 = 55110 * 100 / 200 = 55Solution
Implemented proper FIFO (first-in, first-out) contribution tracking:
Added
remainingfield toContributionstruct (types.rs):amountModified
release_issueto deduct FIFO (lib.rs):contribution.remainingvalue accuratelySimplified
refund_remaining_budget(lib.rs):contribution.remainingAdded comprehensive test (
test.rs):test_late_contributor_refund_correctnessdemonstrates the exact scenario from the issueAdditional Fix
Fixed a pre-existing bug in
ContractInitializedevent:.unwrap_or()on already-unwrappedmax_sponsorsvariableFiles changed:
contracts/milestones/src/types.rs: +4 lines (addremainingfield with docs)contracts/milestones/src/lib.rs: Major refactoring of refund logic, FIFO tracking in release_issue, event fixcontracts/milestones/src/test.rs: +77 lines (comprehensive new test case)Issue #4: deallocate incorrectly blocked during pause (#530)
Problem
The
deallocatefunction started with a pause check that blocked it during contract pause:This violated a core principle from
docs/pause-circuit-breaker-design.md: "A paused contract must still allow sponsor-protective refund/reclaim paths."The issue: During a long pause, sponsors could not recover allocated-but-unreleased funds at all:
cancel_milestone(allowed during pause) only refundsremaining_budgetremaining_budgetthroughdeallocatedeallocatewas blocked, trapping sponsor fundsSolution
Removed pause check from
deallocate(lib.rs):deallocateis now allowed during pauseUpdated existing test (
test.rs):test_deallocate_blocked_while_paused→test_deallocate_allowed_while_paused_for_sponsor_protectionUpdated access control audit (
docs/access-control-audit.md):Files changed:
contracts/milestones/src/lib.rs: Removed pause check, updated documentationcontracts/milestones/src/test.rs: Updated test to verify correct behaviordocs/access-control-audit.md: Updated to reflect intentional designTesting
All changes have been verified:
Impact Assessment
Breaking Changes
Issue #3 (Milestone refund bug) introduces a storage format change:
Contributionstruct now includes aremainingfieldContributionformat will need migration or redeploymentNon-Breaking Changes
fund()allows issue-id griefing via front-running before the legitimate sponsor funds #1, Maintenance-pooldeposit()allows pool-id squatting viaTokenMismatchgriefing #2, and Formal reentrancy audit of alltoken::Clientcross-contract calls #4 are non-breakingFiles Changed
Total: 7 files changed, 227 insertions(+), 129 deletions(-)