Skip to main content
added 128 characters in body
Source Link
Pieter Wuille
  • 109.6k
  • 9
  • 202
  • 318

For the purposes of determining whether a Script stack element is true/false in boolean context:

  • The empty array is false (the canonical encoding of the number 0).
  • Any array consisting of just 0x00 bytes is false (an overly long, but still valid encoding of the number 0).
  • Any array consisting of just 0x00 bytes, followed by a single 0x80 at the end, is false (encodings of "negative 0").
  • Everything else is true.

This boolean context is relevant for OP_IF, OP_NOTIF, OP_VERIFY, and OP_IFDUP, as well as for determining final success of Script evaluation. Opcodes like OP_BOOLOR and OP_BOOLAND actually interpret their arguments as integers, though the only practical difference is that integer arguments are limited to 4 bytes (violating this limit makes the entire script invalid).

For the purposes of determining whether a Script stack element is true/false in boolean context:

  • The empty array is false.
  • Any array consisting of just 0x00 bytes is false.
  • Any array consisting of just 0x00 bytes, followed by a single 0x80 at the end, is false.
  • Everything else is true.

This boolean context is relevant for OP_IF, OP_NOTIF, OP_VERIFY, and OP_IFDUP, as well as for determining final success of Script evaluation. Opcodes like OP_BOOLOR and OP_BOOLAND actually interpret their arguments as integers, though the only practical difference is that integer arguments are limited to 4 bytes (violating this limit makes the entire script invalid).

For the purposes of determining whether a Script stack element is true/false in boolean context:

  • The empty array is false (the canonical encoding of the number 0).
  • Any array consisting of just 0x00 bytes is false (an overly long, but still valid encoding of the number 0).
  • Any array consisting of just 0x00 bytes, followed by a single 0x80 at the end, is false (encodings of "negative 0").
  • Everything else is true.

This boolean context is relevant for OP_IF, OP_NOTIF, OP_VERIFY, and OP_IFDUP, as well as for determining final success of Script evaluation. Opcodes like OP_BOOLOR and OP_BOOLAND actually interpret their arguments as integers, though the only practical difference is that integer arguments are limited to 4 bytes (violating this limit makes the entire script invalid).

Source Link
Pieter Wuille
  • 109.6k
  • 9
  • 202
  • 318

For the purposes of determining whether a Script stack element is true/false in boolean context:

  • The empty array is false.
  • Any array consisting of just 0x00 bytes is false.
  • Any array consisting of just 0x00 bytes, followed by a single 0x80 at the end, is false.
  • Everything else is true.

This boolean context is relevant for OP_IF, OP_NOTIF, OP_VERIFY, and OP_IFDUP, as well as for determining final success of Script evaluation. Opcodes like OP_BOOLOR and OP_BOOLAND actually interpret their arguments as integers, though the only practical difference is that integer arguments are limited to 4 bytes (violating this limit makes the entire script invalid).