bit-matrix / script-wiz-lib

MIT License
42 stars 5 forks source link

liquid p2tr opcodes silently ignored when liquid p2wsh mode is selected #50

Open dgpv opened 1 year ago

dgpv commented 1 year ago

When compiling the following script in ScriptWiz app (https://ide.scriptwiz.app/): (edit: in liquid v0_p2wsh mode)

<0x0100000000000000> // timestamp
OP_DUP // copy timestamp
<0x0000008000000000>
OP_GREATERTHANOREQUAL64
OP_IF
// If timestamp does not fit into 4-byte scriptnum, we will just take 5 lower
// bytes of it. This will allow to use locktimes up to year 2106
<0>
<5>
OP_SUBSTR
OP_ELSE
// If timestamp fits into 4-byte scriptnum, just convert it
OP_LE64TOSCRIPTNUM
OP_ENDIF

// timestamp in scriptnum format is now on top of the stack
OP_CHECKLOCKTIMEVERIFY
OP_DROP

I get the following bytes:

0x080100000000000000760800000080000000006300557f6768b175

As you can see, right after the 76080000008000000000, which is OP_DUP, <0x0000008000000000>, follows 63. But this is the code for OP_IF rather than for OP_GREATERTHANOREQUAL64 (which is df)

dgpv commented 1 year ago

When I switch to liquid v1_ptr mode, everything is compiled correctly. But from UX standpoint, the fact that there is no warning is unfortunate. I think if the code have opcodes that are clearly not compatible with the current mode, at least a warning telling the user that they should probably switch the mode is in order.