Feat/auth snapshot#899
Open
Power70 wants to merge 13 commits into
Open
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.
Per-Entrypoint Auth Snapshot Test
Closes #829
Summary
Adds an integration suite that snapshots the Soroban authorization required by every
state-changing entrypoint of
PredictifyHybrid. Rather than only asserting "authorizedsucceeds / unauthorized fails", each test inspects
env.auths()after the call and pinswhich address the host actually required an authorization from.
This catches two regressions a pass/fail test misses: a
require_authsilently dropped(auth set becomes empty), and an auth subject rebound to the wrong argument.
Writing the suite surfaced three real authorization defects and a set of pre-existing build
breakages that stopped the crate compiling at all. Both are fixed here so the suite can run.
Changes
Tests
tests/auth_snapshot.rs(new) — 24 tests: committed-snapshot assertions for 13entrypoints, auth-boundary assertions for 3, read-only entrypoints pinned to no auth,
plus edge cases (wrong-subject binding, subject tracking across users, non-admin
rejection,
#[should_panic]no-auth traps). The fixture registers a real Stellar AssetContract so stake transfers commit.
Cargo.toml— registered theauth_snapshottest target.Authorization fixes
Soroban rejects a second
require_authon an already-authorized frame(
Error(Auth, ExistingValue)). Three paths authorized the same address twice — entrypointand inner manager — so they could never succeed on-chain:
fees.rs— redundantadmin.require_auth()inFeeManager::collect_fees. It was#[cfg(not(test))]-gated, so unit tests masked it while production builds hit it.disputes.rs— redundantuser.require_auth()inDisputeManager::dispute_market.rate_limiter.rs— redundantuser.require_auth()inrate_limit_voting/rate_limit_disputes.Auth strength is unchanged: each is still enforced by the calling entrypoint
(
require_primary_adminfor admin paths,user.require_auth()for user paths).Build restoration
The crate did not compile on
master:e5db2d8collapsedlib.rsto a "minimal workingversion" and later PRs re-added call sites without restoring their definitions.
lib.rs— restored 14 droppedmoddeclarations; theinitialize/deposit/withdraw/get_balanceentrypoints; the admin-auth helpers (stored_primary_admin,require_primary_admin{,_or_panic},require_initialized_admin_root,require_admin_permission); theSYM_*/PERCENTAGE_DENOMINATORconstants and theresolution_timeout_reached/automatic_oracle_result_unavailablehelpers. Removedduplicate imports, fixed 7 invalid
Addressderefs, repointedcapabilities().resolution.rs— repaired a mis-merge that spliced a payout-distribution body intoimpl ResolutionOutcomeCacheand intodetermine_outcome_from_oracle_data; restored thecache methods 6 modules call,
ResolutionAnalytics/MedianResolutionResult, and theOracleResolutionManagerimpl boundary.market_id_generator.rs— restored the clean file from28c8db4.err.rs— removed a duplicateReplayedOverride; added 6 declared-nowhere variants;catch-all arms on
description()/code().storage.rs— removed a duplicateAdminOverrideNonce; addedPlaceBetsIdemandAntiGriefFloor.gas.rs—Env::budget()is test-only, soBudgetGuarddegrades to a no-op outsidetests; fixed an oversized
symbol_short!and an invalidDefaultderive.upgrade_manager.rs— fixed au32/u64branch mismatch.Auth matrix
create_market,resolve_market_manual,collect_fees,set_platform_fee,set_treasury,set_global_claim_period,set_market_claim_period,extend_deadlinesweep_unclaimed_winningsvote,place_bet,cancel_betclaim_winnings,dispute_marketget_market,get_market_bet_statsCommitted snapshot — the call is driven through a fully satisfied happy path and the auth
is read back from
env.auths(). Auth boundary — the host rolls back recorded auths when acall traps or returns
Err, so entrypoints needing state the fixture does not build assertinstead that an authorized call gets past
require_authwhile an unauthorized one traps.API / visible changes
None. The suite is test-only, and the three fixes remove redundant authorization calls
without weakening any check.
Testing
cargo test -p predictify-hybrid --test auth_snapshotcargo build -p predictify-hybrid --libalso succeeds, where it previously failed with ~40parse and resolution errors.
Notes for reviewers
within the same frame.
#[cfg(test)]modules undersrc/still fail to compile frompre-existing API drift, and
tests/err_stability.rsneeds nightly (variant_count).export ordinal too largelink error on thecdylibwhen
testutilsis enabled; run locally withcrate-type = ["lib"]. Linux CI isunaffected.