Repository navigation
fix(confidential): reject set_spender with a past live_until_ledger - #955
ninglinLiu wants to merge 1 commit into
Conversation
set_spender stored a live_until_ledger that was already in the past. The proof was verified, the allowance was escrowed out of the owner's spendable balance, and the delegation was expired on arrival, so every confidential_transfer_from reverted with DelegationExpired until the owner revoked it. Revert with the new ConfidentialTokenError::InvalidLiveUntilLedger (3515) when live_until_ledger < ledger.sequence(), before the auditor lookup and proof verification. The bound is inclusive like the liveness check and the fungible set_allowance, so live_until_ledger == ledger.sequence() is still a valid single-ledger delegation. Fixes OpenZeppelin#947
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Expiry validation and boundary tests packages/confidential/src/lib.rs, packages/confidential/src/storage.rs, packages/confidential/src/test.rs |
ConfidentialTokenError adds InvalidLiveUntilLedger = 3515. set_spender rejects an expiration earlier than the current ledger before account retrieval and proof processing. Tests cover rejection of ledger 99 and acceptance of ledger 100 when the current ledger is 100. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers: brozorec
Merge Risk: 
Minimal · up to 904c9
-
The expiry validation and boundary behavior are consistent with the intended delegation contract, so the change is ready to merge.
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
Issue
#947requires an early rejection whenlive_until_ledger < e.ledger().sequence(), errorConfidentialTokenError::InvalidLiveUntilLedger = 3515, and acceptance at equality. The supplied change summary reports this check as the first operation instorage::set_spender, before lookups and proof verification. It also reports the new error declaration, error documentation, and tests for ledger 99 versus current ledger 100. These changes satisfy the stated coding and test requirements.
Full details: Out of Scope Changes check
-
Explanation
The reported changes are limited to the new error variant, the early
set_spenderliveness check and its documentation, and focused boundary tests. These changes directly implement issue#947. No unrelated production behavior or unrelated tests are identified.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the ledger’s page,
No stale expiry can engage.
At today’s mark, the grant may stay,
One code names what’s turned away.
Two tests hop through the boundary.
The burrow keeps the rules in view.
Comment @coderabbitai help to get the list of available commands.
Fixes #947
set_spendernow reverts with a newConfidentialTokenError::InvalidLiveUntilLedger = 3515whenlive_until_ledger < e.ledger().sequence(). Before this change, the delegation was expired as soon as it was stored, but the owner still paid for the proof and the escrow, and the(owner, spender)pair stayed blocked untilrevoke_spender.storage::set_spender, so it runs before the account and auditor lookups and before proof verification.ledger.sequence() <= live_until_ledger) and the fungibleset_allowance, solive_until_ledger == ledger.sequence()is still a valid single-ledger delegation.storage::set_spenderlists the new error in its# Errorsdocs.Tests
set_spender_with_past_live_until_ledger_panics: at ledger 100,live_until_ledger = 99panics with#3515.set_spender_with_current_ledger_is_live: at ledger 100,live_until_ledger = 100is stored andis_spenderreturns true.cargo test -p stellar-confidentialpasses (117 tests).cargo clippy -p stellar-confidential --all-targetsandcargo +nightly fmt --checkreport nothing for the changed files.PR Checklist
AI disclosure: I used an AI coding assistant to help write this change. I reviewed the diff and ran the tests above.
Summary by CodeRabbit