Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: GCath on August 18, 2017, 01:56:34 PM



Title: Signing raw transactions with custom scriptPubKey/scriptSig
Post by: GCath on August 18, 2017, 01:56:34 PM
Hi everyone !

I'm starting to experience with Bitcoin Core and I got really interested with Scripts. What I wanted to do is to use a custom puzzle in addition to the common scriptPubKey script, (i.e. need a solution + a private key to redeem the output).

I've managed so far to send a transaction on the testnet network with a 5+x=10 puzzle and my usual scriptPubKey script:

Code:
{
  "txid": "033ca8bdb4f8d5944ef445719b32162f6df9beff3211a769eb0a2bceab2e9583",
  "hash": "033ca8bdb4f8d5944ef445719b32162f6df9beff3211a769eb0a2bceab2e9583",
  "size": 94,
  "vsize": 94,
  "version": 2,
  "locktime": 0,
  "vin": [
    {
      "txid": "b888efa3e07ae14ff758083be2abbb15e8126d5970341744c231f9c520d2ab78",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.00004000,
      "n": 0,
      "scriptPubKey": {
        "asm": "5 OP_ADD 10 OP_NUMEQUAL OP_DROP OP_DUP OP_HASH160 43e497c40f933af83d8a3fc6c92e92f26117a8af OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "4c0105934c010a9c7576a91443e497c40f933af83d8a3fc6c92e92f26117a8af88ac",
        "type": "nonstandard"
      }
    }
  ]
}

So I'm trying to redeem this transaction with create/sign rawtransactions, but it seems I can't sign it even if I include the "5" solution:

Code:
{
  "hex": "02000000010ce773f9e7d1c35485b0440a9982b652d08503cd666f24c753534717e0da92ee000000000155ffffffff01b80b0000000000001976a91443e497c40f933af83d8a3fc6c92e92f26117a8af88ac00000000",
  "complete": false,
  "errors": [
    {
      "txid": "ee92dae017475353c7246f66cd0385d052b682990a44b08554c3d1e7f973e70c",
      "vout": 0,
      "scriptSig": "55",
      "sequence": 4294967295,
      "error": "Data push larger than necessary"
    }
  ]
}

I looked up for this error message but even if I try to change the redeem script to either OP_5 or 5 with OP_PUSHDATA1 it doesn't work...

I was wondering if any of you had an idea on how to do it ? :/ I think the best would be to manually sign the transaction but I really don't want to use librairies ><

Thank you for your time!


Title: Re: Signing raw transactions with custom scriptPubKey/scriptSig
Post by: achow101 on August 18, 2017, 05:38:03 PM
Your scriptPubKey is wrong. You are using pushdatas to push the hex numbers 5 and 10 to stack. To push just 1 byte, you don't need to use OP_PUSHDATA1. You should only be using OP_PUSHDATA1 when you have more than 75 bytes of data to push. opcodes 1 through 75 (0x01 - 0x4b) just mean "push that number of bytes to the stack".

Also, Bitcoin Core will not be able to sign your transaction because it does not know what kind of script your scriptPubKey is so it does not know about what needs to be done in order to sign it properly.


Title: Re: Signing raw transactions with custom scriptPubKey/scriptSig
Post by: GCath on August 21, 2017, 08:26:32 AM
Alright thank you for your answer. I will modify the scriptPubkey accordingly, but then do you have any idea how I should sign the transaction ?

No choice but "by hand", right ?


Title: Re: Signing raw transactions with custom scriptPubKey/scriptSig
Post by: achow101 on August 21, 2017, 03:32:52 PM
Alright thank you for your answer. I will modify the scriptPubkey accordingly, but then do you have any idea how I should sign the transaction ?

No choice but "by hand", right ?
You could modify Core so that it knows what kind of scriptPubKey that is so it can sign for it.