Skip to content

fix: initialize admin auth + deployer/salt binding (options 1 and 2, #8) - #23

Open
ayush8620 wants to merge 3 commits into
YieldAnchor:mainfrom
ayush8620:fix/8-initialize-admin-auth-guarantee
Open

ayush8620 wants to merge 3 commits into
YieldAnchor:mainfrom
ayush8620:fix/8-initialize-admin-auth-guarantee

Conversation

@ayush8620

@ayush8620 ayush8620 commented Sep 21, 2026 •

Copy link
Copy Markdown

Closes #8

Summary

Implements both guarantees from issue #8 on initialize:

  1. Option 1 — admin auth — after AlreadyInit and deployer binding, require admin.require_auth() (when admin ≠ deployer) before metadata validation.
  2. Option 2 — deployer binding — take deployer + creation salt, re-derive the contract address, reject mismatches with BadDeployer, and require deployer authorization.

Together these close the self-install capture window: a non-deployer cannot initialize even when self-signing as admin. No Soroban SDK major bump and no __constructor.

Why this differs from #24

This PR (#23) #24
Option 1 + option 2 together yes (this branch already had option 1) option 2 shaped; admin auth when distinct
Check / auth order AlreadyInit → address bind → auth → metadata AlreadyInit → address bind → metadata → auth
Option-1 regression tests (foreign-admin mock_auths, auth-before-BadName, missing-auth Err(Err(_))) kept and adapted to new ABI not present
Docs states both guarantees; notes already-init Testnet vault unaffected deployer-binding focused

Changes

  • contracts/yield_vault/src/lib.rs — new ABI initialize(deployer, salt, admin, …), BadDeployer, both auths, regression tests
  • contracts/yield_vault/README.md / docs/deployment/testnet.md — document both guarantees
  • packages/{constants,shared-types,validation,contract-clients} — error code, schemas, salt helpers, client/deploy threading
  • scripts/deploy/deploy-yield-vault.{ts,sh} — pass salt through create + initialize

Tests

cargo test -p yield_vault          # 19/19
cargo clippy -p yield_vault --all-targets -- -D warnings
cargo fmt --all -- --check
pnpm build:packages + validation/contract-clients/constants/shared-types tests + typecheck

BountyHub

PR targets the open BountyHub bounty on #8 from ayush8620.

Move admin.require_auth() ahead of name/symbol/decimals checks while
keeping AlreadyInit first, add mock_auths front-runner coverage, and
update README/testnet docs so they no longer claim initialize is
unauthenticated.

Closes YieldAnchor#8
Copilot AI lite review requested due to automatic review settings September 21, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

A newly added regression test uses #[should_panic] and should assert the specific auth-failure result to avoid false positives.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

This PR tightens the YieldVault::initialize authorization semantics by ensuring the selected admin’s signature is required before metadata validation, and adds regression tests + documentation to pin the intended “option 1” guarantee from issue #8.

Changes:

  • Move admin.require_auth() to run immediately after the AlreadyInit check and before metadata validation.
  • Add initialization regression tests covering foreign-admin front-run attempts and auth-before-metadata behavior.
  • Update deployment/testnet documentation and the contract README to reflect the guarantee and residual self-install window.
File Description
docs/​deployment/​testnet.md Updates Testnet deployment caveats to reflect the admin self-authorization guarantee and residual self-install window.
contracts/​yield_vault/​src/​lib.rs Reorders require_auth ahead of metadata validation and adds regression tests for front-running/auth ordering.
contracts/​yield_vault/​README.md Documents the initialization authorization guarantee and its limits.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1082 to +1101
#[test]
#[should_panic]
fn initialize_panics_without_admin_auth() {
let env = Env::default();
let admin = Address::generate(&env);
let asset = env
.register_stellar_asset_contract_v2(admin.clone())
.address();
let vault = env.register_contract(None, YieldVault);
let client = YieldVaultClient::new(&env, &vault);

// No mock_all_auths: require_auth must abort.
client.initialize(
&admin,
&asset,
&String::from_str(&env, "YieldAnchor Vault"),
&String::from_str(&env, "yVAULT"),
&6,
);
}
@ayush8620

Copy link
Copy Markdown
Author

Reviewed the diff: AlreadyInit → admin.require_auth() → metadata, plus the foreign-admin front-run and missing-auth host-error tests. Ran cargo test -p yield_vault (16/16) and clippy/fmt clean locally. Happy to adjust if you want a different option-1 shape.

…auth

Close the self-install window by requiring deployer+salt to re-derive this
contract address (BadDeployer otherwise) and deployer authorization, while
keeping admin.require_auth from option 1. Thread salt through deploy helpers,
clients, and both deploy scripts; update docs and tests accordingly.
@ayush8620 ayush8620 changed the title fix: pin initialize admin-auth before metadata + front-run tests (#8) fix: initialize admin auth + deployer/salt binding (options 1 and 2, #8) Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: initialize is unauthenticated, so a front-runner can capture admin on a fresh vault

2 participants