Skip to content

InputPair's lack of a constructor seems to cause mistakes #583

@DanGould

Description

@DanGould

@kumulynja mentioned to me that

[in] the last step of broadcasting the payjoin transaction I get the following error:

BdkError.electrum(field0: Electrum server error: "sendrawtransaction RPC error -26: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)")

The proposal psbt is finalized when signing with the sender before broadcasting, and I think I am using the same signing options as in the current version, so not sure what to change there.

Turned out @kumulynja was passing empty lists to the psbt::Input's redeemScript and witnessScript fields, but should have been leaving them None to spend his P2WPKH Input. See the commented code below:

Image

I believe I recall @konstantinullrich having a similar problem in implementation.

I wonder if AddressType-specific constructors (e.g. InputPair::new_p2tr, InputPair::new_p2wpkh etc.) would have prevented this implementation error. It was tricky to hunt down what the problem even was since it only failed script verification.

To be explicit, I think their flutter (dart) implementation:

Future<InputPair> _inputPairFromUtxo(bdk.LocalUtxo utxo, bool isTestnet) async {
  final psbtin = PsbtInput(
    witnessUtxo: TxOut(
      value: utxo.txout.value,
      scriptPubkey: utxo.txout.scriptPubkey.bytes,
    ),
  );
  final txin = TxIn(
    previousOutput:
        OutPoint(txid: utxo.outpoint.txid, vout: utxo.outpoint.vout),
    scriptSig: await Script.newInstance(rawOutputScript: []),
    sequence: 0xFFFFFFFF,
    witness: [],
  );
  return InputPair.newInstance(txin, psbtin);
}

May prevent misuse if an imagined InputPair constructor were instead applied as

InputPair _inputPairFromUtxo(bdk.LocalUtxo utxo, bool isTestnet) {
  return InputPair.newP2wpkh(witnessUtxo: utxo.txout, previousOutput: utxo.outpoint);
}

and provided the other fields as defaults (perhaps with optional sequence), or further specified the necessary parameters to create a p2wpkh InputPair.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apienhancementNew feature or requestgood first issueDoes NOT mean "an LLM can do this." Please discuss the constraints and intended approach.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions