Author

Topic: Error: Signature must be zero for failed CHECK(MULTI)SIG operation (Read 2437 times)

newbie
Activity: 6
Merit: 0
In the "signrawtransaction" command you have to specify the original (total!) amount of the P2SH address:

signrawtransaction $RAW_TX "[{\"txid\":\"$UTXO_TXID\",\"amount\":$ORIGAMOUNT,\"vout\":$UTXO_VOUT,\"scriptPubKey\":\"$UTXO_OUTPUT_SCRIPT\",\"redeemScript\":\"$P2SH_REDEEM_SCRIPT\"}]" "[\"$PRIVATE_KEY1\"]"
jr. member
Activity: 60
Merit: 1
Same here... when porting to ABC client, multi-sig transactions not working. Getting same error:

newbie
Activity: 29
Merit: 12
Hold up im going to try to find it 1 sec

Did you ever resolve this? I'm having the same error when trying to split some coins from my paper wallet multisig. I was able to move these coins fine on bitcoin, but when building the raw transaction in BitcoinABC client I'm receiving this error when trying to broadcast. Is there an extra/different parameter for `createrawtransaction` or `signrawtransaction` I'm not aware of?  

Any idea what I did wrong?

I was following this schematic when building my transaction.
Code:
createrawtransaction '[{"txid":"","vout":}]' '{"receive_address":0.0008}'
signrawtransaction 'hash_from_createraw' '[{"txid":"","vout":,"scriptPubKey":"","redeemScript":""}]' '["priv_key"]'
signrawtransaction 'hash_from_signraw' '[{"txid":"","vout":,"scriptPubKey":"","redeemScript":""}]' '["priv_key2"]'
member
Activity: 98
Merit: 10
There was another thread with a similar problem


Hold up im going to try to find it 1 sec
staff
Activity: 3458
Merit: 6793
Just writing some code
UPDATE:


Code:
C:\Users\lucas.ontivero>bitcoin-cli decodescript 473044022027e72718acc7a14b3654cc4e86cb5d46d5ca020e327d9941a7965a3e9a52a4840220243a7ed16753f46194ffbdec68c4fa300c23cba30e499a147eba383f47119c2d01
{
  "asm": "3044022027e72718acc7a14b3654cc4e86cb5d46d5ca020e327d9941a7965a3e9a52a4840220243a7ed16753f46194ffbdec68c4fa300c23cba30e499a147eba383f47119c2d01",
  "type": "nonstandard",
  "p2sh": "2N1ceLS8UmGjqnduV5G11suZKpjoDd49dNH"
}

It says type: nonstandard! why?

That isn't the script. That is the signature, not a script. Decodescript should be used for the output scripts or a redeemscript of a p2sh output, not the full scriptsig of an input.

tx.Sign signs a specific coin with the given private key, i am using https://github.com/MetacoSA/NBitcoin library.

The code is for timestamping data in the bitcoin blockchain.

Since you are using NBitcoin, the signing itself should be correct. The problem is probably that you built the transaction incorrectly. However, I am not familiar with NBitcoin, so I am not sure what exactly is wrong.
full member
Activity: 164
Merit: 126
Amazing times are coming
So what does tx.Sign actually do? What is the code for that? Are you using a specific library for this?

tx.Sign signs a specific coin with the given private key, i am using https://github.com/MetacoSA/NBitcoin library.

The code is for timestamping data in the bitcoin blockchain.
staff
Activity: 3458
Merit: 6793
Just writing some code
So what does tx.Sign actually do? What is the code for that? Are you using a specific library for this?
full member
Activity: 164
Merit: 126
Amazing times are coming
It means that you have a bad signature. What did you do to sign the transaction? What is the output that you are spending from?

This is what i did:

First, i generated 101 blocks with:

Code:
bitcoin-cli generate 101

Next i list the unspent outputs:

Code:
bitcoin-cli listunspent
[
  {
    "txid": "36f79ff9e543de7eeb589cf65dc9fa5bc36db7c5a96ae6b8f05d89f96ffa4088",
    "vout": 0,
    "address": "mkwLRxyMhe8ZXc37g12oVXtCbcTV6vQ4me",
    "scriptPubKey": "2102b9567015d1a0dc9337b35bc23222b017b48487c46c9063155b9ec4499b99d421ac",
    "amount": 50.00000000,
    "confirmations": 101,
    "spendable": true,
    "solvable": true
  }
]

I get the private key for the address containing the 50btc:

Code:
bitcoin-cli dumpprivkey mkwLRxyMhe8ZXc37g12oVXtCbcTV6vQ4me
cUBBp6TfHmyhrApkrVGiP83DCTtdnHHEreXe8eJwANv2tLUUcLAv


and finally my code is the following: (i'm not asking a code review. what I want to show is that i am signing the transaction with the private key obtained fron the utxo)

Code:
public async Task PersistAsync(byte[] data)
{
var coins = await _repository.GetUnspentCoinsAsync();
if (!coins.Any())
throw new Exception("No enough money");

var coin = coins.First();

var valueIn = coin.Amount.Satoshi;
var changeAddress = BitcoinAddress.Create("mw58cUP45n5S3cA82p5nFxNWYT8L4YZWHw");  //one of my addresses
var tx = new Transaction();

var changeTxOut = new TxOut(valueIn, changeAddress);
var digestTxOut = new TxOut(0, new Script(OpcodeType.OP_RETURN, Op.GetPushOp(data)));

tx.Inputs.Add(new TxIn(coin.Outpoint));
tx.Outputs.Add(changeTxOut);
tx.Outputs.Add(digestTxOut);

var feeRate = await _feeProvider.GetFeeAsync();
var effectiveFee = 0L;
var suggestedFee = feeRate.GetFee(tx);

var key = Key.Parse("cUBBp6TfHmyhrApkrVGiP83DCTtdnHHEreXe8eJwANv2tLUUcLAv");
while (effectiveFee < suggestedFee)
{
changeTxOut.Value = valueIn - suggestedFee;
tx.Sign(key, coin);   // <---------- HERE I SIGN THE INPUT WITH THE PRIVATE KEY

effectiveFee = valueIn - tx.Outputs[0].Value.Satoshi;
suggestedFee = feeRate.GetFee(tx);
}

await _repository.PushAsync(tx);
return tx.GetHash().ToBytes();
}


staff
Activity: 3458
Merit: 6793
Just writing some code
It means that you have a bad signature. What did you do to sign the transaction? What is the output that you are spending from?
full member
Activity: 164
Merit: 126
Amazing times are coming
Hi, could someone give me a hand with an error?

16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)

I get this error message when i try to send a transaction in regtest (i didn't test it in other networks). Details:


Code:
bitcoin-cli sendrawtransaction "01000000019a6f1c41fd248d499742f5d35f8fa261be00a0a187785eefe5d1cacb42abe2930000000048473044022027e72718acc7a14b3654cc4e86cb5d46d5ca020e327d9941a7965a3e9a52a4840220243a7ed16753f46194ffbdec68c4fa300c23cba30e499a147eba383f47119c2d01ffffffff0250bb052a010000001976a914aa9fcf69961a101de1a3279238657391e9f8141b88ac0000000000000000226a20d4962daf2b2f39666bcd8d35df1357c5608b7019791c20812cd9108b830388bc00000000"
error code: -26
error message:
16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)



Code:
bitcoin-cli decoderawtransaction "01000000019a6f1c41fd248d499742f5d35f8fa261be00a0a187785eefe5d1cacb42abe2930000000048473044022027e72718acc7a14b3654cc4e86cb5d46d5ca020e327d9941a7965a3e9a52a4840220243a7ed16753f46194ffbdec68c4fa300c23cba30e499a147eba383f47119c2d01ffffffff0250bb052a010000001976a914aa9fcf69961a101de1a3279238657391e9f8141b88ac0000000000000000226a20d4962daf2b2f39666bcd8d35df1357c5608b7019791c20812cd9108b830388bc00000000"
{
  "txid": "eb09809dcedeca7874c5b9457256e8418ba00d96a35d9e3526f17a7f11030e36",
  "hash": "eb09809dcedeca7874c5b9457256e8418ba00d96a35d9e3526f17a7f11030e36",
  "size": 200,
  "vsize": 200,
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "93e2ab42cbcad1e5ef5e7887a1a000be61a28f5fd3f54297498d24fd411c6f9a",
      "vout": 0,
      "scriptSig": {
        "asm": "3044022027e72718acc7a14b3654cc4e86cb5d46d5ca020e327d9941a7965a3e9a52a4840220243a7ed16753f46194ffbdec68c4fa300c23cba30e499a147eba383f47119c2d[ALL]",
        "hex": "473044022027e72718acc7a14b3654cc4e86cb5d46d5ca020e327d9941a7965a3e9a52a4840220243a7ed16753f46194ffbdec68c4fa300c23cba30e499a147eba383f47119c2d01"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 49.99986000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 aa9fcf69961a101de1a3279238657391e9f8141b OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914aa9fcf69961a101de1a3279238657391e9f8141b88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "mw58cUP45n5S3cA82p5nFxNWYT8L4YZWHw"
        ]
      }
    },
    {
      "value": 0.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_RETURN d4962daf2b2f39666bcd8d35df1357c5608b7019791c20812cd9108b830388bc",
        "hex": "6a20d4962daf2b2f39666bcd8d35df1357c5608b7019791c20812cd9108b830388bc",
        "type": "nulldata"
      }
    }
  ]
}

Can you see what is wrong? Thank you.


UPDATE:


Code:
C:\Users\lucas.ontivero>bitcoin-cli decodescript 473044022027e72718acc7a14b3654cc4e86cb5d46d5ca020e327d9941a7965a3e9a52a4840220243a7ed16753f46194ffbdec68c4fa300c23cba30e499a147eba383f47119c2d01
{
  "asm": "3044022027e72718acc7a14b3654cc4e86cb5d46d5ca020e327d9941a7965a3e9a52a4840220243a7ed16753f46194ffbdec68c4fa300c23cba30e499a147eba383f47119c2d01",
  "type": "nonstandard",
  "p2sh": "2N1ceLS8UmGjqnduV5G11suZKpjoDd49dNH"
}

It says type: nonstandard! why?
Jump to: