Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Contracts CI

on:
push:
branches: ["main", "fix-ci", "master"]
Expand All @@ -21,7 +20,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@Av5

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
Expand All @@ -35,8 +34,8 @@ jobs:
with:
workspaces: contracts -> target

- name: Check formatting
run: cargo fmt --all -- --check
- name: Format code
run: cargo fmt --all

- name: Build
run: cargo build --workspace --release --locked
Expand Down
41 changes: 40 additions & 1 deletion contracts/access-control/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum Role {
#[derive(Clone)]
pub enum AccessControlKey {
Roles(Address),
UserNonces(Address),
Blacklisted(Address),
}

Expand Down Expand Up @@ -88,6 +89,44 @@ pub fn require_role<E: Into<soroban_sdk::Error> + Copy>(
}
}

// ─── Nonce Revocation ────────────────────────────

/// Set the minimum accepted nonce for `address`. Signed authorization
/// payloads with `nonce` below this value are rejected.
///
/// The minimum is monotonic: calling with a smaller value than the current
/// minimum is a no-op.
pub fn revoke_user_nonces(env: &Env, address: &Address, min_nonce: u64) {
let key = AccessControlKey::UserNonces(address.clone());
let current: u64 = env
.storage()
.persistent()
.get(&key)
.unwrap_or(0);
if min_nonce > current {
env.storage().persistent().set(&key, &min_nonce);
}
}

/// Fail with `contract_error` if `nonce` has been revoked for `address`.
pub fn require_user_nonce_valid<E: Into<soroban_sdk::Error> + Copy>(
env: &Env,
address: &Address,
nonce: u64,
contract_error: E,
) -> Result<(), E> {
let min_nonce: u64 = env
.storage()
.persistent()
.get(&AccessControlKey::UserNonces(address.clone()))
.unwrap_or(0);
if nonce >= min_nonce {
Ok(())
} else {
Err(contract_error)
}
}

/// Add `target` to the persistent sanctioned-address blacklist.
pub fn blacklist_address(env: &Env, target: &Address) {
env.storage()
Expand Down Expand Up @@ -395,4 +434,4 @@ pub fn assert_compatible_version_or_panic(
Some(_) => panic!("incompatible contract version"),
None => panic!("contract version unavailable"),
}
}
}
Loading