Have an exhaustive regex about unlock conditions
Today the regexp applied on an oupout condition in transaction looks like this:
const SIG = "[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{43,44}";
const CLTV_INTEGER = "([0-9]{1,10})";
const CSV_INTEGER = "([0-9]{1,8})";
const CONDITIONS = "(&&|\\|\\|| |[()]|(SIG\\(" + SIG + "\\)|(XHX\\([A-F0-9]{64}\\)|CLTV\\(" + CLTV_INTEGER + "\\)|CSV\\(" + CSV_INTEGER + "\\))))*";
Which we can sum up like:
« put any combination of allowed characters, and you are allowed to repeat them »
This is a too permissive. For example, this condition would be accepted by the regex:
)(CLTV(2000)))(CSV(1900)||&& ())()
No one has ever sent such a transction, but if he does the output would be locked forever. This is not a problem, but we could prevent such wrong syntax. We want an boolean expression with parenthesis, &&
and ||
characters separated by a single space.
I have to get the correct regex. Let's say we only allow 3 levels of parenthesis (i.e. opening a parenthesis = open a level, closing it = close the level). Having a limit of 3 opened levels should be enough for most cases.