Skip to content

verify signature against public key sighash #54

@zebpay-peswani

Description

@zebpay-peswani

I am working on trezor multisig support
I've a raw transaction 2of3 multisig signed by 1 cosigner

0100000001f479528049ee4b235548a7116f5ca31c607728af3d4ac8f102c5be13e93dcca900000000b40047304402201b83bd2209bc101736f60eeec3bcc1f79d45019d1829af97f5bd3210e8d8d786022020954c15372268d299b5463e1335595221e16222aee0291509a2098a0eb7fe80414c69522103556117b3f9a92f2997529af415c2c07185b872ddf1439995eca7f3acb65c58822103917f2527fc394ae2da48ce0148d29e5b756c4d9d180a6762bbe7abe215b29a562103f03364c624889c99059902524bcd8e2b24fb09cceb2e0f895d6475ef4913676553aeffffffff02a08601000000000017a914fd80725877f902f4491a6dc733fe788c376aeff8875033f4050000000017a9149aba36d2c19b08781230a4301f364610a163fc2d8700000000

Signed hex

304402201b83bd2209bc101736f60eeec3bcc1f79d45019d1829af97f5bd3210e8d8d786022020954c15372268d299b5463e1335595221e16222aee0291509a2098a0eb7fe80

public keys involved

['03556117b3f9a92f2997529af415c2c07185b872ddf1439995eca7f3acb65c5882', '03917f2527fc394ae2da48ce0148d29e5b756c4d9d180a6762bbe7abe215b29a56', '03f03364c624889c99059902524bcd8e2b24fb09cceb2e0f895d6475ef49136765']

transaction details

I want to verify from which public key signed the transaction out of 3 public key

I tried with the below code in electrumg

    tx = Transaction(raw_tx)
    sighash = Hash(bfh(tx.serialize_preimage(0)))

    pubkeys, x_pubkeys = tx.get_sorted_pubkeys(tx.inputs()[0])

    print(pubkeys)
    print(x_pubkeys)

    order = ecdsa.ecdsa.generator_secp256k1.order()
    r, s = ecdsa.util.sigdecode_der(bfh(sig), order)
    sig_string = ecdsa.util.sigencode_string(r, s, order)
    compressed = True

    for recid in range(4):
        print(recid)
        public_key = MyVerifyingKey.from_signature(sig_string, recid, sighash, curve=SECP256k1)
        print(public_key)
        pubkey = bh2u(point_to_ser(public_key.pubkey.point, compressed))
        print(pubkey)
        # print(public_key.verify_digest(sig_string, sighash, sigdecode=ecdsa.util.sigdecode_string))
    print(tx.signature_count())
    print(sighash.hex())

The output of this comes

1
02e4ee5e437084cc41095ef383803d06268068ce602a95d2e1cf7f5f5584a7d4b4
2
028b7b3b8a52b866166e34ae1194cbf60d3e2f553393410585ae4488cfb7a86796
3
027a9e3a118516cf8892b3c078ad6073f539c40e8301382f74ddc66de32783df2d

As you can see no public key match with original public keys. they all start with 02 and my public keys start with 03

Please help me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions