Bitcoin Forum
May 06, 2024, 06:35:21 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Error: Signature must be zero for failed CHECK(MULTI)SIG operation  (Read 2417 times)
lontivero (OP)
Full Member
***
Offline Offline

Activity: 164
Merit: 126

Amazing times are coming


View Profile
November 14, 2016, 07:53:29 PM
 #1

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?
1714977321
Hero Member
*
Offline Offline

Posts: 1714977321

View Profile Personal Message (Offline)

Ignore
1714977321
Reply with quote  #2

1714977321
Report to moderator
1714977321
Hero Member
*
Offline Offline

Posts: 1714977321

View Profile Personal Message (Offline)

Ignore
1714977321
Reply with quote  #2

1714977321
Report to moderator
1714977321
Hero Member
*
Offline Offline

Posts: 1714977321

View Profile Personal Message (Offline)

Ignore
1714977321
Reply with quote  #2

1714977321
Report to moderator
"If you don't want people to know you're a scumbag then don't be a scumbag." -- margaritahuyan
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714977321
Hero Member
*
Offline Offline

Posts: 1714977321

View Profile Personal Message (Offline)

Ignore
1714977321
Reply with quote  #2

1714977321
Report to moderator
1714977321
Hero Member
*
Offline Offline

Posts: 1714977321

View Profile Personal Message (Offline)

Ignore
1714977321
Reply with quote  #2

1714977321
Report to moderator
1714977321
Hero Member
*
Offline Offline

Posts: 1714977321

View Profile Personal Message (Offline)

Ignore
1714977321
Reply with quote  #2

1714977321
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
November 14, 2016, 07:57:24 PM
 #2

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?

lontivero (OP)
Full Member
***
Offline Offline

Activity: 164
Merit: 126

Amazing times are coming


View Profile
November 14, 2016, 08:14:39 PM
 #3

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<byte[]> 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();
}


achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
November 14, 2016, 08:16:44 PM
 #4

So what does tx.Sign actually do? What is the code for that? Are you using a specific library for this?

lontivero (OP)
Full Member
***
Offline Offline

Activity: 164
Merit: 126

Amazing times are coming


View Profile
November 14, 2016, 08:38:05 PM
 #5

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.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
November 14, 2016, 08:48:52 PM
 #6

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.

myparentsdisownedme
Member
**
Offline Offline

Activity: 98
Merit: 10


View Profile
November 24, 2016, 06:27:07 PM
 #7

There was another thread with a similar problem


Hold up im going to try to find it 1 sec
MaxSoocha
Newbie
*
Offline Offline

Activity: 29
Merit: 12


View Profile
August 04, 2017, 02:20:29 AM
Last edit: August 23, 2022, 05:56:20 PM by MaxSoocha
 #8

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"]'
JamesBold
Newbie
*
Offline Offline

Activity: 52
Merit: 0


View Profile
August 26, 2017, 07:38:27 AM
 #9

Same here... when porting to ABC client, multi-sig transactions not working. Getting same error:

Carsten83FFM
Newbie
*
Offline Offline

Activity: 6
Merit: 0


View Profile
October 23, 2017, 09:28:51 PM
 #10

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\"]"
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!