Skip to content

fix(transaction_components): enforce exactly m multisig signatures and strict parsing - #8331

Merged
SWvheerden merged 12 commits into
tari-project:developmentfrom
Burapa-J:fix/multisig-offline-signing-bounds-and-uniqueness
Nov 30, 2026
Merged

SWvheerden merged 12 commits into
tari-project:developmentfrom
Burapa-J:fix/multisig-offline-signing-bounds-and-uniqueness

Conversation

@Burapa-J

@Burapa-J Burapa-J commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A multisig spend accepted more signatures than the script's threshold m. CheckMultiSigVerify consumes exactly m signatures, so any extra is left on the stack and consensus rejects the spend with StackNotEmpty, after the wallet has already built and broadcast the transaction.

Separately, get_multi_sig_script_components / is_multisig_utxo accepted any CheckMultiSigVerify opcode, 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

  • Spend signature count (multisig/script.rs)
    • Adds validate_multisig_spend_signature_count, which requires exactly m signatures.
    • It is used by MultisigSession::spend_multisig_utxo and by the wallet's PrepareWithdrawMultisigTransaction, where it still runs before the input is encumbered.
  • Strict script parsing (multisig/script.rs)
    • get_multi_sig_script_components returns None, and is_multisig_utxo returns false, for m == 0, m > n, n != keys.len() or n > tari_script::MAX_MULTISIG_LIMIT.
    • This uses the consensus limit of 32, not the 13-key deposit cap, so outputs that already exist are still recognised. Repeated keys are still accepted.

Compatibility

  • Consensus: no change; tari_script is untouched.
  • Existing UTXOs: the spend side accepts every script consensus accepts.
  • Wire format: no serde/borsh changes.

Tests

  • multisig/script.rs:
    • exact signature count (m - 1 and m + 1 are refused);
    • unexecutable opcodes are rejected;
    • duplicate-key and 32-key scripts are accepted.
  • multisig/session.rs: spend_multisig_utxo refuses m + 1 signatures.
  • cargo test -p tari_transaction_components --lib -- multisig offline_signing: 82 passed.
  • Nightly rustfmt --check is clean. Clippy on tari_transaction_components and minotari_wallet shows nothing in the changed files.

Known follow-ups (not in this PR)

  • A wallet-level test that PrepareWithdrawMultisigTransaction refuses m + 1 signatures.

Confidence Score: 5/5 · The PR appears safe to merge; no blocking issues were found.RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no blocking issues were found.

Summary

This PR rejects multisig spends unless callers supply exactly m signatures.

  • Multisig withdrawals require exactly the script threshold in signatures.
  • Multisig detection now rejects scripts consensus cannot execute.

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

…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 SWvheerden left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 -- --check reports diffs in files this PR touches (development itself is clean):

    • multisig/session.rs:314, 348, 383
    • offline_signing/mod.rs:2829, 2888
    • offline_signing/one_sided_signer.rs:43
    • transaction_builder/builder.rs:1116

    Run cargo +nightly fmt --all.

  • cargo lints clippy --all-targets --all-features -p tari_transaction_components fails with 5 × clippy::indexing_slicing ("indexing may panic") in the new tests in multisig/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 in prepare_transaction_to_send and only then reaches validate_multisig_parameters inside create_deposit_multisig_transaction. This applies to duplicate keys, more than 32 keys, and threshold errors.
  • PrepareDepositMultisigTransaction (service.rs:541-587): multisig_pending_output checks the counts before locking, which is good. The duplicate-key check only happens in prepare_deposit_multisig_transaction, after prepare_offline_transaction_to_send has 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 before sign_multisig_transaction runs, so a tampered payload can still show an operator something like "5 of 3" before signing fails. Rejecting an invalid party_number / key count when building the summary would close that gap.
  • Avoid triple validation in the cold signer. sign_multisig_transaction validates, then multisig_pending_output validates the bounds, then build_multisig_output validates again. One check at the entry point plus the one in build_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 same make_builder() returns Ok.
    • The offline cold-signer test comment mentions duplicate and >32 keys, but only party_number = 0 is exercised.
  • Constant. MAX_MULTISIG_LIMIT duplicates the private constant in infrastructure/tari_script/src/script.rs:60. A comment pointing at it is enough; exporting it from tari_script would be better.

Compatibility

  • Consensus: no change; tari_script is untouched.
  • Existing UTXOs: the spend side still accepts any script consensus would accept (including duplicate keys), so existing multisig outputs stay spendable. is_multisig_utxo now returns false for malformed scripts, but its only caller is the console wallet's ExportUtxos display.
  • 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_payload to take a signing key id, so the new test's offline_signer::sign_payload(&alice_key_manager, &canonical) will need updating, whichever PR lands second.

Burapa-J and others added 2 commits November 19, 2026 21:36
…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>
@Burapa-J
Burapa-J requested a review from a team as a code owner November 19, 2026 14:38
@Burapa-J

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. Addressed in two new commits (no history rewrite):

816e955

  1. Formatting is now nightly rustfmt (nightly-2026-06-01). The keys[0] indexing in the tests is gone. clippy --all-targets --all-features -D clippy::indexing_slicing is clean on tari_transaction_components and minotari_wallet.
  2. Added multisig::script::validate_multisig_spend_signature_count(script, n_sigs). Both MultisigSession::spend_multisig_utxo and the wallet's PrepareWithdrawMultisigTransaction now use it, so both paths require exactly m signatures.
  3. validate_multisig_parameters(request.party_number, &request.public_keys) now runs at the top of CreateMultisigUtxo and PrepareDepositMultisigTransaction, before any input is selected. The inner checks stay as a second line of defence.
  4. Tests:
    • They assert the error messages.
    • They include a valid 2-of-2 positive control on the same builder.
    • The cold-signer test now re-signs tampered payloads with party_number = 0, m > n and n = 33, plus an untampered control that must sign.
  5. MAX_MULTISIG_LIMIT now has a comment pointing at the constant in tari_script, which is left untouched.

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 payload_summary and removing the middle bound check. multisig_pending_output needs the u8 key count anyway. Happy to do either if you want.

cargo test -p tari_transaction_components --lib multisig offline_signing: 56 passed.

…ffline-signing-bounds-and-uniqueness

# Conflicts:
#	base_layer/transaction_components/src/offline_signing/mod.rs

@SWvheerden SWvheerden left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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_parameters becomes the bounds check only (or just call validate_multisig_bounds at 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_size is 512 on every network, so deposits with n >= 14 still pass the new checks and are then rejected by nodes with TariScriptExceedsMaxSize. 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 CreateMultisigUtxo path, a 32-byte value that is not a valid point therefore fails in derive_multisig_ephemeral_pubkey, which runs after inputs are locked.

Burapa-J and others added 2 commits November 23, 2026 17:15
…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>
@Burapa-J

Copy link
Copy Markdown
Contributor Author

Thanks. All three are addressed in two new commits, with no history rewrite:

  1. clippy (ba063b4 / adeb1e1): I split the long test into create_deposit_multisig_enforces_script_bounds and spend_multisig_utxo_requires_exact_signature_count. Clippy with the lints.toml deny list (which includes too_many_lines) is clean on tari_transaction_components, minotari_wallet and minotari_console_wallet, and nightly rustfmt --check is clean on the changed files.
  2. Duplicate-key rejection (ba063b4): This reverts 7709a46. validate_multisig_parameters is now the bounds check only, and the duplicate-key cases are removed from the script, session and cold-signer tests. The spend-side test that shows repeated keys are still accepted is kept.
  3. Payload summary (adeb1e1): PayloadDetails::multisig runs validate_multisig_bounds(info.party_number, info.public_keys.len()), and PayloadSummary::from_multisig now returns a Result.
    • All callers are updated. The console wallet reports the error and does not sign.
    • A tampered payload (m = 0, 5 of 3, n = 33) is refused before it is shown to the operator. This is covered by multisig_summary_refuses_an_invalid_threshold. The re-signed tampered payloads in cold_signer_refuses_re_signed_payloads_with_invalid_multisig_parameters are now stopped at the summary.
    • The signer keeps its own check as the second line of defence.
    • I removed the new check locally to confirm the summary test then fails.

cargo test -p tari_transaction_components --lib -- multisig offline_signing payload_summary: 82 passed.

I'll leave the n >= 14 script size limit and the point decompression on CreateMultisigUtxo for a follow-up, as you suggested.

@Burapa-J Burapa-J changed the title fix(transaction_components): enforce multisig script bounds, key uniqueness, and exact spend signature count fix(transaction_components): enforce multisig script bounds and exact spend signature count Nov 23, 2026

@SWvheerden SWvheerden left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks. All three round-2 items are fixed:

  • The long test is split into create_deposit_multisig_enforces_script_bounds and spend_multisig_utxo_requires_exact_signature_count. cargo lints clippy --all-targets --all-features now passes on tari_transaction_components, minotari_wallet and minotari_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_multisig now refuse m = 0, m > n and n > 32 before the summary is shown. The console wallet maps the error after verify_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 session no longer needs mut after the split (an unused_mut warning). Please drop it while you are there.
  • validate_multisig_parameters is now just a call to validate_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 / PrepareDepositMultisigTransaction request leaves the inputs unlocked. Also, n from 14 to 32 passes the bound but makes a script over the 512-byte max_script_byte_size. That was already the case before this PR.

@Burapa-J

Copy link
Copy Markdown
Contributor Author

Thanks. Both are done:

Checked on the merged branch:

  • cargo test -p tari_transaction_components --lib -- multisig offline_signing: 84 passed.
  • rustfmt (nightly-2026-06-01) --check on the changed files: clean.
  • Clippy with the lints.toml flags on tari_transaction_components, minotari_wallet and minotari_console_wallet: no warnings in these files.

I've left the wallet-level unlock test and the 512-byte script limit for n from 14 to 32 for a follow-up, as you suggested.

…nd-uniqueness

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Burapa-J

Copy link
Copy Markdown
Contributor Author

fe61e09 merges development again to clear the new conflict with #8428 in multisig/script.rs. The conflict was only in mod test, and both sides are kept: our bounds and spend-count tests, then the co-signer test from #8428. The test module now imports use super::* like #8428 does. No code outside the tests changed.

On the merged branch, cargo test -p tari_transaction_components --lib -- multisig offline_signing passes 85 tests, nightly rustfmt --check is clean, and clippy shows nothing in the files this PR touches.

@SWvheerden SWvheerden left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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_transaction and build_multisig_output
  • PayloadDetails::multisig / PayloadSummary::from_multisig, which now return Result<_, 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

  1. Rebase onto development. Take #8430's side for the deposit-side checks:
    • Remove validate_multisig_bounds, validate_multisig_parameters and the local MAX_MULTISIG_LIMIT from multisig/script.rs. tari_script::MAX_MULTISIG_LIMIT is now public.
    • Remove their call sites: session deposit, offline_signer.rs, the three in one_sided_signer.rs, payload_summary.rs + commands.rs, and wallet service.rs (CreateMultisigUtxo, PrepareDepositMultisigTransaction).
    • In transaction_builder/builder.rs, every caller already validates. Drop the two new checks, or make them call validate_multisig_threshold.
    • Drop the deposit-threshold tests that #8430's tests already cover: the session deposit-bounds test, the offline_signing/mod.rs deposit tests, and multisig_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.
  2. Keep the spend-side work. It is correct and not on development:
    • validate_multisig_spend_signature_count (exactly m) in MultisigSession::spend_multisig_utxo and wallet PrepareWithdrawMultisigTransaction. On development the 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 against tari_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.
  3. 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>
@Burapa-J Burapa-J changed the title fix(transaction_components): enforce multisig script bounds and exact spend signature count fix(transaction_components): require exactly m multisig spend signatures and parse multisig scripts strictly Nov 25, 2026
@Burapa-J

Copy link
Copy Markdown
Contributor Author

Thanks. Done in a857022, a signed merge of development:

  1. Deposit side: this now uses fix(wallet): lock multisig inputs when spending them and size multisig deposits for the real script #8430's side everywhere. validate_multisig_bounds, validate_multisig_parameters and the local MAX_MULTISIG_LIMIT are gone, along with all their call sites and the deposit-threshold tests. That covers the session deposit, offline_signer.rs, one_sided_signer.rs, payload_summary.rs, commands.rs, wallet CreateMultisigUtxo / PrepareDepositMultisigTransaction, the two builder.rs checks and the offline_signing/mod.rs deposit tests. Those files are now identical to development.
  2. Spend side, kept:
    • validate_multisig_spend_signature_count (exactly m) in MultisigSession::spend_multisig_utxo and PrepareWithdrawMultisigTransaction.
    • get_multi_sig_script_components does its bounds check inline against tari_script::MAX_MULTISIG_LIMIT (32), and is_multisig_utxo delegates to it.
    • TariScript::new already refuses n != keys.len(), so that case is checked in the code but cannot be built in a test.
  3. Title and description: updated to the remaining scope.

The diff against development is now 3 files (multisig/script.rs, multisig/session.rs, wallet transaction_service/service.rs). cargo test -p tari_transaction_components --lib -- multisig offline_signing passes 82 tests. Nightly rustfmt --check is clean, and clippy on tari_transaction_components and minotari_wallet shows nothing in those files. I've left the wallet-level m + 1 withdraw test as a follow-up.

@SWvheerden SWvheerden left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 exactly m signatures. That matches check_multisig, which takes exactly m signatures off the stack.
  • The bounds in get_multi_sig_script_components match the consensus check against tari_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_wallet is clean.
  • cargo test -p tari_transaction_components --lib -- multisig offline_signing passes 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>
@Burapa-J

Copy link
Copy Markdown
Contributor Author

Thanks. Both are done in 974c0a2 (signed, no history rewrite):

  1. clippy: the duplicate-key test now uses keys.first().unwrap().clone() instead of keys[0], so clippy::indexing_slicing no longer fires.
  2. Error name: the comments at session.rs:140 and in the session test now say NonUnitLengthStack instead of StackNotEmpty.

Checked on 974c0a2:

  • cargo clippy --all-targets --all-features -p tari_transaction_components with the lints.toml flags is clean.
  • Nightly fmt (nightly-2026-06-01) is clean on both files.
  • cargo test -p tari_transaction_components --lib -- multisig offline_signing passes all 82 tests.

@Burapa-J Burapa-J changed the title fix(transaction_components): require exactly m multisig spend signatures and parse multisig scripts strictly fix(transaction_components): require exactly m multisig signatures and strict script parsing Nov 30, 2026
@SWvheerden
SWvheerden merged commit e1eb873 into tari-project:development Nov 30, 2026
22 of 23 checks passed
@Burapa-J Burapa-J changed the title fix(transaction_components): require exactly m multisig signatures and strict script parsing fix(transaction_components): enforce exactly m multisig signatures and strict parsing Nov 30, 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.

2 participants