<p>OP_NUMEQUAL doesn't provide a subset of the functionality of OP_EQUAL as they evaluate differently when comparing <code>0x01</code> with <code>0x0001</code>. OP_NUMEQUAL evaluates <code>0x01</code> and <code>0x0001</code> as equal as it compares <code>1</code> with <code>1</code> whilst OP_EQUAL does <strong>not</strong> deem them equal as it compares a different number of bytes. Hence which one you use in your script will be determined by whether you want such a comparison to evaluate to equal or not.</p>
<p><strong>Edit (August 2023):</strong></p>
<p>Note the Taproot descriptor <code>multi_a</code> uses the OP_NUMEQUAL opcode. <code>multi_a(k,A,B,C,...Z)</code> translates to:</p>
<pre><code>[A] CHECKSIG [B] CHECKSIGADD [C] CHECKSIGADD ... [Z] CHECKSIGADD &lt;k&gt; OP_NUMEQUAL
</code></pre>
<p>There is no strong reason for it doing so as <code>multi_a</code> will always have the number encoded minimally. It arguably makes it easier to parse as OP_EQUAL is used in multiple other Miniscript constructions.</p>
<p>Thanks to individuals on IRC for clarifying the latter.</p>

CC BY-SA 4.0
2022-09-10T15:12:32.313Z
2023-08-31T08:27:05.013Z
2023-08-31T08:27:05.013Z
Michael Folkson
<p>There is a OP_EQUAL <a href="https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L886" rel="nofollow noreferrer">opcode</a> that returns (from the Bitcoin <a href="https://en.bitcoin.it/wiki/Script" rel="nofollow noreferrer">wiki</a>):</p>
<blockquote>
<p>1 if the inputs are exactly equal, 0 otherwise</p>
</blockquote>
<p>And a OP_NUMEQUAL <a href="https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L97698073cdfab01/src/script/interpreter.cpp#L976" rel="nofollow noreferrer">opcode</a> that returns:</p>
<blockquote>
<p>1 if the numbers are equal, 0 otherwise</p>
</blockquote>
<p>In the case where you want to use OP_NOTEQUAL it is <a href="https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L888" rel="nofollow noreferrer">suggested</a> to use OP_NUMNOTEQUAL so it seems like OP_EQUAL and OP_NUMEQUAL can be used interchangeably when dealing with integers:</p>
<p><code>//case OP_NOTEQUAL: // use OP_NUMNOTEQUAL</code></p>
<p>What is the point of the OP_NUMEQUAL opcode? Can't you just always use OP_EQUAL instead? Is OP_NUMEQUAL more efficient than OP_EQUAL when dealing with integers?</p>

<script><opcodes>
Why is there a OP_NUMEQUAL opcode? Does OP_NUMEQUAL offer a subset of the functionality of OP_EQUAL?
Michael Folkson
# Why is there a OP_NUMEQUAL opcode? Does OP_NUMEQUAL offer a subset of the functionality of OP_EQUAL?

(Asked by: username_0 on 2022-09-10)

There is a OP\_EQUAL [opcode](https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L886) that returns (from the Bitcoin [wiki](https://en.bitcoin.it/wiki/Script)):

> 1 if the inputs are exactly equal, 0 otherwise

And a OP\_NUMEQUAL [opcode](https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L97698073cdfab01/src/script/interpreter.cpp#L976) that returns:

> 1 if the numbers are equal, 0 otherwise

In the case where you want to use OP\_NOTEQUAL it is [suggested](https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L888) to use OP\_NUMNOTEQUAL so it seems like OP\_EQUAL and OP\_NUMEQUAL can be used interchangeably when dealing with integers:

`//case OP_NOTEQUAL: // use OP_NUMNOTEQUAL`

What is the point of the OP\_NUMEQUAL opcode? Can't you just always use OP\_EQUAL instead? Is OP\_NUMEQUAL more efficient than OP\_EQUAL when dealing with integers?

**Tags:** script, opcodes


---

## 1 answers

### Answer by username_0 on 2022-09-10. Score: 4 | Accepted answer

OP\_NUMEQUAL doesn't provide a subset of the functionality of OP\_EQUAL as they evaluate differently when comparing `0x01` with `0x0001`. OP\_NUMEQUAL evaluates `0x01` and `0x0001` as equal as it compares `1` with `1` whilst OP\_EQUAL does **not** deem them equal as it compares a different number of bytes. Hence which one you use in your script will be determined by whether you want such a comparison to evaluate to equal or not.

**Edit (August 2023):**

Note the Taproot descriptor `multi_a` uses the OP\_NUMEQUAL opcode. `multi_a(k,A,B,C,...Z)` translates to:

```
[A] CHECKSIG [B] CHECKSIGADD [C] CHECKSIGADD ... [Z] CHECKSIGADD <k> OP_NUMEQUAL

```

There is no strong reason for it doing so as `multi_a` will always have the number encoded minimally. It arguably makes it easier to parse as OP\_EQUAL is used in multiple other Miniscript constructions.

Thanks to individuals on IRC for clarifying the latter.


---

