1

I have this testnet transaction that I created:

Version: 01000000
Marker: 00
Flag: 01
Input Count: 01
    Input #1 TXID: 42a752fe4ebd0bdc69cb1b3724de6ccc364661028ab9c043526f3f7cb0571147
    Input #1 VOUT: 00000000
    Input #1 ScriptSize: 00
    Input #1 ScriptSig:
    Input #1 Sequence: ffffffff
Output Count: 01
    Output Value: e8fd000000000000
    Output Script Length:16
    Output Script: 00143778e5361fdad0d209de8a16c2ec4ca64618993e
Witness:
    Witness Stack Size: 02
    Witness Signature Length: 47
    Witness Signature: 304402204af85395dd8c758ac379c343bc278351f73cdf9d8548d933aada5fa4e13194a80220126c0614f75520709e63ac41 9308344c00a4a22c021e1b9d8b42115aa73e37b01
    Witness PubKey Length: 21
    Witness PubKey: 02ad2a42eed9fecc022093e8682b62b034690b06587be18f01bb8e60df1afeaaf8
Locktime: 00000000

When I try to broadcast it, it gives me this error:

Mempool accept test failed: 64: non-mandatory-script-verify-flag (Signature must be zero for failed CHECK(MULTI)SIG operation)

I believe this error occurs because the signature is incorrect, but I am having a hard time identifying how I created the wrong signature.

Here are the steps I took to sign the transaction:

Sign the hash of the following with the signing key:
1. Transaction version (4 bytes little endian)
2. The hash of all input outpoints (32 bytes)
3. The hash of all input sequences (32 bytes)
4. The outpoint (32 + 4 bytes)
5. The script code (26 bytes consisting of 0x1976a914<20 byte pub key hash>88ac)
6. The value of the input being signed (8 bytes little endian)
7. The sequence of the input being signed (4 byte little endian)
8. The hash of all the outputs (32 byte)
9. The locktime of the transaction (4 bytes little endian)
10. Sighash type (4 bytes little endian)

this signature was then used in conjunction with the Public key of the signing key to create the Witness script as seen above.

Here is the info I used to create the transaction:

Input #1:
    txid: 471157b07c3f6f5243c0b98a02614636cc6cde24371bcb69dc0bbd4efe52a742
    out: 0
    signing key wif: 3a8c0c731cba400917f66bc3435a405387a9a5b20cdbfdedb19e37d0c6cad8b9

Output #1
    value: 65000
    recipient: tb1qxauw2dslmtgdyzw73gtv9mzv5erp3xf7mt83vq
4
  • The sighash type is missing in the sighash calculation. 10. sighash type of the signature (4-byte little endian) Commented Sep 30, 2021 at 9:18
  • @ShigeyukiAzuchi My mistake when writing out the steps. My code was appending the sig hash type but still am getting the wrong signature.
    – Keijyu
    Commented Sep 30, 2021 at 9:49
  • As a result, what is the value of the sighash you generated? Commented Sep 30, 2021 at 14:15
  • 1
    I found my mistake. I was not reversing the TXID when serializing the tx according to BIP143. Thanks @ShigeyukiAzuchi
    – Keijyu
    Commented Oct 2, 2021 at 4:22

2 Answers 2

1

Witness Signature: 304402204af85395dd8c758ac379c343bc278351f73cdf9d8548d933aada5fa4e13194a80220126c0614f75520709e63ac41 9308344c00a4a22c021e1b9d8b42115aa73e37b01

It seems that the signature value contains white space.

Isn't the correct signature value below?

30440220722ed739d8a69832ecf6e5d636b2949ab6dc00026b88129a8652916904b80c6e0220370d30e8fb3e2d76f6c64b6d89e050ab47faefd3ca017752496035329534207e01

And full tx is:

01000000000101471157b07c3f6f5243c0b98a02614636cc6cde24371bcb69dc0bbd4efe52a7420000000000ffffffff01e8fd0000000000001600143778e5361fdad0d209de8a16c2ec4ca64618993e024730440220722ed739d8a69832ecf6e5d636b2949ab6dc00026b88129a8652916904b80c6e0220370d30e8fb3e2d76f6c64b6d89e050ab47faefd3ca017752496035329534207e012102ad2a42eed9fecc022093e8682b62b034690b06587be18f01bb8e60df1afeaaf800000000

0

tx_hash_big_endian":"5da8f74aa4d6612c58c0a740b4740579db57c95828e4cdf04e7d18c23b66cb4a","tx_hash":"4acb663bc2187d4ef0cde42858c957db790574b440a7c0582c61d6a44af7a85d", Auto-correct ^ class S256Point(Point): ... def sec(self): '''returns the binary version of the SEC format''' return b'\x04' + self.x.num.to_bytes(32, 'big') \ + self.y.num.to_bytes(32, 'big')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.