0

Guide link: https://comit.network/blog/2018/06/23/connect-all-the-blockchains/

For context I'm following a guide I found online about how to create a HTLC (Hash-time lock contract) and have it work between the Bitcoin-Ethereum network. I've followed the guide up until the point of:

More specifically, Bob sends a transaction with the following witness:

3045022100d780139514f39ed943179e4638a519101bae875ec1220b226002bcbcb147830b0220273d1efb1514a77ee3dd4adee0e896b7e76be56c6d8e73470ae9bd91c91d700c01
0344f8f459494f74ebb87464de9b74cdba3709692df4661159857988966f94262f
ec9e9fb3c669b2354ea026ab3da82968a2e7ab9398d5cbed4e78e47246f2423e
01
63a82091d6a24697ed31932537ae598d3de3131e1fcd0641b9ac4be7afcb376386d71e8876a9149f4a0cf348b478336cb1d87ea4c8313a7ca3de1967029000b27576a91465252e57f727a27f32c77098e14d88d8dbec01816888ac
The first two lines are his signature and public key. The third line is the secret followed by 01 to execute the correct if branch in the HTLC.

The trade is now complete: Alice received the ETH funds and Bob received the BTC funds.

I understand what a witness script is, however I don't understand how to append the metadata along with the witness script. Isn't the witness script just the redeem script alone, which means any additional information like the signature, pubkey, and secret would cause the "witness script" hash to no longer match up with the scriptPubkey? Also what exactly is a signature and where do I get it? I understand signing messages, but I've never heard of a full on signature that you can extract from a wallet/private key to put as meta data for a P2WSH.

These are additional things you may need in order to help answer my question: This is from the Bitcoin testnet anyways so I don't care about leaking any information.

Redeem Script Raw:

OP_IF
  OP_SHA256 517652066604fdee5acebc8a6be53254256bf87a8c77684f248ccdcce2b475a4
  OP_EQUALVERIFY OP_DUP OP_HASH160 16e38bbd921c2d0be7a8eb2f06e042146fdd0102
OP_ELSE
  9000 OP_CHECKSEQUENCEVERIFY OP_DROP
  OP_DUP OP_HASH160 0e3a1efcd44db4d49e20293a15b06bda27922172
OP_ENDIF
OP_EQUALVERIFY OP_CHECKSIG

Bob and Alice information:

Alice Wallet: tb1qpcapalx5fk6df83q9yaptvrtmgneygtjeham9x
Alice Public key: 032bb47c8aad2dde087a9574a8abd61b7bd1a43a10c8327bd20e78667c6e496dcf
Alice Hashed Public Key: 0e3a1efcd44db4d49e20293a15b06bda27922172
Alice Private Key: cTMsxWkkm2mKhzJzB6FgzvCKobzZMdtwEW6P21hzGXRjRsmb9dq1

Bob Wallet: tb1qzm3ch0vjrsksheagavhsdczzz3ha6qgzntf5wl
Bob Public key : 0309cb59b943eb81fbfd1f8fe1372f8096403a1e9b7b94432321d23bb9710ade1e
Bob Hashed Public Key: 16e38bbd921c2d0be7a8eb2f06e042146fdd0102
Bob Priv Key: cRkYpyAyCqEDVpDjxPajT4bnAkpYTLhNajZdzHENoPyHcGq3zojT

secret = c44ec7fb5a84ebbb3e2d253f7852f39b5e7ea48917f46c9eb3ba1fcce19d529f

Redeem Script in hex format:

63a820517652066604fdee5acebc8a6be53254256bf87a8c77684f248ccdcce2b475a48876a91416e38bbd921c2d0be7a8eb2f06e042146fdd010267022823b27576a9140e3a1efcd44db4d49e20293a15b06bda279221726888ac

Transaction information:

**createrawtransaction results in this hexsig**
0200000001a27f384d32192d50420acaffaeb912a8dee553c07cd1027534e4376220ab52270000000000ffffffff01401f00000000000016001416e38bbd921c2d0be7a8eb2f06e042146fdd010200000000

**what I tried using to sign the raw transaction**
signrawtransactionwithkey'0200000001a27f384d32192d50420acaffaeb912a8dee553c07cd1027534e4376220ab52270000000000ffffffff01401f00000000000016001416e38bbd921c2d0be7a8eb2f06e042146fdd010200000000' '["cRkYpyAyCqEDVpDjxPajT4bnAkpYTLhNajZdzHENoPyHcGq3zojT"]' '[{"txid": "2752ab206237e4347502d17cc053e5dea812b9aeffca0a42502d19324d387fa2","vout": 0,"amount":0.00009000,"scriptPubKey":"0020d70b1e70eb32ab1f22da3273150469d48b97fd9f50e1c462792fb4c1383cb37d","witnessScript":"0309cb59b943eb81fbfd1f8fe1372f8096403a1e9b7b94432321d23bb9710ade1ec44ec7fb5a84ebbb3e2d253f7852f39b5e7ea48917f46c9eb3ba1fcce19d529f0163a820517652066604fdee5acebc8a6be53254256bf87a8c77684f248ccdcce2b475a48876a91416e38bbd921c2d0be7a8eb2f06e042146fdd010267022823b27576a9140e3a1efcd44db4d49e20293a15b06bda279221726888ac"}]'

Now the problem occurs when I try signrawtransactionwithkey and try to include the pubkey and secret along with the redeemScript. I get the error saying

redeemScript/witnessScript does not match scriptPubKey (code -8)

If I try to signrawtransactionwithkey with the witnessScript parameter being ONLY the redeemScript it does go through but I get a different error. Also I want to point out that the guide told me that I NEED to include the signature, public key, and secret as part of the witnessScript so it makes no sense that I can't include them.

**command*
signrawtransactionwithkey '0200000001a27f384d32192d50420acaffaeb912a8dee553c07cd1027534e4376220ab52270000000000ffffffff01401f00000000000016001416e38bbd921c2d0be7a8eb2f06e042146fdd010200000000' '["cRkYpyAyCqEDVpDjxPajT4bnAkpYTLhNajZdzHENoPyHcGq3zojT"]' '[{"txid": "2752ab206237e4347502d17cc053e5dea812b9aeffca0a42502d19324d387fa2","vout": 0,"amount":0.00009000,"scriptPubKey":"0020d70b1e70eb32ab1f22da3273150469d48b97fd9f50e1c462792fb4c1383cb37d","witnessScript":"63a820517652066604fdee5acebc8a6be53254256bf87a8c77684f248ccdcce2b475a48876a91416e38bbd921c2d0be7a8eb2f06e042146fdd010267022823b27576a9140e3a1efcd44db4d49e20293a15b06bda279221726888ac"}]'

**result**
{
  "hex": "02000000000101a27f384d32192d50420acaffaeb912a8dee553c07cd1027534e4376220ab52270000000000ffffffff01401f00000000000016001416e38bbd921c2d0be7a8eb2f06e042146fdd0102015b63a820517652066604fdee5acebc8a6be53254256bf87a8c77684f248ccdcce2b475a48876a91416e38bbd921c2d0be7a8eb2f06e042146fdd010267022823b27576a9140e3a1efcd44db4d49e20293a15b06bda279221726888ac00000000",
  "complete": false,
  "errors": [
    {
      "txid": "2752ab206237e4347502d17cc053e5dea812b9aeffca0a42502d19324d387fa2",
      "vout": 0,
      "witness": [
        "63a820517652066604fdee5acebc8a6be53254256bf87a8c77684f248ccdcce2b475a48876a91416e38bbd921c2d0be7a8eb2f06e042146fdd010267022823b27576a9140e3a1efcd44db4d49e20293a15b06bda279221726888ac"
      ],
      "scriptSig": "",
      "sequence": 4294967295,
      "error": "Invalid OP_IF construction"
    }
  ]
}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.