Author

Topic: Locked topic: Bitcoin Time lock question (Read 128 times)

copper member
Activity: 821
Merit: 1992
February 11, 2023, 06:16:37 AM
#5
Quote
Have you tried using signrawtransactionwithkey command? It can take in private key and the redeem (witness) script as arguments and sign the given transaction. I believe it should work.
It almost works. Almost, because locktime is not satisfied for some reason.

Code:
signrawtransactionwithkey "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20000000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000" "[\"cUhWuApMfhVaGdweY1W2kEuwnjTyoJ9jxQ6vFwCuP3TuZngZXKQP\"]" "[{\"txid\":\"f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14\",\"vout\":0,\"scriptPubKey\":\"a9141965f9b5556eae3bad2644044075541f13809dec87\",\"redeemScript\":\"0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac\",\"amount\":1.00000000}]"
{
  "hex": "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf2000000002b2a0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0acfdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000",
  "complete": false,
  "errors": [
    {
      "txid": "f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "2a0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac",
      "sequence": 4294967293,
      "error": "Locktime requirement not satisfied"
    }
  ]
}
signrawtransactionwithkey "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20100000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000" "[\"cUhWuApMfhVaGdweY1W2kEuwnjTyoJ9jxQ6vFwCuP3TuZngZXKQP\"]" "[{\"txid\":\"f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14\",\"vout\":1,\"scriptPubKey\":\"00202896005bb01874a711cb9779dc0e244e5fb19d03cb9da4837a6949599e8f55b3\",\"witnessScript\":\"0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac\",\"amount\":1.00000000}]"
{
  "hex": "0200000000010114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20100000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d012a0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac00000000",
  "complete": false,
  "errors": [
    {
      "txid": "f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14",
      "vout": 1,
      "witness": [
        "0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac"
      ],
      "scriptSig": "",
      "sequence": 4294967293,
      "error": "Locktime requirement not satisfied"
    }
  ]
}
signrawtransactionwithkey "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20200000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000" "[\"cUhWuApMfhVaGdweY1W2kEuwnjTyoJ9jxQ6vFwCuP3TuZngZXKQP\"]" "[{\"txid\":\"f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14\",\"vout\":2,\"scriptPubKey\":\"a914eda9c6593e1b7fa5524f561198b4a7468d29dad187\",\"redeemScript\":\"0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac\",\"witnessScript\":\"00202896005bb01874a711cb9779dc0e244e5fb19d03cb9da4837a6949599e8f55b3\",\"amount\":1.00000000}]"
redeemScript does not correspond to witnessScript (code -8)

Quote
The 3 transactions you posted here at the end are all the same without any signature or witness.
There are different inputs selected.
legendary
Activity: 3472
Merit: 10611
February 11, 2023, 05:27:18 AM
#4
As we can see, signing it directly won't work. We have watch-only addresses, so even if we have our private key, then still we need to pass the script that is behind each of those addresses, because it is not stored anywhere in the wallet.
However, we can try any other tool outside of Bitcoin Core,
Have you tried using signrawtransactionwithkey command? It can take in private key and the redeem (witness) script as arguments and sign the given transaction. I believe it should work.

sign those transactions, and then check if they will be broadcasted successfully by sendrawtransaction
The 3 transactions you posted here at the end are all the same without any signature or witness.
copper member
Activity: 821
Merit: 1992
February 11, 2023, 04:42:15 AM
#3
Quote
the only existing tool that I know of and OP was talking about is coinb.in and that only uses P2SH
You can always use Bitcoin Core, run it even offline if you don't want to download the chain, and then it can generate any type of address.

Code:
dumpprivkey bcrt1qy6jt5w2pv6ydqryts9vn7ut3g8cf3ygaxp4xae
cUhWuApMfhVaGdweY1W2kEuwnjTyoJ9jxQ6vFwCuP3TuZngZXKQP
getaddressinfo bcrt1qy6jt5w2pv6ydqryts9vn7ut3g8cf3ygaxp4xae
{
  ...
  "pubkey": "032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0",
  ...
}
Let's make it 2023-02-11 at 00:00, just to make sure it is now valid: https://duckduckgo.com/?q=unixtime+1676073600&ia=answer
Code:
Time (1676073600) to hex in little-endian: 0x80dae663
Push to stack with its size: 0x0480dae663
Add OP_CHECKLOCKTIMEVERIFY: 0xb1
Add OP_DROP: 0x75
Push public key to the stack with its size: 0x21032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0
Add OP_CHECKSIG: 0xac
Result:
Code:
decodescript 0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac
{
  "asm": "1676073600 OP_CHECKLOCKTIMEVERIFY OP_DROP 032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0 OP_CHECKSIG",
  "desc": "raw(0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac)#t4yrcshe",
  "type": "nonstandard",
  "p2sh": "2MuZX3TRME2pre1xu54X2iZ8a4gyMYErt8u",
  "segwit": {
    "asm": "0 2896005bb01874a711cb9779dc0e244e5fb19d03cb9da4837a6949599e8f55b3",
    "desc": "addr(bcrt1q9ztqqkasrp62wywtjauacr3yfe0mr8greww6fqm6d9y4n8502kesv2pg4y)#u33kx8h4",
    "hex": "00202896005bb01874a711cb9779dc0e244e5fb19d03cb9da4837a6949599e8f55b3",
    "address": "bcrt1q9ztqqkasrp62wywtjauacr3yfe0mr8greww6fqm6d9y4n8502kesv2pg4y",
    "type": "witness_v0_scripthash",
    "p2sh-segwit": "2NEusWubTsTxwziFY16xejNbTSktU1skFwX"
  }
}
The first warning is that our script type is marked as "nonstandard". But let's see if we can generate some regtest coins, send them to our address, and then get them with standardness rules enabled. First, generate some regtest coins:
Code:
generatetoaddress 101 bcrt1qy6jt5w2pv6ydqryts9vn7ut3g8cf3ygaxp4xae
And then, let's send them to all address types we reached from decodescript:
Code:
decoderawtransaction 0200000000010127b52425f2d9f5f33896a22c80d850334228cfd18923d76af7cf77bcb7d5372f0000000000fdffffff0400e1f5050000000017a9141965f9b5556eae3bad2644044075541f13809dec8700e1f505000000002200202896005bb01874a711cb9779dc0e244e5fb19d03cb9da4837a6949599e8f55b300e1f5050000000017a914eda9c6593e1b7fa5524f561198b4a7468d29dad187274e24180100000016001426a4ba39416688d00c8b81593f717141f098911d024730440220734377f733719a71177b1db84230ad7e69464240ce9a22abf461cc1f0bbaa62e0220679c67c5444919f207a59c9ae21ad010e0f37bbaa68eb8fdf01a7c705b395f340121032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b065000000
{
  "txid": "f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14",
  "hash": "3ce035f4649f379e96fb51d66afa6f286e12d75d0fe661531385c9b302a2e206",
  "version": 2,
  "size": 298,
  "vsize": 217,
  "weight": 865,
  "locktime": 101,
  "vin": [
    {
      "txid": "2f37d5b7bc77cff76ad72389d1cf28423350d8802ca29638f3f5d9f22524b527",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "30440220734377f733719a71177b1db84230ad7e69464240ce9a22abf461cc1f0bbaa62e0220679c67c5444919f207a59c9ae21ad010e0f37bbaa68eb8fdf01a7c705b395f3401",
        "032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0"
      ],
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 1.00000000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_HASH160 1965f9b5556eae3bad2644044075541f13809dec OP_EQUAL",
        "desc": "addr(2MuZX3TRME2pre1xu54X2iZ8a4gyMYErt8u)#xv98pchz",
        "hex": "a9141965f9b5556eae3bad2644044075541f13809dec87",
        "address": "2MuZX3TRME2pre1xu54X2iZ8a4gyMYErt8u",
        "type": "scripthash"
      }
    },
    {
      "value": 1.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "0 2896005bb01874a711cb9779dc0e244e5fb19d03cb9da4837a6949599e8f55b3",
        "desc": "addr(bcrt1q9ztqqkasrp62wywtjauacr3yfe0mr8greww6fqm6d9y4n8502kesv2pg4y)#u33kx8h4",
        "hex": "00202896005bb01874a711cb9779dc0e244e5fb19d03cb9da4837a6949599e8f55b3",
        "address": "bcrt1q9ztqqkasrp62wywtjauacr3yfe0mr8greww6fqm6d9y4n8502kesv2pg4y",
        "type": "witness_v0_scripthash"
      }
    },
    {
      "value": 1.00000000,
      "n": 2,
      "scriptPubKey": {
        "asm": "OP_HASH160 eda9c6593e1b7fa5524f561198b4a7468d29dad1 OP_EQUAL",
        "desc": "addr(2NEusWubTsTxwziFY16xejNbTSktU1skFwX)#vw0e5eea",
        "hex": "a914eda9c6593e1b7fa5524f561198b4a7468d29dad187",
        "address": "2NEusWubTsTxwziFY16xejNbTSktU1skFwX",
        "type": "scripthash"
      }
    },
    {
      "value": 46.99999783,
      "n": 3,
      "scriptPubKey": {
        "asm": "0 26a4ba39416688d00c8b81593f717141f098911d",
        "desc": "addr(bcrt1qy6jt5w2pv6ydqryts9vn7ut3g8cf3ygaxp4xae)#q5erljel",
        "hex": "001426a4ba39416688d00c8b81593f717141f098911d",
        "address": "bcrt1qy6jt5w2pv6ydqryts9vn7ut3g8cf3ygaxp4xae",
        "type": "witness_v0_keyhash"
      }
    }
  ]
}
Now, let's try to get our coins.
Code:
importaddress "2MuZX3TRME2pre1xu54X2iZ8a4gyMYErt8u"
importaddress "bcrt1q9ztqqkasrp62wywtjauacr3yfe0mr8greww6fqm6d9y4n8502kesv2pg4y"
importaddress "2NEusWubTsTxwziFY16xejNbTSktU1skFwX"
Generate some blocks, to make our transaction confirmed:
Code:
generatetoaddress 6 bcrt1qy6jt5w2pv6ydqryts9vn7ut3g8cf3ygaxp4xae
We can see our coins as watch-only, but we need some way to move them. So, we have to create a transaction for each address:
Code:
createrawtransaction "[{\"txid\":\"f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14\",\"vout\":0}]" "[{\"bcrt1qy6jt5w2pv6ydqryts9vn7ut3g8cf3ygaxp4xae\":0.99999000}]" 0 true
020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20000000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000
createrawtransaction "[{\"txid\":\"f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14\",\"vout\":1}]" "[{\"bcrt1qy6jt5w2pv6ydqryts9vn7ut3g8cf3ygaxp4xae\":0.99999000}]" 0 true
020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20100000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000
createrawtransaction "[{\"txid\":\"f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14\",\"vout\":2}]" "[{\"bcrt1qy6jt5w2pv6ydqryts9vn7ut3g8cf3ygaxp4xae\":0.99999000}]" 0 true
020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20200000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000
Then, the hardest part is to sign those transactions.
Code:
signrawtransactionwithwallet "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20000000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000" "[{\"txid\":\"f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14\",\"vout\":0,\"scriptPubKey\":\"a9141965f9b5556eae3bad2644044075541f13809dec87\",\"redeemScript\":\"0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac\",\"amount\":1.00000000}]"
{
  "hex": "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20000000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000",
  "complete": false,
  "errors": [
    {
      "txid": "f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967293,
      "error": "Unable to sign input, invalid stack size (possibly missing key)"
    }
  ]
}
signrawtransactionwithwallet "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20100000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000" "[{\"txid\":\"f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14\",\"vout\":1,\"scriptPubKey\":\"00202896005bb01874a711cb9779dc0e244e5fb19d03cb9da4837a6949599e8f55b3\",\"witnessScript\":\"0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac\",\"amount\":1.00000000}]"
{
  "hex": "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20100000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000",
  "complete": false,
  "errors": [
    {
      "txid": "f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14",
      "vout": 1,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967293,
      "error": "Witness program was passed an empty witness"
    }
  ]
}
signrawtransactionwithwallet "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20200000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000" "[{\"txid\":\"f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14\",\"vout\":2,\"scriptPubKey\":\"a914eda9c6593e1b7fa5524f561198b4a7468d29dad187\",\"redeemScript\":\"0480dae663b17521032d02e0fe6b071d74fefa64235ee6a3db46fc489443d00291538c0b6d2ec6d1b0ac\",\"witnessScript\":\"00202896005bb01874a711cb9779dc0e244e5fb19d03cb9da4837a6949599e8f55b3\",\"amount\":1.00000000}]"
{
  "hex": "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20200000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000",
  "complete": false,
  "errors": [
    {
      "txid": "f2ac7f0d8dedaa7062dc8f957ffc21684a42d85f4bfc0bdf06bbfd1efd82cb14",
      "vout": 2,
      "witness": [
      ],
      "scriptSig": "",
      "sequence": 4294967293,
      "error": "Unable to sign input, invalid stack size (possibly missing key)"
    }
  ]
}
As we can see, signing it directly won't work. We have watch-only addresses, so even if we have our private key, then still we need to pass the script that is behind each of those addresses, because it is not stored anywhere in the wallet.

However, we can try any other tool outside of Bitcoin Core, sign those transactions, and then check if they will be broadcasted successfully by sendrawtransaction. Let's see how it works without signatures:
Code:
sendrawtransaction "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20000000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000"
bad-txns-nonstandard-inputs (code -26)
sendrawtransaction "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20100000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000"
non-mandatory-script-verify-flag (Witness program was passed an empty witness) (code -26)
sendrawtransaction "020000000114cb82fd1efdbb06df0bfc4b5fd8424a6821fc7f958fdc6270aaed8d0d7facf20200000000fdffffff0118ddf5050000000016001426a4ba39416688d00c8b81593f717141f098911d00000000"
bad-txns-nonstandard-inputs (code -26)
Then, by adding signatures and trying again, we should reach them in our regtest mempool. If not, then that means they are non-standard, and we cannot use them without contacting miners directly.
legendary
Activity: 3472
Merit: 10611
February 11, 2023, 12:34:22 AM
#2
The example I posted there is using P2SH because the only existing tool that I know of and OP was talking about is coinb.in and that only uses P2SH. Otherwise P2WSH is better since the fee will be slightly lower among other things. But in both cases the script is standard and will be relayed by all nodes.

The only case that is non-standard, if I'm not mistaken, is when you put the redeem script in your scriptpub instead. Otherwise one of the benefits of using script hash is to be able to use this type of uncommon scripts and still be standard.
copper member
Activity: 821
Merit: 1992
February 10, 2023, 10:35:56 AM
#1
For some reason, this topic is locked: https://bitcointalksearch.org/topic/bitcoin-time-lock-question-5438853
If proposed solution will lead to some non-standard P2SH transaction, it can cause problems for non-mining users.

Quote
Now compute hash160 of this script, add the P2SH version byte and convert it to base58 with a checksum:
Code:
3HHEkX7dBBbs692nKJz5P6egkCazKRZxBt
Why P2SH? Is this standard or non-standard? As far as I know, the whole script under P2SH has to be standard. Usually I choose P2WSH (or even better, P2TR, because then you can always spend by key if you will be unable to do that by TapScript for any reason). Standardness rules can make it locked forever (unless you reach some support from miners).
Jump to: