feat: reject stale authorization nonces on admin actions (#1223) - #1246
Merged
mikewheeleer merged 2 commits intoAug 30, 2026
Merged
Conversation
Add persistent, monotonic admin-nonce consumption for all admin-gated entrypoints to completely prevent replay attacks on signed administrative operations. ## Changes ### Core (escrow/src/lib.rs) - Add instance-storage key for monotonic nonce tracking - Add (code 85) for stale/duplicate/future nonces - Implement helper that atomically validates and increments - Add read-only entrypoint for callers to query current nonce - Integrate nonce validation into all 17 admin-gated entrypoints: set_legal_hold, clear_legal_hold, request_clear_legal_hold, set_allowlist_active, set_investor_allowlisted, set_investors_allowlisted, update_funding_target, update_funding_deadline, lower_max_unique_investors, update_maturity, update_maturity_max_horizon, migrate, upgrade, cancel_funding, propose_admin, cancel_pending_admin, rotate_beneficiary - Pass nonce through deprecated transfer_admin to propose_admin delegation ### Tests (escrow/src/tests/admin_nonce.rs) - New comprehensive test module covering all required edge cases: - Next nonce succeeds and increments - Old nonce (replay) rejected - Future nonce (out-of-order) rejected - Duplicate nonce (race condition) rejected - Nonce near u32::MAX overflow protection - Shared nonce across different entrypoints - Nonce consumed even when downstream validation fails (migrate) - Error does not leak internal details ### Test Updates - Updated all existing tests across 11 test files to include nonce parameter ## Architecture - Nonce stored in instance storage under DataKey::AdminNonce (u32) - Starts at 0; defaults to 0 for legacy deployments missing the key - Consumed atomically after admin auth, before state mutations - Single error code (AdminNonceMismatch) for all mismatch types - Backward-compatible: append-only error semantics, no storage layout changes Closes Liquifact#1223
|
@adeboladee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
13 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
Implements persistent, monotonic admin-nonce consumption for all admin-gated entrypoints to completely prevent replay attacks on signed administrative operations.
Architectural Approach
Storage
DataKey::AdminNoncein instance storage (u32)0; defaults to0for legacy deployments missing the key (backward-compatible via.unwrap_or(0))Nonce Consumption Flow
Error Handling
EscrowError::AdminNonceMismatch(85)Atomicity
checked_add(1)with overflow protection: u32::MAX nonce returns the same error codeSecurity & Failure-Mode Handling
AdminNonceMismatch— nonce unchangedAdminNonceMismatch— nonce unchangedAdminNonceMismatch— nonce unchangedEdge-Case Test Coverage
nonce_starts_at_zeronext_nonce_succeeds_and_incrementssequential_nonces_succeedold_nonce_rejectedold_nonce_after_multiple_actions_rejectedfuture_nonce_rejectedfuture_nonce_after_actions_rejectedduplicate_nonce_second_call_rejectedtwo_identical_nonces_different_entrypointsnonce_at_max_minus_one_succeedsnonce_at_max_overflow_rejectednonce_shared_across_entrypointspropose_admin_increments_noncecancel_pending_admin_increments_nonceset_legal_hold_uses_noncerequest_clear_legal_hold_uses_nonceclear_legal_hold_uses_noncestale_nonce_error_matches_future_nonce_errormigrate_uses_nonceFiles Changed
escrow/src/lib.rsescrow/src/tests/admin_nonce.rsescrow/src/tests.rsValidation Evidence
Acceptance Criteria
DataKey::AdminNonceAdminNonceMismatch= 85)Closes #1223