Repository navigation
fix(transaction_components): enforce exactly m multisig signatures and strict parsing - #8331
Conversation
…ueness, and exact spend signature count Enforce script bounds, duplicate public key rejection on new deposits, and exact signature validation across multisig and offline-signing transaction flows: - Validate n == 0, n > MAX_MULTISIG_LIMIT (32), party_number == 0, and duplicate public keys on deposit creation (validate_multisig_parameters), while preserving execution-bound checks (validate_multisig_bounds) when reading existing outputs in get_multi_sig_script_components. - Enforce signatures.len() == threshold in spend_multisig_utxo. - Validate duplicate public keys and ephemeral_public_nonces.len() == public_keys.len() in TransactionBuilder::with_multisig. - Reject 0-output payment and one-sided recipient requests in prepare_deposit_multisig_transaction and prepare_one_sided_transaction_for_signing.
SWvheerden
left a comment
There was a problem hiding this comment.
Thanks for this. The direction is right: the offline deposit path never checked 1 <= m <= n, a payload with more than 255 keys could hit the expect("Is checked") panic in build_multisig_output, and the builder silently fell back to u8::MAX. The spend-side parser only rejects scripts that consensus would refuse to run anyway, so existing multisig UTXOs stay spendable, and nothing in tari_script or consensus changes. A few things need to change before this can merge.
Required changes
1. CI: formatting and clippy fail
Merged onto current development:
-
cargo +nightly fmt --all -- --checkreports diffs in files this PR touches (developmentitself is clean):multisig/session.rs:314, 348, 383offline_signing/mod.rs:2829, 2888offline_signing/one_sided_signer.rs:43transaction_builder/builder.rs:1116
Run
cargo +nightly fmt --all. -
cargo lints clippy --all-targets --all-features -p tari_transaction_componentsfails with 5 ×clippy::indexing_slicing("indexing may panic") in the new tests inmultisig/script.rs(lines 154, 196 ×2, 202 ×2:keys[0]). Use.first()or iterate instead. The crate denies this lint in test code too.
The 55 multisig / offline_signing lib tests pass.
2. The exact signature count is only enforced on one of the two withdraw paths
MultisigSession::spend_multisig_utxo (multisig/session.rs:140) now requires signatures.len() == threshold. The wallet's offline withdraw handler has its own copy of the same check, still written as <:
base_layer/wallet/src/transaction_service/service.rs:631 (PrepareWithdrawMultisigTransaction)
if signatures.len() < threshold as usize {Excess signatures are pushed onto the input stack, the payload is signed offline, and consensus then rejects the spend because more than one item is left on the stack. Meanwhile the multisig UTXO is tied to the pending transaction. Please apply the same != rule there, ideally through one small shared helper in multisig::script (for example validate_multisig_spend_signature_count(script, n_sigs)), so the two paths can't drift apart again.
3. Validate before the wallet locks inputs
The new checks run after the wallet has already selected and locked inputs under temp_tx_id, and that error path never releases them:
CreateMultisigUtxo(wallet/.../transaction_service/service.rs:1521-1545) locks inputs inprepare_transaction_to_sendand only then reachesvalidate_multisig_parametersinsidecreate_deposit_multisig_transaction. This applies to duplicate keys, more than 32 keys, and threshold errors.PrepareDepositMultisigTransaction(service.rs:541-587):multisig_pending_outputchecks the counts before locking, which is good. The duplicate-key check only happens inprepare_deposit_multisig_transaction, afterprepare_offline_transaction_to_sendhas locked the inputs.
Before this PR these requests produced a (bad) output. Now they return an error and leave the inputs locked until the wallet restarts. Please call validate_multisig_parameters(request.party_number, &request.public_keys) at the top of both handlers, before any input is selected. The deposit handler already does the same for the missing view key ("Checked before any input is locked"). Keep the inner checks as the second line of defence.
4. Duplicate-key rejection
Rejecting duplicate keys for new deposits is a policy change. A key listed twice yields identical derived script keys, so one holder can fill two threshold slots. We want to settle the policy on our side before merging this part. Please either split the duplicate-key rule into its own commit so it can be dropped or kept on its own, or be ready to remove it. The bounds and threshold checks are not affected by this.
Also, the PR description says get_multi_sig_script_components rejects duplicate keys, but the code (correctly) uses only validate_multisig_bounds there, and the test asserts duplicates are accepted. Please update the description to match. Accepting duplicates on the spend side is what keeps any existing outputs of that shape spendable.
Suggestions
- Show an invalid threshold before signing. The offline payload summary (
offline_signing/payload_summary.rs,PayloadDetails::multisig) is built beforesign_multisig_transactionruns, so a tampered payload can still show an operator something like "5 of 3" before signing fails. Rejecting an invalidparty_number/ key count when building the summary would close that gap. - Avoid triple validation in the cold signer.
sign_multisig_transactionvalidates, thenmultisig_pending_outputvalidates the bounds, thenbuild_multisig_outputvalidates again. One check at the entry point plus the one inbuild_multisig_output(which is also reached directly) is enough. - Tighten the tests.
- The new deposit tests only assert
is_err(). Please assert on the error message, as the spend test already does, and add a positive control: a valid 2-of-2 with the samemake_builder()returnsOk. - The offline cold-signer test comment mentions duplicate and >32 keys, but only
party_number = 0is exercised.
- The new deposit tests only assert
- Constant.
MAX_MULTISIG_LIMITduplicates the private constant ininfrastructure/tari_script/src/script.rs:60. A comment pointing at it is enough; exporting it fromtari_scriptwould be better.
Compatibility
- Consensus: no change;
tari_scriptis untouched. - Existing UTXOs: the spend side still accepts any script consensus would accept (including duplicate keys), so existing multisig outputs stay spendable.
is_multisig_utxonow returnsfalsefor malformed scripts, but its only caller is the console wallet'sExportUtxosdisplay. - Wire format: no serde/borsh changes.
Merge notes
- This merges cleanly onto current
development. - It conflicts with #8399 in the test module at the end of
offline_signing/mod.rs, where both PRs append tests. - #8399 also changes
sign_payloadto take a signing key id, so the new test'soffline_signer::sign_payload(&alice_key_manager, &canonical)will need updating, whichever PR lands second.
…re locking inputs Review follow-up for tari-project#8331: - add `validate_multisig_spend_signature_count` and use it in both `MultisigSession::spend_multisig_utxo` and the wallet's `PrepareWithdrawMultisigTransaction`, which still accepted excess signatures - call `validate_multisig_parameters` at the top of `CreateMultisigUtxo` and `PrepareDepositMultisigTransaction`, before any input is selected and locked - drop the duplicate-key rule from this commit; it follows separately so it can be kept or dropped on its own - assert error messages, add valid 2-of-2 positive controls, and exercise the cold signer with re-signed payloads (party_number 0, m > n, n > 32) - replace `keys[0]` indexing in tests, point MAX_MULTISIG_LIMIT at tari_script, and apply nightly rustfmt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Policy change, kept in its own commit so it can be dropped independently. A key listed twice yields identical derived script keys, letting one holder fill two threshold slots. Only new deposits are checked (`validate_multisig_parameters`); the spend side still accepts any script consensus accepts, so existing outputs with repeated keys stay spendable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the detailed review. Addressed in two new commits (no history rewrite):
7709a46: the duplicate-key rule, alone in its own commit. It applies to new deposits only, so it can be dropped by reverting that one commit. The PR description is updated: the spend side accepts duplicate keys. Not done here: validating in
|
…ffline-signing-bounds-and-uniqueness # Conflicts: # base_layer/transaction_components/src/offline_signing/mod.rs
SWvheerden
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. 816e955 addresses most of the last round: the spend rule is now shared and exact, the wallet deposit handlers validate before any input is selected, and the bounds and tests look right. "Exactly m" is correct for the [CheckMultiSigVerify, PushPubKey] shape: check_multisig pops m, and any extra signature fails the final-stack check. The new None cases in get_multi_sig_script_components match ValueExceedsBounds in tari_script exactly. So no consensus-spendable output becomes unspendable through the wallet, and nothing changes on the node side. Three things remain.
1. CI: clippy fails (blocking)
cargo ci-clippy (lints clippy --all-targets --all-features) fails on the new test:
error: this function has too many lines (133/100)
--> base_layer/transaction_components/src/multisig/session.rs:301:5
clippy::too_many_lines is denied in lints.toml. Split the test into a deposit test and a spend test, or add #[allow(clippy::too_many_lines)] the way the long tests in offline_signing/mod.rs do. cargo +nightly fmt --check is clean now.
2. Please drop 7709a46 (duplicate-key rejection) from this PR
Thanks for isolating it. We have not decided yet whether new deposits should reject repeated keys. Please revert that commit here so the bounds and exact-count fixes can land on their own. If you want, open it as a separate PR. Concretely:
validate_multisig_parametersbecomes the bounds check only (or just callvalidate_multisig_boundsat the deposit sites).- Remove the duplicate-key test cases.
- Keep the spend-side test that shows repeated keys are still accepted.
3. Validate the threshold in the payload summary too
PayloadDetails::multisig (offline_signing/payload_summary.rs:334) copies info.party_number into multisig_required_signatures without a check. A payload with m = 0, m > n or n > 32 is still summarised and shown to the operator (for example "5 of 3") before sign_multisig_transaction refuses it. Please make the summary fail on an invalid threshold, using the same validate_multisig_bounds(info.party_number, info.public_keys.len()). Either make PayloadDetails::multisig (or the constructor that calls it at :724) return a Result, or check before building the summary. Add a test with a tampered payload.
Non-blocking, fine as a follow-up:
- The wallet's script
[CheckMultiSigVerify(m, n, keys, msg), PushPubKey]serialises to roughly 68 + 32·n bytes.max_script_byte_sizeis 512 on every network, so deposits with n >= 14 still pass the new checks and are then rejected by nodes withTariScriptExceedsMaxSize. This was already the case before this PR (it used to accept up to 255). - Keys are only checked for length, not decompressed. On the online
CreateMultisigUtxopath, a 32-byte value that is not a valid point therefore fails inderive_multisig_ephemeral_pubkey, which runs after inputs are locked.
…deposits" This reverts commit 7709a46.
…mary `PayloadSummary::from_multisig` now runs `validate_multisig_bounds` and returns a `Result`, so a tampered deposit payload (m = 0, m > n or n > 32) is refused before it is shown to the operator, instead of only when `sign_multisig_transaction` runs. The signer keeps its own check as a second line of defence. Also splits the long multisig session test into a deposit test and a spend test so it passes `clippy::too_many_lines`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. All three are addressed in two new commits, with no history rewrite:
I'll leave the n >= 14 script size limit and the point decompression on |
SWvheerden
left a comment
There was a problem hiding this comment.
Thanks. All three round-2 items are fixed:
- The long test is split into
create_deposit_multisig_enforces_script_boundsandspend_multisig_utxo_requires_exact_signature_count.cargo lints clippy --all-targets --all-featuresnow passes ontari_transaction_components,minotari_walletandminotari_console_wallet. - The duplicate-key rejection is reverted cleanly (ba063b4). Nothing of it is left in the code or the tests.
PayloadDetails::multisig/PayloadSummary::from_multisignow refusem = 0,m > nandn > 32before the summary is shown. The console wallet maps the error afterverify_offline_payload. That is the only caller outside tests.
Since your last push, nothing has changed beyond those three items. On a local merge with development, nightly fmt is clean and the 84 multisig / offline_signing lib tests pass.
1. Merge development: the PR now conflicts
#8425 (merged this morning) added signing_logs_name_the_payload_without_its_contents and other tests at the end of the mod test block in base_layer/transaction_components/src/offline_signing/mod.rs. Your offline_deposit_multisig_enforces_threshold_and_participant_bounds test lands in the same place, so GitHub reports the PR as conflicting. Keep both blocks. Please also check that your new .unwrap() calls on from_multisig still compile against the tests #8425 added. They did in my local merge.
Non-blocking:
base_layer/transaction_components/src/multisig/session.rs:420:let mut sessionno longer needsmutafter the split (anunused_mutwarning). Please drop it while you are there.validate_multisig_parametersis now just a call tovalidate_multisig_bounds. Keeping it as the deposit-side entry point is fine.- From earlier rounds, still open and fine to leave for a follow-up: there is no wallet-level test that a bad
CreateMultisigUtxo/PrepareDepositMultisigTransactionrequest leaves the inputs unlocked. Also,nfrom 14 to 32 passes the bound but makes a script over the 512-bytemax_script_byte_size. That was already the case before this PR.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. Both are done:
Checked on the merged branch:
I've left the wallet-level unlock test and the 512-byte script limit for |
…nd-uniqueness Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
fe61e09 merges On the merged branch, |
SWvheerden
left a comment
There was a problem hiding this comment.
Thanks for the merges and the mut fix. The branch conflicts again, this time with #8430 (merged today) in multisig/session.rs and automation/commands.rs. #8430 also covers most of the deposit side of this PR, so the rebase should shrink the PR rather than keep both versions.
What #8430 already does. It adds one shared check, validate_multisig_threshold / multisig_placeholder_script in offline_signing/one_sided_signer.rs. That check is used by:
- the online session deposit
- offline prepare,
sign_multisig_transactionandbuild_multisig_output PayloadDetails::multisig/PayloadSummary::from_multisig, which now returnResult<_, TransactionBuilderError>- the CLI and gRPC
- wallet
CreateMultisigUtxo/PrepareDepositMultisigTransaction, where it runs before any input is locked
It is also stricter than validate_multisig_bounds. It refuses any script larger than the smallest consensus max_script_byte_size, which is 13 keys today. This PR allows 14 to 32 keys on deposit. Consensus rejects those outputs, but only after the inputs are locked. Keeping both helpers would leave two different limits and two error texts.
Requested changes
- Rebase onto
development. Take #8430's side for the deposit-side checks:- Remove
validate_multisig_bounds,validate_multisig_parametersand the localMAX_MULTISIG_LIMITfrommultisig/script.rs.tari_script::MAX_MULTISIG_LIMITis now public. - Remove their call sites: session deposit,
offline_signer.rs, the three inone_sided_signer.rs,payload_summary.rs+commands.rs, and walletservice.rs(CreateMultisigUtxo,PrepareDepositMultisigTransaction). - In
transaction_builder/builder.rs, every caller already validates. Drop the two new checks, or make them callvalidate_multisig_threshold. - Drop the deposit-threshold tests that #8430's tests already cover: the session deposit-bounds test, the
offline_signing/mod.rsdeposit tests, andmultisig_summary_refuses_an_invalid_threshold. Their expected messages ("expected 1..=32, got 33","Invalid multisig threshold party_number=…") will not match after the rebase anyway.
- Remove
- Keep the spend-side work. It is correct and not on
development:validate_multisig_spend_signature_count(exactlym) inMultisigSession::spend_multisig_utxoand walletPrepareWithdrawMultisigTransaction. Ondevelopmentthe withdraw check still runs before the input is encumbered, so the order stays right.- The bounds in
get_multi_sig_script_components/is_multisig_utxo. Write them inline againsttari_script::MAX_MULTISIG_LIMIT:m == 0 || m > n || n > MAX_MULTISIG_LIMIT || usize::from(n) != keys.len(). Keep the consensus limit of 32 here, not the 13-key deposit cap, so outputs that already exist are still recognised.
- Update the PR title and description to the remaining scope: exact spend signature count and strict multisig script parsing.
Checked on the current head (fe61e09c97): nightly fmt is clean, clippy is clean on the touched crates, and the 85 multisig/offline_signing lib tests pass. Not blocking: a wallet-level test showing PrepareWithdrawMultisigTransaction refuses m + 1 signatures would be nice.
…nd-uniqueness Take tari-project#8430's validate_multisig_threshold for every deposit-side check and drop this branch's validate_multisig_bounds / validate_multisig_parameters, the local MAX_MULTISIG_LIMIT and their deposit tests. Keep the spend side: exactly-m signature count and strict CheckMultiSigVerify parsing against tari_script::MAX_MULTISIG_LIMIT. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. Done in a857022, a signed merge of
The diff against |
SWvheerden
left a comment
There was a problem hiding this comment.
Thanks, the rebase is what we asked for. The diff is now down to the spend side, it merges cleanly onto development, and the logic is correct:
- Both spend paths share
validate_multisig_spend_signature_count, which requires exactlymsignatures. That matchescheck_multisig, which takes exactlymsignatures off the stack. - The bounds in
get_multi_sig_script_componentsmatch the consensus check againsttari_script::MAX_MULTISIG_LIMIT. - Duplicate keys are still accepted on spend.
One CI blocker is left.
Requested change
cargo ci-clippy fails on the new test:
error: indexing may panic
--> base_layer/transaction_components/src/multisig/script.rs:178:24
178 | let repeated = keys[0].clone();
= note: requested on the command line with `-D clippy::indexing-slicing`
The workspace lints deny indexing_slicing in tests too. Use something like let repeated = keys.first().unwrap().clone();, or build the duplicate key directly, for example sample_keys(1).
Checked on a857022fad:
- Nightly fmt (
nightly-2026-06-01) is clean. cargo lints clippy --all-targets --all-features -p minotari_walletis clean.cargo test -p tari_transaction_components --lib -- multisig offline_signingpasses all 82 tests.
Not blocking: the comments at session.rs:140 and in the new session test say the failure is StackNotEmpty. tari_script's actual error is ScriptError::NonUnitLengthStack. Once the clippy fix is in, this is ready from our side.
…e-key test and name the real script error Use keys.first() so the test passes clippy::indexing_slicing, and say NonUnitLengthStack instead of StackNotEmpty in the spend comments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. Both are done in 974c0a2 (signed, no history rewrite):
Checked on 974c0a2:
|
Summary
A multisig spend accepted more signatures than the script's threshold
m.CheckMultiSigVerifyconsumes exactlymsignatures, so any extra is left on the stack and consensus rejects the spend withStackNotEmpty, after the wallet has already built and broadcast the transaction.Separately,
get_multi_sig_script_components/is_multisig_utxoaccepted anyCheckMultiSigVerifyopcode, including ones consensus can never execute.The deposit-side checks that this PR used to carry are now covered by #8430 (
validate_multisig_threshold), so they have been removed here.Changes
multisig/script.rs)validate_multisig_spend_signature_count, which requires exactlymsignatures.MultisigSession::spend_multisig_utxoand by the wallet'sPrepareWithdrawMultisigTransaction, where it still runs before the input is encumbered.multisig/script.rs)get_multi_sig_script_componentsreturnsNone, andis_multisig_utxoreturnsfalse, form == 0,m > n,n != keys.len()orn > tari_script::MAX_MULTISIG_LIMIT.Compatibility
tari_scriptis untouched.Tests
multisig/script.rs:m - 1andm + 1are refused);multisig/session.rs:spend_multisig_utxorefusesm + 1signatures.cargo test -p tari_transaction_components --lib -- multisig offline_signing: 82 passed.rustfmt --checkis clean. Clippy ontari_transaction_componentsandminotari_walletshows nothing in the changed files.Known follow-ups (not in this PR)
PrepareWithdrawMultisigTransactionrefusesm + 1signatures.

Confidence Score: 5/5
The PR appears safe to merge; no blocking issues were found.Summary
This PR rejects multisig spends unless callers supply exactly
msignatures.No actionable new issues were found. Tests were not run during this review.
Reviews (13) · Last reviewed commit: "Merge branch 'development' into fix/mult..." · Reviewed by Greptile