decodescript could infer miniscript from given script in “segwit” context #27007

issue instagibbs openend this issue on January 31, 2023
  1. instagibbs commented at 4:55 pm on January 31, 2023: member

    I was playing around with a probably-too-cute script for LN channel smart contract, and was looking for something to decide for me if miniscript can infer the structure of the script.

    f.e.

     0decodescript 82012088a914ffffffffffffffffffffffffffffffffffffffff8820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffad51b2
     1
     2{
     3  "asm": "OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 ffffffffffffffffffffffffffffffffffffffff OP_EQUALVERIFY ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY",
     4  "desc": "raw(82012088a914ffffffffffffffffffffffffffffffffffffffff8820ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffad51b2)#5guaahuv",
     5  "type": "nonstandard",
     6  "p2sh": "33YyjgxsJYwSi8Wbp7TaCSFAuJBoUfYWDQ",
     7  "segwit": {
     8    "asm": "0 99f5d0b69f9828fea9363198cf812e95d7fc5e94c7881092b8e3f43984c1bd5c",
     9    "desc": "addr(bc1qn86apd5lnq50a2fkxxvvlqfwjhtlch55c7yppy4cu06rnpxph4wqrar3md)#wtlf0gwk",
    10    "hex": "002099f5d0b69f9828fea9363198cf812e95d7fc5e94c7881092b8e3f43984c1bd5c",
    11    "address": "bc1qn86apd5lnq50a2fkxxvvlqfwjhtlch55c7yppy4cu06rnpxph4wqrar3md",
    12    "type": "witness_v0_scripthash",
    13    "p2sh-segwit": "3MRJN2wTnD2BVm31HLcBwueAYpbbximrtk"
    14  }
    15}
    

    Since it’s evaluated at “top level for desc it cannot get any meaningful structure from it. Perhaps in segwit it could try infering the miniscript in the segwit context

  2. instagibbs added the label Feature on Jan 31, 2023
  3. maflcko added the label RPC/REST/ZMQ on Jan 31, 2023
  4. darosior commented at 5:11 pm on January 31, 2023: member

    The issue here is that in decodescript we do try to parse a wsh descriptor from a constructed P2WSH scriptPubKey: https://github.com/bitcoin/bitcoin/blob/2b211b41e36f914b8d0487e698b619039cc3c8e2/src/rpc/rawtransaction.cpp#L519-L530

    But inferScript won’t be able to analyze the witness script itself since we are passing a dummy signature provider: https://github.com/bitcoin/bitcoin/blob/2b211b41e36f914b8d0487e698b619039cc3c8e2/src/core_write.cpp#L150-L156

    Therefore GetCScript won’t return anything: https://github.com/bitcoin/bitcoin/blob/2b211b41e36f914b8d0487e698b619039cc3c8e2/src/script/descriptor.cpp#L1622-L1629

  5. sipa commented at 5:58 pm on January 31, 2023: member
    I would think that all we need to do is add the RPC argument script to the signature provider used for inference.
  6. instagibbs commented at 7:08 pm on January 31, 2023: member

    Yes, it’s that simple (well, example I gave above was xonly key, so added 0x02 prefix):

     0decodescript 82012088a914ffffffffffffffffffffffffffffffffffffffff882102ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffad51b2
     1{
     2  "asm": "OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 ffffffffffffffffffffffffffffffffffffffff OP_EQUALVERIFY 02ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff OP_CHECKSIGVERIFY 1 OP_CHECKSEQUENCEVERIFY",
     3  "desc": "raw(82012088a914ffffffffffffffffffffffffffffffffffffffff882102ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffad51b2)#x8xuy2m2",
     4  "type": "nonstandard",
     5  "p2sh": "2MzccBLNZbDP7tXZkrKKp5Zi7wDX4XpvAjQ",
     6  "segwit": {
     7    "asm": "0 ef65a26f417cee177ce157608612a95ff6a45a052dc440883cf2d069fca8fc82",
     8    "desc": "wsh(and_v(and_v(v:hash160(ffffffffffffffffffffffffffffffffffffffff),v:pk(02ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)),older(1)))#twc36s59",
     9    "hex": "0020ef65a26f417cee177ce157608612a95ff6a45a052dc440883cf2d069fca8fc82",
    10    "address": "bcrt1qaaj6ym6p0nhpwl8p2asgvy4ftlm2gks99hzypzpu7tgxnl9gljpq8j9ewh",
    11    "type": "witness_v0_scripthash",
    12    "p2sh-segwit": "2MxgwFJU1Ei4eYqbShbVSX2ecYYooEm8zxy"
    13  }
    14}
    
  7. darosior commented at 1:47 pm on February 1, 2023: member
    @instagibbs do you intend to PR this? Otherwise i can do it.
  8. instagibbs commented at 2:07 pm on February 1, 2023: member

    I didn’t love the interface change I did for it. You give it a shot?

    On Wed, Feb 1, 2023, 8:47 AM Antoine Poinsot @.***> wrote:

    @instagibbs https://github.com/instagibbs do you intend to PR this? Otherwise i can do it.

    — Reply to this email directly, view it on GitHub https://github.com/bitcoin/bitcoin/issues/27007#issuecomment-1412087232, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMAFU7PNOHV5VU65AIBESTWVJSQ5ANCNFSM6AAAAAAUMVUAEI . You are receiving this because you were mentioned.Message ID: @.***>

  9. achow101 closed this on Feb 3, 2023

  10. sidhujag referenced this in commit f4fce72f9f on Feb 4, 2023
  11. bitcoin locked this on Feb 3, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-29 04:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me