fix(escrow): implement InsufficientBalance and remove NotExpired - #70
Open
Devadakene wants to merge 1 commit into
Open
fix(escrow): implement InsufficientBalance and remove NotExpired#70Devadakene wants to merge 1 commit into
Devadakene wants to merge 1 commit into
Conversation
- Wired InsufficientBalance into release and refund as a defensive check against the contract's actual token balance, making the solvency invariant enforced at runtime. - Removed NotExpired as it was confirmed to be unused scaffolding. - Added tests to verify InsufficientBalance check.
|
Someone is attempting to deploy a commit to the chonilius' 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.
Closes #48
Overview
This PR addresses the presence of two unused error variants in the Escrow contract's public ABI:
Error::NotExpiredandError::InsufficientBalance.After investigating the git history, it was confirmed that both variants were dead scaffolding introduced in the initial commit (
d17fc888) and were never actually wired up in the contract logic.As part of this cleanup:
InsufficientBalancehas been implemented as a genuine defense-in-depth check in thereleaseandrefundoperational flows.NotExpiredhas been removed from the ABI as it serves no purpose.Changes
1. Enforcing
InsufficientBalanceCheckThe escrow's
releaseandrefundoperations previously trusted the originalescrow.amountrecorded at the time of funding without verifying the contract's actual on-chain token balance before transferring.While Soroban's
token_client.transferinherently panics on insufficient funds, explicitly verifying the balance allows the contract to fail gracefully with a typedError::InsufficientBalance. This is a meaningful defense-in-depth addition that aligns with the maintenance-pool contract's approach. It guarantees the solvency invariant (balance covers obligations) is proactively verified at runtime at the exact moment of payment.Files modified:
contracts/escrow/src/lib.rstoken_client.balance(&contract_address) < escrow.amountto thereleasefunction.token_client.balance(&contract_address) < escrow.amountto therefundfunction.2. Removing
NotExpiredNotExpiredwas determined to be a relic with no structural purpose, given that early refunds are protected natively byrequire_authpanics rather than typed error results.To clean up the ABI,
NotExpiredhas been removed entirely.Files modified:
contracts/escrow/src/error.rsNotExpired = 10.3. Testing
Tests were added to explicitly verify that the contract properly intercepts and rejects payouts with
Error::InsufficientBalancewhen the token balance is artificially drained.Files modified:
contracts/escrow/src/test.rstest_release_rejects_if_contract_balance_insufficient: Simulates draining the contract balance prior to an admin release and assertsError::InsufficientBalanceis returned.test_refund_rejects_if_contract_balance_insufficient: Simulates draining the contract balance prior to a post-deadline permissionless refund and assertsError::InsufficientBalanceis returned.Acceptance Criteria Met
NotExpired/InsufficientBalanceorigin concluded and documented.InsufficientBalanceis fully wired intoreleaseandrefundas a genuine defensive balance check.NotExpiredvariant removed with an explicitly documented rationale in the source.