test(nonce): add regression test for nonce persistence across inactiv… - #1261
Open
TechBroAfrica wants to merge 1 commit into
Open
test(nonce): add regression test for nonce persistence across inactiv…#1261TechBroAfrica wants to merge 1 commit into
TechBroAfrica wants to merge 1 commit into
Conversation
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.
closes #1225
Title
fix(credence_bond): move nonce storage from instance to persistent to prevent replay after archival
Summary
Nonce entries in the bond contract were stored in instance storage with a ~30-day TTL. If a user was inactive for longer, their nonce was archived and reset to 0, enabling replay of previously valid signed payloads. This is a security-critical fix.
The credence_delegation contract already uses persistent storage for nonces — the correct pattern. This PR aligns the bond contract with that same approach.
Proposed Changes
contracts/credence_bond/src/nonce.rs
contracts/credence_bond/src/test_replay_prevention.rs
Threat / Security Rationale
Under the old scheme, an attacker could wait for a victim's nonce entry to be archived (30 days of inactivity), then submit a previously captured signed payload with nonce 0. The contract would accept it because the archived nonce resets to 0. Moving to persistent storage eliminates this window: nonces are bumped on every access and never silently reset.
Migration Notes
For existing deployed instances: the first get_nonce call per identity after upgrade will return 0 (absent from persistent) even if a nonce existed in instance storage. This is safe — the identity has been inactive long enough for the instance entry to have been archived anyway, so no valid nonce was lost. Fresh deployments start entirely in persistent storage.
Testing & Verification
cargo test -p credence_bond
cargo clippy -p credence_bond --all-targets -- -D warnings