fix: unify validity-range semantics across Linear Vesting and Two-Party Escrow#175
Open
fix: unify validity-range semantics across Linear Vesting and Two-Party Escrow#175
Conversation
…ty Escrow Migrates both scenarios to the same production-safe convention introduced for HTLC in #170: "before deadline" checks read the upper bound; "after deadline" checks read the lower bound. Both helpers reject infinite/missing bounds with a traceError. Key changes: - LinearVesting: lowerBoundTime now returns POSIXTime (was Integer); adds upperBoundTime for API parity; both validators use lowerBoundTime. - TwoPartyEscrow: deposit now records depositTime via upperBoundTime so an attacker cannot pass validRange=[0,+∞) to force depositTime=0; refund uses lowerBoundTime with a strict > check (removes succ + contains). - cape-tests.json: point-interval fixtures for deposit; new coverage tests for infinite-bound rejection in both scenarios. - Hspec: matching tests for all new failure paths. - Recompile and remeasure Plinth 1.45 and 1.61 submissions. Closes #171
Contributor
🚀 PR Preview DeployedPreview URL: https://intersectmbo.github.io/UPLC-CAPE/pr-175/ The preview site is automatically updated on every push to this PR and will be removed when the PR is closed. |
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.
Context
depositTimefrom the unchecked lower bound, enabling an attacker to submitvalidRange = [0, +∞)and recorddepositTime = 0, making the refund deadline immediately expired.Approach
HTLC (#170) established a two-helper pattern:
lowerBoundTimefor "after deadline" checks andupperBoundTimefor "before deadline" checks. Both helpers:traceErroron infinite or missing bounds, preventing malformed ranges from bypassing time checks.Linear Vesting only has "after deadline" checks (PartialUnlock, FullUnlock), so
lowerBoundTimewas already the right choice. The fix is purely a type-level cleanup: the helper now returnsPOSIXTimeinstead ofInteger, andupperBoundTimeis added for API parity.Two-Party Escrow needed a security fix: the deposit validator was extracting time from the lower bound without validating infinity or the inclusive/exclusive flag. The refund validator used
from refundDeadline contains nowRange(≥ semantics) with asucchack. Both are replaced with the canonical helpers and a directlessThanEqualsIntegercomparison.Changes
lib/LinearVesting.hslowerBoundTimereturnsPOSIXTime(wasInteger); error message updatedupperBoundTime(unused but present for API consistency)POSIXTime currentTime = lowerBoundTime ...lib/TwoPartyEscrow.hslowerBoundTime/upperBoundTime(verbatim from HTLC)invalidDepositDatum: recordsdepositTime = upperBoundTime validRange(rejects+∞)validateRefund: replacedsucc/containswithlowerBoundTime+lessThanEqualsIntegerimport PlutusLedgerApi.V1.Data.Interval(no longer needed)scenarios/*/cape-tests.jsontwo_party_escrow:successful_depositchanged to point interval[1000, 1000]; new testsdeposit_infinite_upper_boundandrefund_infinite_lower_boundlinear_vesting: new testspartial_unlock_infinite_lower_boundandfull_unlock_infinite_lower_boundscenarios/*/scenario.mdtest/LinearVestingSpec.hs/test/TwoPartyEscrowSpec.hsitblocks covering all four new failure pathsSubmissions
Author's Checklist
cape submission verifypasses for all four touched submissions