Repository navigation
fix(wallet): harden the secondary Solana account and program signing - #8740
Conversation
Wallet setup now refuses an index-0 account whose derivation path matches a known secondary account, since that primary would resolve to the same key and let the secondary's program policy sign for it. Stored wallets written before this check are quarantined at load time so they can never sign as the secondary. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
The pre-state (getTokenAccountsByOwner) and post-state (simulateTransaction) were read separately, so a deposit between them could hide a token debit. Every RPC answer now carries its context slot; a measurement whose reads disagree is repeated and then refused. Only token accounts named in the transaction's account keys are read or requested, which also avoids the RPC rejecting an address list longer than the account-key list. Co-authored-by: Medulla <medulla@tinyhumans.ai>
…cution The quote map is process-wide, so a quote prepared in one workspace or wallet could be executed, and spend its allowance, in another. A quote now records its workspace, a hash of the encrypted phrase, its account index and the Solana endpoint, and is taken only under the same binding; a mismatched take leaves it in place. Execution also reads the clock at the reservation point and refuses a quote that expired while it was being re-simulated, before anything is signed. The snapshot comment now states what the caps guarantee. Co-authored-by: Medulla <medulla@tinyhumans.ai>
The quote map is a new process static. It is partitioned by QuoteBinding and the record names the test that pins that partition. Co-authored-by: Medulla <medulla@tinyhumans.ai>
Applied rustfmt formatting across the wallet program ops and simulate modules and their tests, wrapping long call sites, assertions, and log macros. No behaviour changed. Auto-committed-on: cuttlefish Co-authored-by: Medulla <medulla@tinyhumans.ai>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
🔵 Needs a closer look
The missing TinyWallet implementation leaves derivation-path alias safety unverified, and the expiry-sensitive reservation-to-signing flow still requires human integration validation.
No open issues 🎉
What changed in this PR
This follow-up to #8735 hardens OpenHuman’s secondary Solana account and prepared program-signing flow.
Changes:
- Rejects primary accounts that use a known secondary derivation path, including stored wallet state.
- Binds quotes to their workspace, wallet, account and endpoint, and rechecks expiry at ledger reservation.
- Retries or refuses simulations whose reads span different slots, limits measured accounts to transaction keys, and adds regression tests.
| File | Description |
|---|---|
scripts/ci/process-statics.json |
Records ownership and context partitioning of the process-wide quote map. |
crates/openhuman-core/src/web3/wallet/program/simulate.rs |
Checks snapshot slots and filters token accounts to transaction keys. |
crates/openhuman-core/src/web3/wallet/program/simulate_tests.rs |
Tests split-slot refusal and token-account filtering. |
crates/openhuman-core/src/web3/wallet/program/ops.rs |
Adds quote binding and reservation-time expiry checks; clarifies simulation limits. |
crates/openhuman-core/src/web3/wallet/program/ops_tests.rs |
Tests quote isolation and the expiry predicate. |
crates/openhuman-core/src/web3/wallet/policy.rs |
Adds the QuoteExpired refusal kind. |
crates/openhuman-core/src/web3/wallet/ops.rs |
Rejects primary accounts at known secondary derivation paths. |
crates/openhuman-core/src/web3/wallet/ops_tests.rs |
Tests alias rejection during setup and quarantine during load. |
Review effort: Balanced
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cdd4c450b9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for _ in 0..SNAPSHOT_ATTEMPTS { | ||
| match measure(url, transaction, owner, account_keys).await? { | ||
| Attempt::Measured(report) => return Ok(report), | ||
| Attempt::SplitAcrossSlots(slots) => seen = slots, |
There was a problem hiding this comment.
Move the new snapshot-measurement logic into TinyWallet
The new snapshot retries and transaction-account filtering implement Solana wallet-engine/provider behavior in the OpenHuman host, with direct behavior tests in simulate_tests.rs. AGENTS.md assigns the wallet engine and per-chain transaction flows to vendor/tinywallet, leaving OpenHuman configuration, consent, controllers and seam implementations. Land this measurement fix and its behavior tests upstream, then consume it through the released module contract and gitlink update; adding the algorithm here extends the host-side engine workaround rather than respecting that ownership boundary.
AGENTS.md reference: AGENTS.md:L616-L616
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not resolved here. The ownership point is correct: AGENTS.md assigns per-chain build/sign/broadcast flows to vendor/tinywallet. Moving the snapshot measurement needs a tinywallet bus extension, a test suite upstream, a release and a gitlink bump. That is follow-up work tracked separately, so this thread stays open until that lands. The safety fixes in this PR are unchanged.
| slots.push(context_slot(&answer, "simulateTransaction")?); | ||
| if slots.iter().any(|slot| *slot != slots[0]) { |
There was a problem hiding this comment.
Avoid requiring three serial RPC reads to fit within one slot
For an otherwise healthy remote endpoint with roughly 250 ms round trips and confirmed banks advancing every roughly 400 ms, measure's two awaited getTokenAccountsByOwner calls followed by simulateTransaction necessarily span slots. This equality check therefore rejects every attempt even when all relevant balances remain unchanged, and restarting the same serial sequence cannot recover. Both program preparation and execution become unavailable for such endpoints. Obtain comparable pre/post state through an atomic or coordinated measurement strategy rather than requiring three serial RPC calls to complete against one latest-confirmed bank.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed that three serial reads can span slots on a busy endpoint, and the equality check then refuses every attempt. It fails closed, so it is not a debit-masking hole, but it can make prepare and execute unavailable there. A correct fix needs a coordinated read strategy, which belongs with the upstream measurement work in the first thread. Leaving this open for that change.
Refs #8735
Follow-up to #8735, which merged at
dacda387(merge399bdc9c). This PR hardens the secondary Solana account (index 1) and the program-signing path against four findings from the CodeRabbit and Copilot review of that PR.Changes
validate_setuprefused a secondary account at a non-canonical path, but accepted an index-0 account at a secondary path (m/44'/501'/1'/0'). Both would resolve to the same key, so the secondary's program policy could sign for the primary. Setup now refuses a primary whose path is a known secondary path. A wallet state that already holds such an alias is quarantined at load (load runs the same validation), so no secondary key is ever resolved from it.getTokenAccountsByOwner) and the post-state (simulateTransaction) came from separate RPC reads. Every answer now carries its context slot. A measurement whose reads disagree on slot is repeated and then refused. The request also names only token accounts that are in the transaction's account keys, since the transaction cannot write any other account.RefusalKind::QuoteExpired), and uses that instant for the policy window and the pending ledger record. The snapshot comment now states what the caps guarantee.Also:
QUOTESgets ascripts/ci/process-statics.jsonownership record (category B), and the commits are formatted with rustfmt.Regression tests
Each fix has a test that fails when its fix is removed. I checked this by mutating each guard in turn and running the named test:
ops_tests::validate_setup_rejects_a_primary_at_a_secondary_path,ops_tests::a_stored_primary_at_the_secondary_path_is_quarantined_before_signingprogram::ops_tests::a_quote_is_taken_only_in_the_context_it_was_prepared_inprogram::simulate_tests::a_measurement_whose_reads_span_slots_is_refused,program::simulate_tests::only_token_accounts_the_transaction_names_are_read_or_requestedprogram::ops_tests::a_quote_is_refused_from_its_expiry_instant_onwardGap: the expiry test covers the predicate. Wiring the fresh clock into the reservation closure is not unit-tested here, because it needs the ledger, simulation and signing stack.
Validation
cargo test -p openhuman --features web3 --lib -- web3::wallet: 99 passed, 1 failed. The failure isreveal_recovery_phrase_returns_phrase_for_existing_wallet, which needs the TinySecurity module ("security module unavailable: secret approval unavailable") and does not run in this sandbox. The same failure is documented in feat(wallet): secondary Solana account (index 1) with per-account program-signing policy #8735.rustfmt --checkon the changed files: clean after the style commit.Not in this PR
tinywallet::key::derivedirectly. AGENTS.md assigns both to the vendoredtinywalletrepository. They need an upstream PR there, a release, and a gitlink bump, so they are left open on feat(wallet): secondary Solana account (index 1) with per-account program-signing policy #8735 with that reason.Known CI state of the source PR
The #8735 macOS native-fixture failure reproduces on unrelated branches (
tinysecurity-0-21-1,chore/343-*), so it predates this change. The Linux egress and Windows native jobs hit the job time limit during a cold compile after theCargo.lockchange, not on a test assertion.Co-authored-by: Medulla medulla@tinyhumans.ai
Summary by CodeRabbit