I can't broadcast signed rawtransation
bitcoin transaction signed as below 01000000019ef110ca866e78026d725f3e31f444cf40e494b8a4a96666a0e5e5d7a1365795000000006a473044022021a09fe4e1ab05e3a2aa741d1d00413c96bd0e34ce731185f793218ff5b19cfa0220191fc76cd830af57c2f10aabeb99fd139ce9de6fa25aa076d4cfed05c1a4cc790121022def2c9f983c75bb26d94beaa07190fc78113cb7e50249a7388c4be139448a80ffffffff0250c30000000000001976a914ae86141c9e2360ca05e441fe84f3c8c7f3d1b97b88accbc00000000000001976a914513a7c1b271ac822b71f2b908f648604f3ebe15088ac00000000
rawtransaction decoded as below
{ "txid": "53ae2b1f09e4fb5c5828c9208d13b10f56befcb4fd10a47b8265ffad13a0b186", "hash": "53ae2b1f09e4fb5c5828c9208d13b10f56befcb4fd10a47b8265ffad13a0b186", "version": 1, "size": 225, "vsize": 225, "weight": 900, "locktime": 0, "vin": [ { "txid": "955736a1d7e5e5a06666a9a4b894e440cf44f4313e5f726d02786e86ca10f19e", "vout": 0, "scriptSig": { "asm": "3044022021a09fe4e1ab05e3a2aa741d1d00413c96bd0e34ce731185f793218ff5b19cfa0220191fc76cd830af57c2f10aabeb99fd139ce9de6fa25aa076d4cfed05c1a4cc79[ALL] 022def2c9f983c75bb26d94beaa07190fc78113cb7e50249a7388c4be139448a80", "hex": "473044022021a09fe4e1ab05e3a2aa741d1d00413c96bd0e34ce731185f793218ff5b19cfa0220191fc76cd830af57c2f10aabeb99fd139ce9de6fa25aa076d4cfed05c1a4cc790121022def2c9f983c75bb26d94beaa07190fc78113cb7e50249a7388c4be139448a80" }, "sequence": 4294967295 } ], "vout": [ { "value": 0.0005, "n": 0, "scriptPubKey": { "asm": "OP_DUP OP_HASH160 ae86141c9e2360ca05e441fe84f3c8c7f3d1b97b OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a914ae86141c9e2360ca05e441fe84f3c8c7f3d1b97b88ac", "reqSigs": 1, "type": "pubkeyhash", "addresses": [ "1GuoCKaQy1QtNzrcRNmqyERRFpqbB2ubYy" ] } }, { "value": 0.00049355, "n": 1, "scriptPubKey": { "asm": "OP_DUP OP_HASH160 513a7c1b271ac822b71f2b908f648604f3ebe150 OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a914513a7c1b271ac822b71f2b908f648604f3ebe15088ac", "reqSigs": 1, "type": "pubkeyhash", "addresses": [ "18QVo8hHcZzMeDpQe36wEUyye5hS4JABpL" ] } } ] }
when I try to broadcast tx , got error like this bitcoinlib.services.authproxy.JSONRPCException: -26: non-mandatory-script-verify-flag (Non-canonical signature: S value is unnecessarily high) (code 64)
probable cause I looked up in google is that I have used compressed public key to sign transaction, but how to use uncompressed key to sign transaction by bitcoinlib?
Are you using the latest version of bitcoinlib? Because I know there was an problem with high s values in signatures in older versions.
Are you using the latest version of bitcoinlib? Because I know there was an problem with high s values in signatures in older versions.
current version of bitcoinlib imported in my python project equals to 0.4.15. I think maybe it's newest version. could you please tell in which version the high s values problem was fixed?
Yes, 0.4.15 is the latest version, so that shouldn't be the problem.
The s value in the signature input in the raw transaction you provided is correct / canonical. You can check this:
rawtx = '01000000019ef110ca866e78026d725f3e31f444cf40e494b8a4a96666a0e5e5d7a1365795000000006a473044022021a09fe4e1ab05e3a2aa741d1d00413c96bd0e34ce731185f793218ff5b19cfa0220191fc76cd830af57c2f10aabeb99fd139ce9de6fa25aa076d4cfed05c1a4cc790121022def2c9f983c75bb26d94beaa07190fc78113cb7e50249a7388c4be139448a80ffffffff0250c30000000000001976a914ae86141c9e2360ca05e441fe84f3c8c7f3d1b97b88accbc00000000000001976a914513a7c1b271ac822b71f2b908f648604f3ebe15088ac00000000'
t = Transaction.import_raw(rawtx)
s = t.inputs[0].signatures[0].s
print("s: ", s)
print("max s:", int(secp256k1_n / 2))
print("canonical? ", bool(int(s) < secp256k1_n / 2))
which returns
s: 11363969855554523818154740034565561317625499026827673321800212021233599171705
max s: 57896044618658097711785492504343953926634992332820282019728792003956564819968
canonical? True
So I'm not sure why the transaction got rejected, the error message seems incorrect. Are you using bitcoind to send the transaction?
Do you mind sharing the code you used to create and sign the transaction? You can also email me if you're concerned about privacy.
I have exactly the same problem. my code is as below :
input = Input(prev_hash=prev_hash, output_n=output_n,keys=key.public(), network='testnet' ,witness_type="segwit" , value = value )
output = Output(amount, address=outputAddress, network='testnet'))
t = Transaction(input, output, network='testnet' , witness_type="segwit" , fee = fee , version = 2)
t.sign(key.private_byte)
t.verify()
s = t.inputs[0].signatures[0].s
print("s: ", s)
print("max s:", int(secp256k1_n / 2))
print("canonical? ", bool(int(s) < secp256k1_n / 2))
and I get the following output :
s: 4433750427723256683445658442641718727065179203509893270619600250655989546140
max s: 57896044618658097711785492504343953926634992332820282019728792003956564819968
canonical? True
but when I want to broadcast the raw transaction I get this error :
"sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Non-canonical signature: S value is unnecessarily high)"}"
I tested it with version 1 transactions and legacy transactions too. the only situation that I don't get this error is when I use version= 1 and witness_type="legacy"
I have exactly the same problem. my code is as below :
input = Input(prev_hash=prev_hash, output_n=output_n,keys=key.public(), network='testnet' ,witness_type="segwit" , value = value ) output = Output(amount, address=outputAddress, network='testnet')) t = Transaction(input, output, network='testnet' , witness_type="segwit" , fee = fee , version = 2) t.sign(key.private_byte) t.verify() s = t.inputs[0].signatures[0].s print("s: ", s) print("max s:", int(secp256k1_n / 2)) print("canonical? ", bool(int(s) < secp256k1_n / 2))and I get the following output : s: 4433750427723256683445658442641718727065179203509893270619600250655989546140 max s: 57896044618658097711785492504343953926634992332820282019728792003956564819968 canonical? True
but when I want to broadcast the raw transaction I get this error : "sendrawtransaction RPC error: {"code":-26,"message":"non-mandatory-script-verify-flag (Non-canonical signature: S value is unnecessarily high)"}"
I tested it with version 1 transactions and legacy transactions too. the only situation that I don't get this error is when I use
version= 1andwitness_type="legacy"
bro, how did you solve this problem?