[CO-07] Fix off-by-one expiry in loyalty_token approve() causing immediate silent expiration#291
Merged
Leothosine merged 3 commits intoJun 25, 2026
Conversation
Leothosine
approved these changes
Jun 24, 2026
…er with expiry fix
…er with expiry validation - Keep MIN/MAX_APPROVAL_VALIDITY_LEDGERS constants and updated approve() from PR - Preserve two-step admin transfer (PendingAdmin, accept_admin, cancel_transfer) from main - Update test_approve_and_transfer_from to use 17_280 ledger window (MIN_APPROVAL_VALIDITY_LEDGERS) - Retain all expiry boundary tests from PR and two-step admin tests from main
Leothosine
approved these changes
Jun 25, 2026
Closed
5 tasks
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
Fixes the misaligned boundary in
loyalty_token approve()that allowed callers to set expiry windows as short as 1 ledger (~5 seconds), causing approvals to silently expire almost immediately.Changes in
contracts/loyalty_token/src/lib.rsMIN_APPROVAL_VALIDITY_LEDGERS: u32 = 17_280(~24 hours at 5-second ledger close)MAX_APPROVAL_VALIDITY_LEDGERS: u32 = 6_307_200(~1 year) to prevent indefinite approvalsapprove()to panic with"expiration too soon"whenexpiration_ledger < current + MIN_APPROVAL_VALIDITY_LEDGERSapprove()to panic with"expiration too far in the future"when above the capexpiration_ledgeris inclusive (valid through that ledger, expires atexpiration_ledger + 1)get_allowance()to make the inclusive semantics explicitTests updated / added
test_approve_and_transfer_fromto use+ 17_280instead of the old+ 1_000(which was below the new minimum)test_approve_expiry_too_soon_panics- expiry below minimum must panic with"expiration too soon"test_approve_minimum_valid_expiry- expiry exactly at minimum is acceptedtest_allowance_valid_at_expiry_ledger- allowance is still non-zero at the exact expiry ledger (inclusive boundary)test_allowance_zero_after_expiry_ledger- allowance returns 0 one ledger past expirycloses #285