Skip to content

feat(wallet): gate high-value transfers behind the 2-of-3 quorum on submission - #1086

Merged
ibochielizabeth-spec merged 4 commits into
EF-CHAIN:mainfrom
Aboyeji-Isaac:fix/959-multisig-integration
Nov 27, 2026
Merged

ibochielizabeth-spec merged 4 commits into
EF-CHAIN:mainfrom
Aboyeji-Isaac:fix/959-multisig-integration

Conversation

@Aboyeji-Isaac

Copy link
Copy Markdown
Contributor

Refs #959.

No closing keyword: two requirements below need a maintainer decision before
the gate can safely be enabled. Whether this closes #959 is your call once
they are settled — see "Unresolved requirements".

Rebased onto the repaired main (c9439b9, #1085). Merged cleanly, no
conflicts, and the suite is green on top of it.

What changed

Wires the existing 2-of-3 quorum policy into the submission path.
multisig.js could already evaluate a quorum, but nothing called it:
submitPayment built, signed and submitted a high-value envelope with a
single key.

The gate now runs inside wallet/stellar.adapter.js#submitPayment, after the
envelope is signed and before server.submitTransaction, so a transfer that
cannot show two valid signatures throws before any transport exists. It
re-runs on the tx_bad_seq rebuild and precedes onEnvelope, so no txHash
is persisted for an envelope that never reached the network.

Second signatures come from the deployment's configured quorum co-signers
(MULTISIG_COSIGNERS), consulted over the hash-based protocol the HSM signer
already speaks. A co-signer is only ever asked, never trusted: its reply
must be a 64-byte Ed25519 signature that verifies against this exact
envelope, its key must already be an on-chain signer on the account, and
authorizeTransaction then re-verifies the whole envelope against the
ledger's signer set and thresholds. Fee-bump envelopes are unwrapped, so a
fee-payer's signature cannot stand in for inner authorization.

Below the threshold nothing new runs — no extra Horizon read, no co-signer
resolution — so a broken co-signer configuration cannot affect an ordinary
payment.

Security: a real hole closed on the way

verifyExportChallenge-style bare-id handling is not the only gap this kind
of wiring exposes. Here the specific one was a leaked velocity
reservation
: the refusal is raised after submissionStarted is set, but
handleStellarPaymentFailure only enqueues a reversal for genuine Horizon
rejections, so the reservation was left to expire for a transfer that never
left the process — silently shrinking the user's remaining limit. Refusals
raised before submission now carry preSubmission, and the orchestrator
releases the reservation itself. Post-submission failures still defer to the
reversal job, because those may correspond to a transaction that really is on
the network. Both directions are tested.

Scope of coverage — please read

This gate covers user-facing outbound transfers: the payment
orchestrator, refunds, recurring payments and the SEP-6/SEP-31 rails all
funnel through submitPayment. It does not cover every path that can
reach Horizon, and this PR does not claim to:

  • establishTrustline and wallet/trustlines.js submit changeTrust only,
    which moves no value and is exempt on purpose (ZERO_VALUE_OPERATIONS).
  • wallet/feeBump.js wraps an already-authorized inner transaction; its one
    caller is trustlines.js.
  • wallet/channelAccountPool.js is operational plumbing and is dormant.
  • wallet/hotWalletPool.js (feat(wallet): build ephemeral hot wallet pool with automated multi-sig replenishment (closes #965) #1081) is not exempt and is the one real
    gap.
    Its _executeMultisigTransfer builds a native payment of arbitrary
    size from cold storage, signs it with raw in-process keypairs up to its own
    coldStorageThreshold, and submits directly, applying a quorum notion
    unrelated to this policy. Nothing in src/ requires it today, so it is a
    latent bypass rather than a live one.

multisig.sendpath.test.js asserts exactly that shape — one allowlisted
feeBump caller, the other two dormant — so widening the ungated surface
fails a test instead of passing silently. Bringing the treasury path under
one policy, or deciding it is deliberately governed separately, is a
maintainer decision and is not made here.

Unresolved requirements (blocking enablement, not review)

Both are disclosed rather than decided, because either answer changes custody
or compliance policy.

  1. Reference currency is unresolved. classifyTransaction compares each
    asset's total against one bare number in that asset's own units, with
    no FX normalization. MULTISIG_HIGH_VALUE_THRESHOLD defaults to
    MAX_SEND_AMOUNT, documented at .env.example:42 as XLM. The issue's
    acceptance criteria say "exceeding compliance thresholds (e.g. >
    $1,000
    )" — dollars. So 1000 USDC and 1000 XLM gate identically, roughly
    3x apart in real value. The orchestrator already carries a
    policySnapshot with referenceCurrency and convertedAmount, so the
    data exists, but routing it into a gate that deliberately reads only the
    envelope is an architectural change. Decision needed: per-asset
    thresholds, or move classification up to where the FX snapshot lives.

  2. Independent approval is not established. configuredCoSigners
    forwards any hash to MULTISIG_COSIGNER_ENDPOINT and attaches whatever
    verifies. The second signature proves a second key and a second credential
    were available — it does not prove a second party reviewed the
    transfer. Against a stolen custody key that is genuine defense-in-depth;
    against a host holding both credentials it is not. Any compliance-review
    semantics live entirely inside the external co-signing service, outside
    this repo. Decision needed: is that service required to enforce its
    own policy (limits, velocity, hold-and-review), and should that be a
    documented deployment precondition?

Also not done, deliberately: the issue's required work includes configuring
account thresholds and adding the compliance and operator signers. This code
never mutates on-chain signers or thresholds — buildThresholdPlan only
produces the plan. That is an operator action.

⚠️ Deployment precondition (blocking, operator action)

With MULTISIG_COSIGNERS unset, every transfer above the threshold is
refused with cosigner_unavailable (409). This is intentional
fail-closed behaviour — never a silent downgrade to single-key submission —
but it means deploying this without configuration does not preserve all
existing payment behaviour
: with the default threshold of 1000 XLM,
transfers above 1000 XLM stop working the moment it is deployed.

Rollout order is load-bearing:

  1. Add the quorum keys as on-chain signers and raise high_threshold to 2.
  2. Set MULTISIG_COSIGNERS and MULTISIG_COSIGNER_ENDPOINT.
  3. Then deploy.

Deploying before step 1 converts a single-key vulnerability into a
high-value outage.

Tests added

  • apps/api/test/multisig.sendpath.test.js (22) — the gate is reachable on
    every submission path, runs before submission, survives the retry rebuild,
    and is the only gated Horizon payment path, plus the tripwire above.
  • apps/api/test/multisig.orchestrator.test.js (9) — the refusal path: the
    caller sees the gate's own error and status, the row is marked failed
    exactly once and never advanced to pending, no txHash is written for an
    envelope that never existed, the failed ledger entry is posted only after
    the row is failed, the reservation is released for a pre-submission refusal
    and not for a post-submission failure, and a failing reversal job cannot
    mask the original refusal.

Results on top of c9439b9

tests pass fail skipped
main (c9439b9) 1810 1802 0 8
This branch 1841 1833 0 8

Targeted: 75/75 (44 existing multisig + Stellar adapter, 22 new
submission-path, 9 new orchestrator). Backend lint: clean. prisma validate:
valid. git diff --check: clean. Node 20.20.2, all services mocked,
synthetic accounts only — no live signers, credentials or transactions.

Thank you for #1085 — it took this branch from "32 pre-existing failures I
have to explain" to a clean run.

How to test

cd apps/api && node --test test/multisig.test.js test/stellarAdapter.test.js \
  test/multisig.sendpath.test.js test/multisig.orchestrator.test.js

Scope exception requested: three implementation files

The checklist asks for no more than two. This changes three:
multisig.js, stellar.adapter.js, payment.orchestrator.js
(.env.example is config documentation; the rest are tests).

Requesting an exception to keep them together. The 6-line orchestrator
edit is the other half of the gate, not a separate change: the gate's refusal
is what creates the leaked velocity reservation, and the reservation fix is
unreachable and untestable without the gate. Splitting them would ship a
release window in which a refused high-value transfer silently consumes the
user's velocity allowance, and would put the gate and the test proving it
unwinds correctly in different PRs. Happy to split if you would rather — say
the word and I will reorder them so the reservation fix lands first.

Checklist

  • npm test passes and new backend logic has tests in apps/api/test/
  • This pull request changes no more than two implementation files — three;
    scope exception requested above
  • Documentation is updated (.env.example; module comments state the
    submission boundary and every exception to it)
  • No secrets, private keys, or .env files committed
  • New environment variables are documented in .env.example
  • Security/data-model implications considered

…ubmission

The 2-of-3 quorum policy existed but nothing called it: `submitPayment`
built, signed and submitted a high-value envelope with a single key. This
wires the policy into the one function every outbound value-moving path
goes through, between signing and `server.submitTransaction`, so a transfer
that cannot show two valid signatures throws before any transport exists.

Second signatures come from the deployment's configured quorum co-signers
(`MULTISIG_COSIGNERS`), consulted over the protocol the HSM signer already
speaks. A co-signer is only ever asked, never trusted: its reply must be a
64-byte Ed25519 signature that verifies against this exact envelope, its key
must already be an on-chain signer on the account, and the whole envelope is
then re-verified against the ledger's own signer set and thresholds. With
nothing configured, high-value transfers fail closed with
`cosigner_unavailable` rather than silently downgrading to single-key
submission.

Below the threshold nothing new runs - no extra Horizon read, no co-signer
resolution - so a broken co-signer configuration cannot break an ordinary
payment. `changeTrust` stays single-key, since it moves no value.

Also fixes a reservation leak the gate exposed: the refusal is raised after
`submissionStarted` is set, but `handleStellarPaymentFailure` only enqueues a
reversal for genuine Horizon rejections, so the velocity reservation was
left to expire. Refusals raised before any submission now carry
`preSubmission`, and the orchestrator releases the reservation itself.
The gate's own comments claimed `submitPayment` is the one function every
outbound value-moving path goes through. That was true at the base commit but
is not true on current upstream main, and a comment that overstates a security
boundary is worse than no comment: the next reader trusts it.

`wallet/hotWalletPool.js` (EF-CHAIN#1081, now merged) builds a native payment of
arbitrary size from cold storage, signs it with raw in-process keypairs up to
its own `coldStorageThreshold`, and submits directly to Horizon. It applies an
ad-hoc quorum unrelated to this policy and this gate cannot see or refuse it.

The comments now scope the claim to user-facing outbound transfers, enumerate
the modules that submit directly, and separate the genuinely exempt ones
(changeTrust, fee bumps, channel accounts) from that real gap. Whether the
treasury path comes under one policy is a maintainer decision and is flagged
as such rather than assumed.

Comments only; no behaviour change.


The guard asserted that `feeBump.js` and `channelAccountPool.js` are dormant,
which was true at this branch's base but is not on current main: EF-CHAIN#1066 wires
`feeBump.buildFeeBumpEnvelope` into `trustlines.js`. Merging EF-CHAIN#959 onto main
therefore turned this test red for a reason that is not a bypass — the wrapped
operation is a zero-value ChangeTrust.

Reworked so it asserts the invariant instead of the snapshot:

- `feeBump.js` may have callers, but only allowlisted ones. Subset semantics,
  so it holds both on a base that predates `trustlines.js` and on main; an
  unsanctioned caller still fails, because feeBump is generic and could be
  handed a valued inner transaction.
- `channelAccountPool.js` and `hotWalletPool.js` must stay dormant. Both
  submit valued transactions straight to Horizon. `hotWalletPool` (EF-CHAIN#1081)
  signs native payments of arbitrary size with raw in-process keypairs under
  its own quorum notion; nothing requires it today, so it is a latent rather
  than live gap, and this is what keeps it that way.

Verified red-to-green against both trees: this branch's base and a trial merge
onto current upstream main. The module comment is corrected to match.

Tests only, plus comments; no behaviour change.
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.

Implement Multi-Signature Quorum Policy (2-of-3) for High-Value Transactions

2 participants