Skip to content

commands: createmultisig: validate arguments like bitcoind does - #11021

Open
devdavidejesus wants to merge 2 commits into
spesmilo:masterfrom
devdavidejesus:fix-createmultisig-validation
Open

devdavidejesus wants to merge 2 commits into
spesmilo:masterfrom
devdavidejesus:fix-createmultisig-validation

Conversation

@devdavidejesus

Copy link
Copy Markdown
Contributor

On master, createmultisig does not validate its arguments:

$ electrum --testnet createmultisig 1 '["0378"]'
{
    "address": "2N7r9SCdMN9u4frmSdyPJcF8wEEuVWEnCFH",
    "redeemScript": "5102037851ae"
}

0378 is not a public key, yet an address is returned; coins sent to a multisig address built with an invalid key might not be spendable. Likewise, 8 uncompressed keys give a 531-byte redeem script, which cannot be spent as p2sh (520-byte limit), and other bad arguments raise bare AssertionErrors.

This adds the checks that bitcoind's createmultisig does (HexToPubKey and AddAndGetMultisigDestination in src/rpc/util.cpp): num must be an integer with 1 <= num <= number of keys, each key must be a valid hex-encoded public key (hybrid keys are accepted, as in bitcoind), and the redeem script must fit in 520 bytes. The limit of 15 keys from multisig_script is kept.

The order of the keys is unchanged (see #5343). Keys passed as bytes, which only worked from the Python console, are no longer accepted, as the argument is documented as a list of hex strings.

An invalid public key was silently accepted (e.g. createmultisig 1 '["0378"]'),
yielding an address whose coins might not be spendable. A redeem script
larger than 520 bytes (e.g. 8 uncompressed keys) also yielded an
unspendable p2sh address. Bad parameters raised bare AssertionErrors.

Now the same checks as bitcoind's createmultisig are done: num must be an
integer, the public keys must be valid hex-encoded points (hybrid keys are
accepted, as in bitcoind), and the redeem script must fit in 520 bytes.
Public keys given as bytes are no longer accepted. The order of the public
keys is unchanged (see spesmilo#5343).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants