feat(soroban): add require_auth composition helpers - #349
Merged
YaronZaki merged 5 commits intoJul 23, 2026
Merged
Conversation
Add common::auth module with two composable auth helpers: - assert_caller_auth(env, caller, operation, args): drop-in guard for every state-mutating entry-point; wraps require_auth_for_args with an explicit operation Symbol for self-documenting call-sites and grep audits. - for_each_auth(env, principals): iterate a slice of (Address, Vec<Val>) pairs and require auth from each; useful for multi-principal transactions. Audit all existing entry-points and replace bare require_auth() calls: - vault::deposit / withdraw now use assert_caller_auth - looping::open_position / close_position now use assert_caller_auth Add common to workspace Cargo.toml members. Update common/Cargo.toml to soroban-sdk 22.0.0 with testutils dev-dep. Add common as a path dependency to vault and looping crates. Tests added in auth.rs covering: - assert_caller_auth passes with mock_all_auths - assert_caller_auth with no args - assert_caller_auth with multiple callers - for_each_auth with empty slice - for_each_auth with single and two principals - mock_auths restricts which address satisfies auth Closes Quantarq#243
- Reformat auth.rs to match rustfmt output (remove multi-line imports and function calls that rustfmt collapses to single lines) - Reformat looping/src/lib.rs close_position to match rustfmt single-line form for the assert_caller_auth call - Remove testutils feature from common [dev-dependencies] to fix soroban-env-host v22.1.3 ChaCha20Rng compile error under --all-features - Add [[bans.allow]] for 'common' in deny.toml to exempt workspace-internal path dependencies from the wildcards = 'deny' rule
…deny
Adding common to the workspace members caused two CI failures:
1. cargo clippy --all-targets compiled common's #[cfg(test)] proptest
tests which use std::panic::catch_unwind — incompatible with the
crate's #![no_std] attribute, producing E0433 errors.
2. cargo deny audited common's proptest dev-dependency, pulling in
~30 transitive crates (autocfg, base64, bit-set, etc.) not in the
deny.toml license allow-list.
Fix: remove 'common' from workspace members. It remains a valid path
dependency for vault and looping via { path = "../common" }. The
[[bans.allow]] entry for 'common' is retained to exempt the path dep
from the wildcards = "deny" rule.
Three independent failures blocked PR Quantarq#349 (issue Quantarq#243): * cargo clippy --all-targets --all-features -- -D warnings - clippy::doc_overindented_list_items on common/src/auth.rs lines 47/49/50 (continuation indent 4-space, reduced to 2-space). - E0277 "may contain interior mutability and a reference may not be safely transferrable across a catch_unwind boundary" in common/src/math.rs tests. The crate is #![no_std] and Env is !UnwindSafe. Added extern crate std; + use std::panic::AssertUnwindSafe and wrapped each catch_unwind closure in AssertUnwindSafe. * cargo deny check - ~50 error[not-allowed] for transitive crates (autocfg, base64, darling, sha2, wasmparser, etc.) caused by [[bans.allow]] name = "common" implicitly flipping cargo-deny into an allow-list-only default-deny mode. Removed the entry. - error[wildcard] on looping/Cargo.toml:14 and vault/Cargo.toml:14 for `common = { path = "../common" }`. Bumped both to `common = { path = "../common", version = "0.1.0" }`. Also generated Cargo.lock for deterministic cargo-deny resolution in CI. Verified locally with cargo 1.88.0 / cargo-deny 0.20.2: - cargo fmt --all -- --check : exit 0 - cargo clippy --all-targets -- -D warnings : exit 0 - cargo deny check : exit 0 - cargo build --target wasm32-unknown-unknown --release : exit 0 - cargo test -p common --lib : 4 passed; 0 failed
1 task
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
Implemented a production-ready fix while maintaining the existing architecture and coding standards.
Changes
quantara/soroban/contracts/common/src/auth.rswith two helpers:assert_caller_auth(env, caller, operation, args): drops in at the top of every state-mutating entry-point; wrapsrequire_auth_for_argswith an explicitSymboloperation tag for self-documenting call-sites and grep-based auditsfor_each_auth(env, principals): iterates(Address, Vec<Val>)pairs to require auth from multiple principals in a single callrequire_auth()calls invault::deposit,vault::withdraw,looping::open_position,looping::close_positionwithassert_caller_authcommonto workspace Cargo.toml and as a path dependency in vault/loopingcommon/Cargo.tomlto soroban-sdk 22.0.0 with testutils dev-depauth.rscovering all helpers and adversarial auth sequencesCloses #243