<p>Short answer: arithmetic on large numbers will cause the script to fail.</p>

<p>Long answer:</p>

<p>Script arithmetic is limited to 32-bit arithmetic.</p>

<p>You can find the code for arithmetic operations in <a href="https://github.com/bitcoin/bitcoin/blob/master/src/script.cpp" rel="nofollow">script.cpp</a>, in the function <code>EvalScript</code>, where the opcodes are evaluated using <code>CScriptNum</code> in [script.h](<a href="https://github.com/bitcoin/bitcoin/blob/master/src/script.h]" rel="nofollow">https://github.com/bitcoin/bitcoin/blob/master/src/script.h]</a>.</p>

<p>The numeric limit is enforced through the constant <code>nMaxNumSize</code>.</p>

<p>The CScriptNum constructor shows that numbers larger than 32 bits throw an exception, resulting in failure of the script.</p>

CC BY-SA 3.0
2014-07-12T20:56:45.433Z
2014-07-12T20:56:45.433Z
Willem Hengeveld
<p>How do arithmetic operations work in Bitcoin? If I have:</p>

<pre><code> 5
 OP_1ADD
</code></pre>

<p>it is obvious that I will get 6 on stack. But what if I have to make OP_1ADD on "02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f"?</p>

<pre><code> "02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f"
 OP_1ADD
</code></pre>

<script>
Arithmetic operations in Bitcoin (OP_ADD, etc)
me.ex
# Arithmetic operations in Bitcoin (OP_ADD, etc)

(Asked by: username_0 on 2014-07-12)

How do arithmetic operations work in Bitcoin? If I have:
 5
 OP_1ADD

it is obvious that I will get 6 on stack. But what if I have to make OP_1ADD on "02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f"?
 "02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f"
 OP_1ADD

**Tags:** script


---

## 1 answers

### Answer by username_1 on 2014-07-12. Score: 2

Short answer: arithmetic on large numbers will cause the script to fail.

Long answer:

Script arithmetic is limited to 32-bit arithmetic.

You can find the code for arithmetic operations in [script.cpp](https://github.com/bitcoin/bitcoin/blob/master/src/script.cpp), in the function `EvalScript`, where the opcodes are evaluated using `CScriptNum` in [script.h](<https://github.com/bitcoin/bitcoin/blob/master/src/script.h]>.

The numeric limit is enforced through the constant `nMaxNumSize`.

The CScriptNum constructor shows that numbers larger than 32 bits throw an exception, resulting in failure of the script.


---

