Sunday, December 22, 2024

bitcoinj – spend founds from p2wsh deal with,non-mandatory-script-verify-flag (Signature have to be zero for failed CHECK(MULTI)SIG operation) (code 64)

i need spent coin from p2wsh deal with on btc testnet3 community, i exploit bitcoinj 0.15.2 construct transaction and signal it, use 2/3 multiSig

when i ship uncooked transaction by bitcoin core 0.17.0 command line by use ./bitcoin-cli sendrawtransaction, i get error

error code: -26
error message:non-mandatory-script-verify-flag (Signature have to be zero for failed CHECK(MULTI)SIG operation) (code 64)

For now, I do not identified why my signed tx broadcast fali?
please assist me,Thanks prematurely.

related data

private_key1:cUkNoCzNXMXzN4JhYYbgiWAaKQEwfgUAzW2kogRNhUqGaiZ2AdUh
private_key2:cUpdkS6ekPkQj1RJWtjbLbYyDwszb3nEBbRkeRf9QHVkBBijEdgv
private_key3:cU4tWJk3BGymoJgbGbxNA6NJapTwrbfWWaPsz1bCZBzkoeszb4ML

p2wsh deal with:tb1qrgwja0j7447fz66gufzuj4awed63xm5xpgs57qwpmm0ujc0x7vusdrjmw6

witness script str:2 PUSHDATA(33)[037a5929bacc6251ace6fb688c7de760b047f03ef1d23f86bbbf61c152c16a4409] PUSHDATA(33)[02764c145abc62bf1c3786136c7020b4cef227102f458aa607afc6afda7b578ce6] PUSHDATA(33)[02f06485529af46c93b4bd6ab68f44dc58241176a989cca77fe052644a7602d048] 3 CHECKMULTISIG

witness script encode str:5221037a5929bacc6251ace6fb688c7de760b047f03ef1d23f86bbbf61c152c16a44092102764c145abc62bf1c3786136c7020b4cef227102f458aa607afc6afda7b578ce62102f06485529af46c93b4bd6ab68f44dc58241176a989cca77fe052644a7602d04853ae

witness hash:0 PUSHDATA(32)[1a1d2ebe5ead7c916b48e245c957aecb75136e860a214f01c1dedfc961e6f339]

witness hash encode str:00201a1d2ebe5ead7c916b48e245c957aecb75136e860a214f01c1dedfc961e6f339

signed transaction

01000000000101282f723b362a588f35fee66719c8d739779942b3401995e8e7b3b1f062188c390000000000ffffffff01c8af0000000000002200201a1d2ebe5ead7c916b48e245c957aecb75136e860a214f01c1dedfc961e6f3390400483045022100d6373e87fcebb273c08496e042856acf8068c8685ab3f387151caffb957a828802206ee1488853578b58bdeaba3d47470e2bf58d5a3592b610e505fb31c6cc0f1e780147304402202e9b5c156fef699d9d1c60a22be863a4eb08f01fe86592ade3847d7e7ff9d6b9022077557ce221915b3e2b7c995ba994737f7214a68a0accf6ebb4a259224bc778d601695221037a5929bacc6251ace6fb688c7de760b047f03ef1d23f86bbbf61c152c16a44092102764c145abc62bf1c3786136c7020b4cef227102f458aa607afc6afda7b578ce62102f06485529af46c93b4bd6ab68f44dc58241176a989cca77fe052644a7602d04853ae00000000

the decode uncooked transaction

{
"txid": "45bb61b82eb70f8d1d52edde904b3402d677910ffdcb987264ec58b44eac525a",
"hash": "4b818b6745f45fdd79f0f54222206ee35de27eb103b8974046e6f6b8a323d2b4",
"model": 1,
"dimension": 349,
"vsize": 158,
"weight": 631,
"locktime": 0,
"vin": [
{
"txid": "398c1862f0b1b3e7e8951940b342997739d7c81967e6fe358f582a363b722f28",
"vout": 0,
"scriptSig": {
"asm": "",
"hex": ""
},
"txinwitness": [
"",
"3045022100d6373e87fcebb273c08496e042856acf8068c8685ab3f387151caffb957a828802206ee1488853578b58bdeaba3d47470e2bf58d5a3592b610e505fb31c6cc0f1e7801",
"304402202e9b5c156fef699d9d1c60a22be863a4eb08f01fe86592ade3847d7e7ff9d6b9022077557ce221915b3e2b7c995ba994737f7214a68a0accf6ebb4a259224bc778d601",
"5221037a5929bacc6251ace6fb688c7de760b047f03ef1d23f86bbbf61c152c16a44092102764c145abc62bf1c3786136c7020b4cef227102f458aa607afc6afda7b578ce62102f06485529af46c93b4bd6ab68f44dc58241176a989cca77fe052644a7602d04853ae"
],
"sequence": 4294967295
}
],
"vout": [
{
"value": 0.00045000,
"n": 0,
"scriptPubKey": {
"asm": "0 1a1d2ebe5ead7c916b48e245c957aecb75136e860a214f01c1dedfc961e6f339",
"hex": "00201a1d2ebe5ead7c916b48e245c957aecb75136e860a214f01c1dedfc961e6f339",
"reqSigs": 1,
"type": "witness_v0_scripthash",
"addresses": [
"tb1qrgwja0j7447fz66gufzuj4awed63xm5xpgs57qwpmm0ujc0x7vusdrjmw6"
]
}
}
]
}

the signal code

public void signal() {
NetworkParameters params = TestNet3Params.get();
Coin charge = Coin.SATOSHI.occasions(5000L);
Coin fundAmount = Coin.SATOSHI.occasions(50000L);

Record<ECKey> ecKeyList = Arrays.asList(
    DumpedPrivateKey.fromBase58(params, "cUkNoCzNXMXzN4JhYYbgiWAaKQEwfgUAzW2kogRNhUqGaiZ2AdUh").getKey(),
    DumpedPrivateKey.fromBase58(params, "cUpdkS6ekPkQj1RJWtjbLbYyDwszb3nEBbRkeRf9QHVkBBijEdgv").getKey(),
    DumpedPrivateKey.fromBase58(params, "cU4tWJk3BGymoJgbGbxNA6NJapTwrbfWWaPsz1bCZBzkoeszb4ML").getKey()
);

Record<String> inTxidList = Arrays.asList(
    "398c1862f0b1b3e7e8951940b342997739d7c81967e6fe358f582a363b722f28"
);

Record<Integer> inTxIndexList = Arrays.asList(
    0
);

String redeemScriptStr = "5221037a5929bacc6251ace6fb688c7de760b047f03ef1d23f86bbbf61c152c16a44092102764c145abc62bf1c3786136c7020b4cef227102f458aa607afc6afda7b578ce62102f06485529af46c93b4bd6ab68f44dc58241176a989cca77fe052644a7602d04853ae";

Script script = new Script(Utils.HEX.decode(redeemScriptStr));
Script p2wshScript = ScriptBuilder.createP2WSHOutputScript(script);

Transaction tx = new Transaction(params);
for (int i = 0; i < inTxidList.dimension(); i++) {
    TransactionWitness witness = new TransactionWitness(3);

    tx.addInput(Sha256Hash.wrap(inTxidList.get(i)), inTxIndexList.get(i), new Script(new byte[0]));

    Sha256Hash sigHash = tx.hashForWitnessSignature(i, p2wshScript, fundAmount, Transaction.SigHash.ALL, false);

    for (int j = 1; j < ecKeyList.dimension(); j++) {
        ECKey.ECDSASignature sig = ecKeyList.get(j).signal(sigHash);
        TransactionSignature txSig = new TransactionSignature(sig, Transaction.SigHash.ALL, false);

        witness.setPush(j, txSig.encodeToBitcoin());
    }
    witness.setPush(ecKeyList.dimension(), script.getProgram());

    tx.getInput(i).setWitness(witness);
}

Tackle sendTo = Tackle.fromString(params, "tb1qrgwja0j7447fz66gufzuj4awed63xm5xpgs57qwpmm0ujc0x7vusdrjmw6");
Coin outAmount = fundAmount.minus(charge);
Script outPkScript = ScriptBuilder.createOutputScript(sendTo);
tx.addOutput(outAmount, outPkScript);

log.data("signed tx:{}",Utils.HEX.encode(tx.bitcoinSerialize()));
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles