0

I'm seeking help in redeeming a p2sh transaction using the standard tools from bitcoin core, e.g., bitcoin-cli or using directly the RPC commands via curl would also be fine.

Creating the P2SH address

locking funds in a p2sh address is not the problem I assume, e.g., I handled it that way:

intput

bitcoin-cli -regtest decodescript "935787"

output

{
  "asm": "OP_ADD 7 OP_EQUAL",
  "type": "nonstandard",
  "p2sh": "2N2Mn4F9tUVy9cRTzBQhQTiMpi2Kpwzkyn6"
}

in order to redeem that script I would need two numbers equaling 7 right, e.g., 1 6

Locking some funding in a p2sh

so let's spend some funds into the p2sh

input

bitcoin-cli -regtest sendtoaddress 2N2Mn4F9tUVy9cRTzBQhQTiMpi2Kpwzkyn6 40

output

5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca```

here is the raw transaction

input

bitcoin-cli --regtest getrawtransaction 5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca

output

0200000001cef241d611112f7f9c98a8e825eb801dad923767126bee7c9ec190950c06ba24000000004847304402202d25bc67043c3cc2ec5fbf6b0bfe7e49b0a5f29e3891f5da005f3350188bc79502202ca014de3b60ede7f3b3bf2080ed33a06c9cb39f588178907f48b09caa0b1bca01feffffff0200286bee0000000017a91463f665a76eef10e84662c82bec9aff641edf42ec8750bb9a3b0000000017a914c12b3404c4e13900c5bfefc886533d7eb59524228766000000

or decoded it is:

{
  "txid": "5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca",
  "hash": "5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca",
  "version": 2,
  "size": 187,
  "vsize": 187,
  "locktime": 102,
  "vin": [
    {
      "txid": "24ba060c9590c19e7cee6b12673792ad1d80eb25e8a8989c7f2f1111d641f2ce",
      "vout": 0,
      "scriptSig": {
        "asm": "304402202d25bc67043c3cc2ec5fbf6b0bfe7e49b0a5f29e3891f5da005f3350188bc79502202ca014de3b60ede7f3b3bf2080ed33a06c9cb39f588178907f48b09caa0b1bca[ALL]",
        "hex": "47304402202d25bc67043c3cc2ec5fbf6b0bfe7e49b0a5f29e3891f5da005f3350188bc79502202ca014de3b60ede7f3b3bf2080ed33a06c9cb39f588178907f48b09caa0b1bca01"
      },
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 40.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 63f665a76eef10e84662c82bec9aff641edf42ec OP_EQUAL",
        "hex": "a91463f665a76eef10e84662c82bec9aff641edf42ec87",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2N2Mn4F9tUVy9cRTzBQhQTiMpi2Kpwzkyn6"
        ]
      }
    },
    {
      "value": 9.99996240,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_HASH160 c12b3404c4e13900c5bfefc886533d7eb5952422 OP_EQUAL",
        "hex": "a914c12b3404c4e13900c5bfefc886533d7eb595242287",
        "reqSigs": 1,
        "type": "scripthash",
        "addresses": [
          "2NArcA7oJfBkH6ZWBfh2TaTQkvKYMoK9xhd"
        ]
      }
    }
  ]
}

Creating a new UTXO spending from that p2sh transaction

now I want to redeem that tx, so first create a raw transaction with the old tx as input

input

bitcoin-cli -regtest createrawtransaction "[{\"txid\":\"5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca\",\"vout\":0}]" "{\"2NACSKxqUhLRHTwaSN3xaJpti6BEPyDFSUJ\":39}"

output

0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000000ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000

Signing that UTXO to redeem it

and I figure in the next step I assume I'd have to sign the transaction using the redeemScript, i.e., the redeemScript is:

515603935787 which is the hex form of: 1 6 PUSH 935787

I tried to sign the tx using:

input

bitcoin-cli -regtest signrawtransaction "0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000000ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000" "[{\"txid\":\"5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca\",\"vout\":0,\"scriptPubKey\":\"a91463f665a76eef10e84662c82bec9aff641edf42ec87\",\"redeemscript\":\"515603935787\"}]"

Output

{
  "hex": "0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000000ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000",
  "complete": false,
  "errors": [
    {
      "txid": "5589b316dc210174d988bfab333f93101cea40f5914a1ab833a9bbe56faf55ca",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967295,
      "error": "Unable to sign input, invalid stack size (possibly missing key)"
    }
  ]
}

and that's where I don't know any further. I always get the error Unable to sign input, invalid stack size (possibly missing key) any idea what I am missing?

kind regards, Jagoda

note: I already had a look at various links here on stackexchange/stackoverflow and the official developer wiki but couldn't find an easy to follow tutorial. Tutorials I had a look at which might be useful for future references:

  • i'm in the exact same boat as you (i ended up executing the same commands you did and getting the same result). how did you end up solving for it? – tipu Nov 27 '18 at 20:36
2

You do not need to sign transaction because your redeemScript "OP_ADD 7 OP_EQUAL" does not contain OP_CHECKSIG* operations

Just fill the scriptSig

0200000001ca55af6fe5bba933b81a4a91f540ea1c10933f33abbf88d9740121dc16b389550000000006515603935787ffffffff01004775e80000000017a914b9f330d64c88295017c651d2117785f212cb59938700000000

  • that would work, but is that the preferred way of doing so, or differently asked, is there a way using bitcoin-cli to fill the scriptSig? – jagodacarlito Mar 21 '18 at 6:12
  • Bitcoin Core can't sign arbitrary scripts. You need to fill in the data yourself. – Pieter Wuille Apr 24 '18 at 17:30
2

You cannot use Bitcoin Core to create your transaction because it does not know what to do with non-standard inputs. There is no need to use signrawtransaction because you are not signing anything. In order to make your transaction spendable, you will need to do it manually by inserting the scriptSig that you figured out yourself.

0

That produces scary errors and says that it's not complete. This is all correct. You can see that the signature has been partially successfully because the hex has gotten longer. Though the transaction has been partially signed, it's not done because it needs more signatures.

M-of-N vs N-of-N: Obviously, if you have an n-of-n signature (like the 2-of-2 multisignature), then everyone has to sign, but if you have a m-of-n multisignature where m < n, then the signature will be complete when only some (m) of the signers have signed.

Your Answer

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

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