bit-matrix / script-wiz-lib

MIT License
42 stars 5 forks source link

OP_CHECKLOCKTIMEVERIFY does not accept 5-byte scriptNums #51

Open dgpv opened 1 year ago

dgpv commented 1 year ago

when entering the following script in ScriptWiz app (https://ide.scriptwiz.app/):

<0x0100008000000000> // 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 error at OP_CHECKLOCKTIMEVERIFY: Error: Invalid input: this operation requires a valid Script Number

The number on the stack at this time is 0x0100008000 - a 5-byte scriptnum.

CLTV, as a special case, accepts scriptnums of 5-byte length, to avoid y2038 problem. It seems that ScriptWiz interpreter does not account for this special case.