Skip to content

fix(client/tx): populate multisig bit array in simulation tx - #26776

Open
riba2534 wants to merge 1 commit into
cosmos:mainfrom
riba2534:cursor/fix-multisig-gas-auto-simulation-547d
Open

fix(client/tx): populate multisig bit array in simulation tx#26776
riba2534 wants to merge 1 commit into
cosmos:mainfrom
riba2534:cursor/fix-multisig-gas-auto-simulation-547d

Conversation

@riba2534

Copy link
Copy Markdown
Contributor

Description

Fixes #26759

--gas auto is broken for any multisig sender since #26515:

Error: bit array size is incorrect, expecting: 3

Factory.getSimSignatureData built the dummy signing.MultiSignatureData for the simulation tx with Signatures populated but BitArray left nil. #26515 then required sig.BitArray.Count() == len(pubkey.GetPubKeys()). A nil bit array counts as 0, so simulation always fails before gas is estimated.

Before that check, the nil bit array meant the gas-consumer loop never ran, so multisig simulation "worked" but charged zero signature-verification gas.

Fix

Size the simulation bit array to the full key set and set the first Threshold bits, matching the dummy sub-signatures already created. The ante-handler bounds check is left untouched.

The loop also recurses into selected sub-keys. Without that, a nested multisig sub-key would get SingleSignatureData and DefaultSigVerificationGasConsumer would reject it.

As a side effect, multisig gas estimation now accounts for the Threshold sub-signature verifications instead of silently charging zero.

Tests

Both fail before the fix and pass after.

  • TestFactory_getSimSignatureDataMultisig — 1-of-1, 2-of-3, and a nested-multisig sub-key
  • TestBuildSimTxMultisig — end-to-end --gas auto path; reproduces bit array size is incorrect, expecting: 3 without the fix

Verified: make build, go test ./client/... ./x/auth/... ./crypto/..., cd tests && go test ./integration/auth/..., lint clean on the root module.

@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.96%. Comparing base (0135947) to head (0c8daea).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #26776      +/-   ##
==========================================
- Coverage   65.27%   64.96%   -0.31%     
==========================================
  Files         830      785      -45     
  Lines       58577    55399    -3178     
==========================================
- Hits        38235    35992    -2243     
+ Misses      20342    19407     -935     
Files with missing lines Coverage Δ
client/tx/factory.go 79.02% <100.00%> (+3.64%) ⬆️

... and 55 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread client/tx/factory.go
// set, otherwise the ante handler rejects the simulation tx before estimating gas.
subKeys := multisigPubKey.PubKeys
bitArray := cryptotypes.NewCompactBitArray(len(subKeys))
multiSignatureData := make([]signing.SignatureData, 0, multisigPubKey.Threshold)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ensure that multisigPubKey.Threshold <= len(subKeys)

Comment thread client/tx/factory.go Outdated
multiSignatureData = append(multiSignatureData, &signing.SingleSignatureData{
SignMode: f.SignMode(),
})
for i := 0; i < len(subKeys) && i < int(multisigPubKey.Threshold); i++ {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

then

Suggested change
for i := 0; i < len(subKeys) && i < int(multisigPubKey.Threshold); i++ {
for i := 0; i < int(multisigPubKey.Threshold); i++ {

Comment thread client/tx/factory.go Outdated
})
for i := 0; i < len(subKeys) && i < int(multisigPubKey.Threshold); i++ {
bitArray.SetIndex(i, true)
subKey, _ := subKeys[i].GetCachedValue().(cryptotypes.PubKey)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fail if !ok

Suggested change
subKey, _ := subKeys[i].GetCachedValue().(cryptotypes.PubKey)
subKey, ok := subKeys[i].GetCachedValue().(cryptotypes.PubKey)

@cursor
cursor Bot force-pushed the cursor/fix-multisig-gas-auto-simulation-547d branch from 0c8daea to 54ade17 Compare September 4, 2026 11:10
Factory.getSimSignatureData built a dummy MultiSignatureData with the
Signatures slice populated but BitArray left nil. Since cosmos#26515 hardened
ConsumeMultisignatureVerificationGas to require the bit array to be sized
to the key set, a nil bit array (which counts as 0) makes every multisig
simulation fail with "bit array size is incorrect, expecting: N", so
--gas auto is unusable for multisig senders.

Size the bit array to the full key set and set the first Threshold bits,
and recurse into sub-keys so a nested multisig sub-key gets multisig dummy
signature data instead of single-signature data (which the gas consumer
also rejects). Validate that Threshold does not exceed the key set and
fail when a sub-key cannot be decoded as a public key.

Fixes cosmos#26759
@cursor
cursor Bot force-pushed the cursor/fix-multisig-gas-auto-simulation-547d branch from 54ade17 to 799080c Compare September 4, 2026 11:12
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.

--gas auto fails for multisig senders since v0.53.8: "bit array size is incorrect, expecting: N"

2 participants