0

enter image description here

I'm trying to follow the below transaction example by magic eden and extend it to support multiple buyers and seller (in red). However I am having difficulties when I add more than one signature from another party (with one seller it broadcasts okay). The transaction builds and signs fine but when I try to broadcast it to the network it results in the error mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation). Using native segwit addresses for this (no-tr).

What am I missing or doing wrong?

Using the bitcoinjs library here is what I have so far (only the red):

Seller signing:

let psbt = new bitcoin.Psbt({ network });

const [ordinalUtxoTxId, ordinalUtxoVout] = ordinalOutput.split(":");
const tx = bitcoin.Transaction.fromHex(await getTxHexById(ordinalUtxoTxId));

try {
    tx.setWitness(parseInt(ordinalUtxoVout), []);
} catch {}

const input = {
  hash: ordinalUtxoTxId,
  index: parseInt(ordinalUtxoVout),
  nonWitnessUtxo: tx.toBuffer(),
  witnessUtxo: tx.outs[ordinalUtxoVout],
  sighashType:
    bitcoin.Transaction.SIGHASH_SINGLE |
    bitcoin.Transaction.SIGHASH_ANYONECANPAY,
};

psbt.addInput(input);

psbt.addOutput({
  address: paymentAddress,
  value: price,
});

Buyer Signing (ignoring padding inputs and outputs):

// Add inscriptions inputs and outputs
for (const signedPsbt of sellerSignedPsbts) {
    // Add inscription output
    psbt.addOutput({
        address: receiverAddress,
        value: signedPsbt.data.inputs[0].witnessUtxo.value,
    });

    // Add payer signed input
    psbt.addInput({
        ...signedPsbt.data.globalMap.unsignedTx.tx.ins[0],
        // ...signedPsbt.data.inputs[0],
        witnessUtxo: signedPsbt.data.inputs[0].witnessUtxo,
        // nonWitnessUtxo: signedPsbt.data.inputs[0].nonWitnessUtxo,
        // finalScriptWitness: signedPsbt.data.inputs[0].finalScriptWitness,
    });

    input++;
}

// Add seller payment outputs for payee
for (const signedPsbt of sellerSignedPsbts) {
    // Add payer output
    psbt.addOutput({
        ...signedPsbt.data.globalMap.unsignedTx.tx.outs[0],
    });
}

Merge seller and buyer signed psbts:

const buyerSignedPsbt = bitcoin.Psbt.fromBase64(signedBuyingPSBTBase64);

for (let index = 0; index < signedListingsPSBTBase64.length; index++) {
    const sellerSignedPsbt = bitcoin.Psbt.fromBase64(signedListingsPSBTBase64[index]);

    buyerSignedPsbt.data.globalMap.unsignedTx.tx.ins[BUYING_PSBT_SELLER_SIGNATURE_INDEX + index] = sellerSignedPsbt.data.globalMap.unsignedTx.tx.ins[0];
    buyerSignedPsbt.data.inputs[BUYING_PSBT_SELLER_SIGNATURE_INDEX + index] = sellerSignedPsbt.data.inputs[0];
}

// broadcast buyerSignedPsbt

Regtest Base64 psbt

Seller Signed 1 cHNidP8BAFICAAAAASOmBfmvfvsLtR13NFmTe7a1PqExPjrG3n11nxrkWj8tAQAAAAD/////ATBuFgAAAAAAFgAUWFy3jcqHhb9Q8bNzCelM6HJWOowAAAAAAAEBH4gTAAAAAAAAFgAUWFy3jcqHhb9Q8bNzCelM6HJWOowBCGwCSDBFAiEAzLuOeIyXt/12KDkqD+mGRj105SHJHC1HdshaQ0fg0ocCID2ZxLyTs4NLZvynw5dKIrXetdQv+J0S9KrMJuznDJFRgyEDYTg80B9Vdeb/4anKg9DSL98+B2HsIPk6jUQNJEKFadEAAA==

Seller Signed 2 +PSZaCbgm2ZSnbSI9pFk/2DFLekqsj91nGUx2AQAAAAD/////ATBuFgAAAAAAFgAUWFy3jcqHhb9Q8bNzCelM6HJWOowAAAAAAAEBH4gTAAAAAAAAFgAUWFy3jcqHhb9Q8bNzCelM6HJWOowBCGsCRzBEAiA686mylIphxLrBDMStAv3a5srPBlXkSbsFMtUPIS/04QIgBooAkEWVhDcpJdNToJpO8GmF+Tv9bTqxNLjKbBCxc0ODIQNhODzQH1V15v/hqcqD0NIv3z4HYewg+TqNRA0kQoVp0QAA

Buyer Signed cHNidP8BAP0XAgIAAAAGIrZxkCRmsjVZq0pfHSgXAETZMLww/jncfehoZog1ByMEAAAAAP////8itnGQJGayNVmrSl8dKBcARNkwvDD+Odx96GhmiDUHIwUAAAAA/////+GmgIf+PSZaCbgm2ZSnbSI9pFk/2DFLekqsj91nGUx2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n5opkEDBI+rbJREVPOk0AiBZJsZOb9wXf3nIupypuDlGUhviFN8XbkVF5yykkc0AuAEhA7onFywAMWyVGqpDvyvUhf4rsOaCGFZ2G0nivcLZA+zZAAAAAAEIbAJIMEUCIQCV6RHCRNTT6E7hwdSgFCnP4+WTttUjXuROzgqQWUIxGAIgZ4ZUuwi+0l9KzR1898UCY1Qz5rd2Palbe57SB5plh2wBIQIEmAetj8hmf6nSZTW0I7A/Y7y06tZjhgi31ytXlfBlIwAAAAAAAAAAAAA=

Merged TX (Giving error) 0200000000010622b671902466b23559ab4a5f1d28170044d930bc30fe39dc7de86866883507230400000000ffffffff22b671902466b23559ab4a5f1d28170044d930bc30fe39dc7de86866883507230500000000ffffffff23a605f9af7efb0bb51d773459937bb6b53ea1313e3ac6de7d759f1ae45a3f2d0100000000ffffffffe1a68087fe3d265a09b826d994a76d223da4593fd8314b7a4aac8fdd67194c760100000000ffffffffacf181ceea3dae5d029e45bf945c29c64182f28136e67926466d9d42c3c239710600000000ffffffff0d83286e5ec76fad55b96ce49f6585977ad7d07181511efb475122dd153123140200000000ffffffff097017000000000000160014af4f1135eec1e4c147655026fd0bb48d01ca647c8813000000000000160014af4f1135eec1e4c147655026fd0bb48d01ca647c8813000000000000160014af4f1135eec1e4c147655026fd0bb48d01ca647c306e160000000000160014585cb78dca8785bf50f1b37309e94ce872563a8c306e160000000000160014585cb78dca8785bf50f1b37309e94ce872563a8c90410100000000001600141f3307885b7a03192e660fbc5be85c376acb33eeb80b000000000000160014af4f1135eec1e4c147655026fd0bb48d01ca647cb80b000000000000160014af4f1135eec1e4c147655026fd0bb48d01ca647c268b0f0000000000160014af4f1135eec1e4c147655026fd0bb48d01ca647c024730440220115b86808796fa77b1c293d462d42ed34277f7c3c32ef619ba6cdaaf73b8bdad0220435877b881d91b79e6f8d51030c93b6de34238eb3a56162605c43048a7463522012102049807ad8fc8667fa9d26535b423b03f63bcb4ead6638608b7d72b5795f06523024730440220433648280f8717e5a38b61b127454ec927846ffa100372ff3c9b6546f98331d202206e8272b0c23a9fcc7ae042a925559ec6fa66d0c05c197132b04ab27e0e84b1f5012102049807ad8fc8667fa9d26535b423b03f63bcb4ead6638608b7d72b5795f0652302483045022100ccbb8e788c97b7fd7628392a0fe986463d74e521c91c2d4776c85a4347e0d28702203d99c4bc93b3834b66fca7c3974a22b5deb5d42ff89d12f4aacc26ece70c915183210361383cd01f5575e6ffe1a9ca83d0d22fdf3e0761ec20f93a8d440d24428569d10247304402203af3a9b2948a61c4bac10cc4ad02fddae6cacf0655e449bb0532d50f212ff4e10220068a0090459584372925d353a09a4ef06985f93bfd6d3ab134b8ca6c10b1734383210361383cd01f5575e6ffe1a9ca83d0d22fdf3e0761ec20f93a8d440d24428569d10248304502210097ffb975eccd16401ec311688af93f60d534f9fb74a11695dea0ceebd1b20ad802203e3da5fa00bd40bb773b3aded2269e353e29221275ae72c99436c22afe8de777012102049807ad8fc8667fa9d26535b423b03f63bcb4ead6638608b7d72b5795f065230247304402207328307bea68a39942bbcb459d0ed201407c93a147868fc187dad1b95db5cbdb02205df5f94a1f2713f5b14c060eb7f00a724a63e0ff6f1df081ff6aee7afb892f14012102049807ad8fc8667fa9d26535b423b03f63bcb4ead6638608b7d72b5795f0652300000000

9
  • Can you also share the transaction itself? Commented Feb 1 at 10:02
  • @VojtěchStrnad Sorry for the delay, I have updated the post with regtest psbt txs. Any assistance is appreciated. Commented Feb 21 at 23:51
  • For completeness, can you also share the final serialized transaction that produces the error? Commented Feb 22 at 0:09
  • @VojtěchStrnad Added the final merged transaction giving the error. Commented Feb 22 at 0:17
  • The PSBT you've added doesn't seem to be finalized. Can you post the actual final raw transaction that Bitcoin Core error on when you pass it so sendrawtransaction? Commented Feb 22 at 0:44

1 Answer 1

0

Solution:

Figured it out, basically everything was correct except for the padding of the inputs to make the seller psbt (1 input and 1 output) line up in the same position.

For example:

Input 1 - 3000   Output 1 - 9000
Input 2 - 3000   Output 2 - Input 4
Input 3 - 3000   Output 3 - Input 5
Input 4 - 10000  Output 4 - To Seller 1 (Seller PSBT 1, need to be inline with Input 4) 
Input 5 - 10000  Output 5 - To Seller 2 (Seller PSBT 2, need to be inline with Input 5)
Input 6 - Price  Output 6 - Change

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.