<p>For the purposes of determining whether a Script stack element is true/false in boolean context:</p>
<ul>
<li>The empty array is false (the canonical encoding of the number 0).</li>
<li>Any array consisting of just 0x00 bytes is false (an overly long, but still valid encoding of the number 0).</li>
<li>Any array consisting of just 0x00 bytes, followed by a single 0x80 at the end, is false (encodings of &quot;negative 0&quot;).</li>
<li>Everything else is true.</li>
</ul>
<p>This boolean context is relevant for <code>OP_IF</code>, <code>OP_NOTIF</code>, <code>OP_VERIFY</code>, and <code>OP_IFDUP</code>, as well as for determining final success of Script evaluation. Opcodes like <code>OP_BOOLOR</code> and <code>OP_BOOLAND</code> 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).</p>

CC BY-SA 4.0
2024-12-13T20:24:03.280Z
Thanks for the answer @pieter-wuille. Here is a follow-up question I'd like to confirm with you. Are you saying that the script `<ababababababababab> <01> OP_BOOLAND` is invalid instead of true (because the first argument is 9 bytes long instead of 8 or less?
thunderbiscuit
CC BY-SA 4.0
2024-12-13T20:25:51.957Z
Yes, `<ababababab> OP_1 OP_BOOLAND` would also be invalid (5 bytes is more than 4).
Pieter Wuille
CC BY-SA 4.0
2024-12-13T20:39:16.997Z
Oh shoot yes 4 bytes is what I meant haha. Perfect thanks! I was working on [this page](https://opcodeexplained.com/opcodes/OP_BOOLAND.html). Cheers.
thunderbiscuit
CC BY-SA 4.0
2024-11-05T20:05:04.137Z
2024-11-06T21:15:14.833Z
2024-11-06T21:15:14.833Z
Pieter Wuille
<p>From my interpretation of the <a href="https://en.bitcoin.it/wiki/Script" rel="nofollow noreferrer">bitcoin Script Wiki</a> and the <a href="https://docs.rs/bitcoin/latest/src/bitcoin/blockdata/opcodes.rs.html#78-338" rel="nofollow noreferrer">rust-bitcoin codebase</a>, two items on the stack get interpreted by bitcoin Script as false:</p>
<ol>
<li>The empty array <code>[]</code></li>
<li>The single byte <code>0x00</code></li>
</ol>
<p><strong>Q1:</strong> Is it correct to think that a 2-byte long or more array of 0s (even though as a number would get interpreted as 0) would not be interpreted by bitcoin Script as <code>false</code>? For example the script <code>OP_PUSHBYTES_4 &lt;0x00000000&gt;</code> would put a byte array of 0s on the stack but still equate to <code>true</code>? On the other hand the script <code>OP_PUSHBYTES_1 &lt;0x00&gt;</code> would interpret as false?</p>
<p><strong>Q2:</strong> Will an opcode like <code>OP_NOT</code> work with/interpret both of the above as false? (the docs on rust-bitcoin, <code>Push 1 if the top item is zero; otherwise, push 0.</code> are not very explicit in that sense, and the bitcoin wiki is even worse).</p>

CC BY-SA 4.0
2024-11-06T16:46:17.620Z
For readers coming to this post: note that my assumption on Q1 was wrong, and in fact the script `OP_PUSHBYTES_4 00000000` would evaluate to false.
thunderbiscuit
<script>
Clarification on false value in Script
thunderbiscuit
# Clarification on false value in Script

(Asked by: username_0 on 2024-11-05)

From my interpretation of the [bitcoin Script Wiki](https://en.bitcoin.it/wiki/Script) and the [rust-bitcoin codebase](https://docs.rs/bitcoin/latest/src/bitcoin/blockdata/opcodes.rs.html#78-338), two items on the stack get interpreted by bitcoin Script as false:

1. The empty array `[]`
2. The single byte `0x00`

**Q1:** Is it correct to think that a 2-byte long or more array of 0s (even though as a number would get interpreted as 0) would not be interpreted by bitcoin Script as `false`? For example the script `OP_PUSHBYTES_4 <0x00000000>` would put a byte array of 0s on the stack but still equate to `true`? On the other hand the script `OP_PUSHBYTES_1 <0x00>` would interpret as false?

**Q2:** Will an opcode like `OP_NOT` work with/interpret both of the above as false? (the docs on rust-bitcoin, `Push 1 if the top item is zero; otherwise, push 0.` are not very explicit in that sense, and the bitcoin wiki is even worse).

**Tags:** script

> **Comments:**
> **username_0**: For readers coming to this post: note that my assumption on Q1 was wrong, and in fact the script `OP_PUSHBYTES_4 00000000` would evaluate to false.  

---

## 1 answers

### Answer by username_1 on 2024-11-05. Score: 5 | Accepted answer

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).

> **Comments:**
> **username_0**: Thanks for the answer @pieter-wuille. Here is a follow-up question I'd like to confirm with you. Are you saying that the script `<ababababababababab> <01> OP_BOOLAND` is invalid instead of true (because the first argument is 9 bytes long instead of 8 or less?  
> **username_1**: Yes, `<ababababab> OP_1 OP_BOOLAND` would also be invalid (5 bytes is more than 4).  
> **username_0**: Oh shoot yes 4 bytes is what I meant haha. Perfect thanks! I was working on [this page](https://opcodeexplained.com/opcodes/OP_BOOLAND.html). Cheers.  

---

