Problem
contracts/loyalty_token/src/lib.rs has inconsistent boundary conditions between approve() and get_allowance():
approve() rejects only if expiration_ledger < env.ledger().sequence() (strict less-than)
get_allowance() returns 0 when env.ledger().sequence() > d.expiration_ledger (strict greater-than)
A caller who sets expiration_ledger = current_sequence + 1 gets approval valid for only ~5 seconds (one ledger). There is no minimum validity window enforced, no maximum cap, and the semantics of expiration_ledger are undocumented - making it easy for integrators to create approvals that expire before they can be used.
Proposed Solution
- Add
MIN_APPROVAL_VALIDITY_LEDGERS: u32 = 17280 constant (~24 hours at 5s/ledger)
- Change
approve() to require expiration_ledger >= env.ledger().sequence() + MIN_APPROVAL_VALIDITY_LEDGERS
- Add a
MAX_APPROVAL_VALIDITY_LEDGERS cap (~1 year) to prevent indefinite approvals
- Document in code comments:
expiration_ledger is the LAST ledger at which the approval is valid (inclusive)
Acceptance Criteria
Problem
contracts/loyalty_token/src/lib.rshas inconsistent boundary conditions betweenapprove()andget_allowance():approve()rejects only ifexpiration_ledger < env.ledger().sequence()(strict less-than)get_allowance()returns 0 whenenv.ledger().sequence() > d.expiration_ledger(strict greater-than)A caller who sets
expiration_ledger = current_sequence + 1gets approval valid for only ~5 seconds (one ledger). There is no minimum validity window enforced, no maximum cap, and the semantics ofexpiration_ledgerare undocumented - making it easy for integrators to create approvals that expire before they can be used.Proposed Solution
MIN_APPROVAL_VALIDITY_LEDGERS: u32 = 17280constant (~24 hours at 5s/ledger)approve()to requireexpiration_ledger >= env.ledger().sequence() + MIN_APPROVAL_VALIDITY_LEDGERSMAX_APPROVAL_VALIDITY_LEDGERScap (~1 year) to prevent indefinite approvalsexpiration_ledgeris the LAST ledger at which the approval is valid (inclusive)Acceptance Criteria
expiration_ledger < current + MIN_APPROVAL_VALIDITY_LEDGERSpanics with"expiration too soon"expiration_ledgerexpiration_ledger + 1