Bitcoin Forum
November 22, 2018, 11:58:13 AM *
News: Latest Bitcoin Core release: 0.17.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 2120 times)
lontivero
Full Member
***
Offline Offline

Activity: 157
Merit: 100

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?
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1542887893
Hero Member
*
Offline Offline

Posts: 1542887893

View Profile Personal Message (Offline)

Ignore
1542887893
Reply with quote  #2

1542887893
Report to moderator
1542887893
Hero Member
*
Offline Offline

Posts: 1542887893

View Profile Personal Message (Offline)

Ignore
1542887893
Reply with quote  #2

1542887893
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 1596
Merit: 1761


bc1qshxkrpe4arppq89fpzm6c0tpdvx5cfkve2c8kl


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
Full Member
***
Offline Offline

Activity: 157
Merit: 100

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: 1596
Merit: 1761


bc1qshxkrpe4arppq89fpzm6c0tpdvx5cfkve2c8kl


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
Full Member
***
Offline Offline

Activity: 157
Merit: 100

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: 1596
Merit: 1761


bc1qshxkrpe4arppq89fpzm6c0tpdvx5cfkve2c8kl


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: 13
Merit: 0


View Profile
August 04, 2017, 02:20:29 AM
 #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? 

Code:

decodescript 5241049d1b6d42d4a8a3e8804571fc08e57cc20fe88f0d2d9c81a6994871919ffc7d931a0d554e35d095fa7d9f469f5dee9f9b5acd283dc141a90be64322289aa125914104b8cd3bc653efb0752d82b451dfe53f978cd38464188aa6399b339702c40396b2892f34adf73ea43829b446fe9143581a412b6094f4aeaa47c52984859a96a2ee4104f21aebac0c331445fdafbe425d45ea99b8d46ef07a06ee7780ef3f347183e9eb40a512fb681f96117ab15165d83d0925e193de751a7e6da7ed93c209f0b58e0253ae



{
  "asm": "2 049d1b6d42d4a8a3e8804571fc08e57cc20fe88f0d2d9c81a6994871919ffc7d931a0d554e35d095fa7d9f469f5dee9f9b5acd283dc141a90be64322289aa12591 04b8cd3bc653efb0752d82b451dfe53f978cd38464188aa6399b339702c40396b2892f34adf73ea43829b446fe9143581a412b6094f4aeaa47c52984859a96a2ee 04f21aebac0c331445fdafbe425d45ea99b8d46ef07a06ee7780ef3f347183e9eb40a512fb681f96117ab15165d83d0925e193de751a7e6da7ed93c209f0b58e02 3 OP_CHECKMULTISIG",
  "reqSigs": 2,
  "type": "multisig",
  "addresses": [
    "1NWZpxQ1ATrJKqdTqSPSWgEQrRWCfEYSM8",
    "18kMNg2Mw1v88NViKePVMD1o38FWj5zzLu",
    "14izfR267otujhjq39xZyi9JGrkGSiDcjY"
  ],
  "p2sh": "3MD9o1jtghDJALtDGambXbkyu2MvSS15ZR"
}

     
Code:

decoderawtransaction 020000000119485fd232b8fd0c8d103db6b6a8914e76606fbf07f9ba301275878a430dd01c00000000fd5c0100473044022046d64b21572c8f5377463aaedb0fb6a2a0cef83781b39e445fd20f44908dc6e002201a94a2ec336a8819f821cb19d21f1836902779993c0760d2a2bc9e0ea68faf6d4147304402204024b83e039cc8e96bb3d57293ba2d0b902fe9ab9ce4b1b6b6cf22f48799dd57022026df4b8a6406828050e9ddbb7014885318772064d326101c87ac0a951ce578b4414cc95241049d1b6d42d4a8a3e8804571fc08e57cc20fe88f0d2d9c81a6994871919ffc7d931a0d554e35d095fa7d9f469f5dee9f9b5acd283dc141a90be64322289aa125914104b8cd3bc653efb0752d82b451dfe53f978cd38464188aa6399b339702c40396b2892f34adf73ea43829b446fe9143581a412b6094f4aeaa47c52984859a96a2ee4104f21aebac0c331445fdafbe425d45ea99b8d46ef07a06ee7780ef3f347183e9eb40a512fb681f96117ab15165d83d0925e193de751a7e6da7ed93c209f0b58e0253aeffffffff01c024ec38000000001976a914f5b04fed557924a2d454c35354f59f2c9e3a8d4388ac00000000


{
  "txid": "613db8a55c39d61450555e62a0824ff4595e0a5bff3be75386ae75d15ff99422",
  "hash": "613db8a55c39d61450555e62a0824ff4595e0a5bff3be75386ae75d15ff99422",
  "size": 435,
  "version": 2,
  "locktime": 0,
  "vin": [
    {
      "txid": "1cd00d438a87751230baf907bf6f60764e91a8b6b63d108d0cfdb832d25f4819",
      "vout": 0,
      "scriptSig": {
        "asm": "0 3044022046d64b21572c8f5377463aaedb0fb6a2a0cef83781b39e445fd20f44908dc6e002201a94a2ec336a8819f821cb19d21f1836902779993c0760d2a2bc9e0ea68faf6d[ALL|FORKID] 304402204024b83e039cc8e96bb3d57293ba2d0b902fe9ab9ce4b1b6b6cf22f48799dd57022026df4b8a6406828050e9ddbb7014885318772064d326101c87ac0a951ce578b4[ALL|FORKID] 5241049d1b6d42d4a8a3e8804571fc08e57cc20fe88f0d2d9c81a6994871919ffc7d931a0d554e35d095fa7d9f469f5dee9f9b5acd283dc141a90be64322289aa125914104b8cd3bc653efb0752d82b451dfe53f978cd38464188aa6399b339702c40396b2892f34adf73ea43829b446fe9143581a412b6094f4aeaa47c52984859a96a2ee4104f21aebac0c331445fdafbe425d45ea99b8d46ef07a06ee7780ef3f347183e9eb40a512fb681f96117ab15165d83d0925e193de751a7e6da7ed93c209f0b58e0253ae",
        "hex": "00473044022046d64b21572c8f5377463aaedb0fb6a2a0cef83781b39e445fd20f44908dc6e002201a94a2ec336a8819f821cb19d21f1836902779993c0760d2a2bc9e0ea68faf6d4147304402204024b83e039cc8e96bb3d57293ba2d0b902fe9ab9ce4b1b6b6cf22f48799dd57022026df4b8a6406828050e9ddbb7014885318772064d326101c87ac0a951ce578b4414cc95241049d1b6d42d4a8a3e8804571fc08e57cc20fe88f0d2d9c81a6994871919ffc7d931a0d554e35d095fa7d9f469f5dee9f9b5acd283dc141a90be64322289aa125914104b8cd3bc653efb0752d82b451dfe53f978cd38464188aa6399b339702c40396b2892f34adf73ea43829b446fe9143581a412b6094f4aeaa47c52984859a96a2ee4104f21aebac0c331445fdafbe425d45ea99b8d46ef07a06ee7780ef3f347183e9eb40a512fb681f96117ab15165d83d0925e193de751a7e6da7ed93c209f0b58e0253ae"
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 9.55000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 f5b04fed557924a2d454c35354f59f2c9e3a8d43 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914f5b04fed557924a2d454c35354f59f2c9e3a8d4388ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "1PQ5mPPG19J13Be793ee3c3mXqVABPZHKK"
        ]
      }
    }
  ]
}


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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!