Skip to content

Commit 3ec4552

Browse files
committed
Get feature_64bit-arithmetic_opcodes.py test cases passing
Remove references to 64bit specific opcodes Remove OP_VERIFY from python tests as we no longer push vchTrue/vchFalse onto the stack indicating success of the arithmetic opcode WIP: Get first test passing for 2**63 int64_t overflow in OP_ADD Get all tests passing in feature_64bit_arithmetic_opcodes.py Remove unused functions Remove unused functions Add GetCScriptNum() Add upperbound out of bounds test WIP: Pull over integration tests w/ existing opcodes WIP: Add max/min Get all integration tests w/ existing opcodes passing in feature_64bit_arithmetic_opcodes.py Cleanup Revert IsOpSuccess() fix feature_taproot.py
1 parent 9b4c57a commit 3ec4552

File tree

9 files changed

+229
-355
lines changed

9 files changed

+229
-355
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ static RPCHelpMan decodescript()
566566
for (CScript::const_iterator it{script.begin()}; it != script.end();) {
567567
opcodetype op;
568568
CHECK_NONFATAL(script.GetOp(it, op));
569-
if (op == OP_CHECKSIGADD || IsOpSuccess(op, SigVersion::TAPSCRIPT)) {
569+
if (op == OP_CHECKSIGADD || IsOpSuccess(op)) {
570570
return false;
571571
}
572572
}

src/script/interpreter.cpp

Lines changed: 100 additions & 198 deletions
Large diffs are not rendered by default.

src/script/script.cpp

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,6 @@ std::string GetOpName(opcodetype opcode)
150150
// Opcode added by BIP 342 (Tapscript)
151151
case OP_CHECKSIGADD : return "OP_CHECKSIGADD";
152152

153-
//64bit arithmetic opcodes
154-
case OP_ADD64 : return "OP_ADD64";
155-
case OP_SUB64 : return "OP_SUB64";
156-
case OP_MUL64 : return "OP_MUL64";
157-
case OP_DIV64 : return "OP_DIV64";
158-
case OP_NEG64 : return "OP_NEG64";
159-
case OP_LESSTHAN64 : return "OP_LESSTHAN64";
160-
case OP_LESSTHANOREQUAL64 : return "OP_LESSTHANOREQUAL64";
161-
case OP_GREATERTHAN64 : return "OP_GREATERTHAN64";
162-
case OP_GREATERTHANOREQUAL64 : return "OP_GREATERTHANOREQUAL64";
163-
case OP_SCRIPTNUMTOLE64 : return "OP_SCRIPTNUMTOLE64";
164-
case OP_LE64TOSCRIPTNUM : return "OP_LE64TOSCRIPTNUM";
165-
case OP_LE32TOLE64 : return "OP_LE32TOLE64";
166-
167153
case OP_INVALIDOPCODE : return "OP_INVALIDOPCODE";
168154

169155
default:
@@ -353,29 +339,12 @@ bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator en
353339
return true;
354340
}
355341

356-
bool IsOpSuccess(const opcodetype& opcode, SigVersion sigversion)
342+
bool IsOpSuccess(const opcodetype& opcode)
357343
{
358-
switch (sigversion)
359-
{
360-
case SigVersion::TAPSCRIPT:
361-
return opcode == 80 || opcode == 98 || (opcode >= 126 && opcode <= 129) ||
344+
return opcode == 80 || opcode == 98 || (opcode >= 126 && opcode <= 129) ||
362345
(opcode >= 131 && opcode <= 134) || (opcode >= 137 && opcode <= 138) ||
363346
(opcode >= 141 && opcode <= 142) || (opcode >= 149 && opcode <= 153) ||
364347
(opcode >= 187 && opcode <= 254);
365-
break;
366-
case SigVersion::TAPSCRIPT_64BIT:
367-
return opcode == 80 || opcode == 98 || (opcode >= 126 && opcode <= 129) ||
368-
(opcode >= 131 && opcode <= 134) || (opcode >= 137 && opcode <= 138) ||
369-
(opcode >= 141 && opcode <= 142) || (opcode >= 149 && opcode <= 153) ||
370-
(opcode >= 187 && opcode <= 214) || (opcode >= 227 && opcode <= 254);
371-
break;
372-
case SigVersion::BASE:
373-
case SigVersion::WITNESS_V0:
374-
case SigVersion::TAPROOT:
375-
//impossible to have OP_SUCCESSx in old sig versions
376-
break;
377-
}
378-
assert(false);
379348
}
380349

381350
bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode) {

src/script/script.h

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313
#include <uint256.h>
1414
#include <util/hash_type.h>
1515

16-
#include <cassert>
17-
#include <cstdint>
18-
#include <cstring>
19-
#include <limits>
20-
#include <stdexcept>
21-
#include <string>
22-
#include <type_traits>
23-
#include <utility>
24-
#include <vector>
25-
2616
enum class SigVersion;
2717

2818
// Maximum number of bytes pushable to the stack
@@ -210,22 +200,6 @@ enum opcodetype
210200
// Opcode added by BIP 342 (Tapscript)
211201
OP_CHECKSIGADD = 0xba,
212202

213-
// Arithmetic opcodes
214-
OP_ADD64 = 0xd7,
215-
OP_SUB64 = 0xd8,
216-
OP_MUL64 = 0xd9,
217-
OP_DIV64 = 0xda,
218-
OP_NEG64 = 0xdb,
219-
OP_LESSTHAN64 = 0xdc,
220-
OP_LESSTHANOREQUAL64 = 0xdd,
221-
OP_GREATERTHAN64 = 0xde,
222-
OP_GREATERTHANOREQUAL64 = 0xdf,
223-
224-
// Conversion opcodes
225-
OP_SCRIPTNUMTOLE64 = 0xe0,
226-
OP_LE64TOSCRIPTNUM = 0xe1,
227-
OP_LE32TOLE64 = 0xe2,
228-
229203
OP_INVALIDOPCODE = 0xff,
230204
};
231205

@@ -252,7 +226,7 @@ class CScriptNum
252226
*/
253227
public:
254228

255-
explicit CScriptNum(const int64_t& n)
229+
explicit CScriptNum(const __int128_t& n)
256230
{
257231
m_value = n;
258232
}
@@ -313,12 +287,15 @@ class CScriptNum
313287

314288
inline CScriptNum& operator&=( const CScriptNum& rhs) { return operator&=(rhs.m_value); }
315289

316-
inline CScriptNum operator*(const int64_t& rhs) const { return CScriptNum(m_value * rhs);}
290+
inline CScriptNum operator*(const __int128_t& rhs) const { return CScriptNum(m_value * rhs);}
317291
inline CScriptNum operator*(const CScriptNum& rhs) const { return operator*(rhs.m_value);}
318292

293+
inline CScriptNum operator/(const __int128_t& rhs) const { return CScriptNum(m_value / rhs);}
294+
inline CScriptNum operator/(const CScriptNum& rhs) const { return operator/(rhs.m_value);}
295+
319296
inline CScriptNum operator-() const
320297
{
321-
assert(m_value != std::numeric_limits<int64_t>::min());
298+
assert(m_value != std::numeric_limits<__int128_t>::min());
322299
return CScriptNum(-m_value);
323300
}
324301

@@ -330,16 +307,16 @@ class CScriptNum
330307

331308
inline CScriptNum& operator+=( const int64_t& rhs)
332309
{
333-
assert(rhs == 0 || (rhs > 0 && m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
334-
(rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
310+
assert(rhs == 0 || (rhs > 0 && m_value <= std::numeric_limits<__int128_t>::max() - rhs) ||
311+
(rhs < 0 && m_value >= std::numeric_limits<__int128_t>::min() - rhs));
335312
m_value += rhs;
336313
return *this;
337314
}
338315

339316
inline CScriptNum& operator-=( const int64_t& rhs)
340317
{
341-
assert(rhs == 0 || (rhs > 0 && m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
342-
(rhs < 0 && m_value <= std::numeric_limits<int64_t>::max() + rhs));
318+
assert(rhs == 0 || (rhs > 0 && m_value >= std::numeric_limits<__int128_t>::min() + rhs) ||
319+
(rhs < 0 && m_value <= std::numeric_limits<__int128_t>::max() + rhs));
343320
m_value -= rhs;
344321
return *this;
345322
}
@@ -360,20 +337,21 @@ class CScriptNum
360337
}
361338

362339
int64_t GetInt64() const { return m_value; }
363-
340+
__int128_t GetInt128() const {return m_value; }
364341
std::vector<unsigned char> getvch() const
365342
{
366343
return serialize(m_value);
367344
}
368345

369-
static std::vector<unsigned char> serialize(const int64_t& value)
346+
static std::vector<unsigned char> serialize(const __int128_t& value)
370347
{
371-
if(value == 0)
348+
if(value == 0) {
372349
return std::vector<unsigned char>();
350+
}
373351

374352
std::vector<unsigned char> result;
375353
const bool neg = value < 0;
376-
uint64_t absvalue = neg ? ~static_cast<uint64_t>(value) + 1 : static_cast<uint64_t>(value);
354+
__uint128_t absvalue = neg ? ~static_cast<__uint128_t>(value) + 1 : static_cast<__uint128_t>(value);
377355

378356
while(absvalue)
379357
{
@@ -391,33 +369,35 @@ class CScriptNum
391369
// 0x80 to it, since it will be subtracted and interpreted as a negative when
392370
// converting to an integral.
393371

394-
if (result.back() & 0x80)
372+
if (result.back() & 0x80) {
395373
result.push_back(neg ? 0x80 : 0);
396-
else if (neg)
374+
}
375+
else if (neg) {
397376
result.back() |= 0x80;
377+
}
398378

399379
return result;
400380
}
401381

402382
private:
403-
static int64_t set_vch(const std::vector<unsigned char>& vch)
383+
static __int128_t set_vch(const std::vector<unsigned char>& vch)
404384
{
405385
if (vch.empty())
406386
return 0;
407387

408-
int64_t result = 0;
388+
__int128_t result = 0;
409389
for (size_t i = 0; i != vch.size(); ++i)
410-
result |= static_cast<int64_t>(vch[i]) << 8*i;
390+
result |= static_cast<__int128_t>(vch[i]) << 8*i;
411391

412392
// If the input vector's most significant byte is 0x80, remove it from
413393
// the result's msb and return a negative.
414394
if (vch.back() & 0x80)
415-
return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
395+
return -((__int128_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
416396

417397
return result;
418398
}
419399

420-
int64_t m_value;
400+
__int128_t m_value;
421401
};
422402

423403
/**
@@ -609,7 +589,7 @@ class CScriptID : public BaseHash<uint160>
609589
};
610590

611591
/** Test for OP_SUCCESSx opcodes as defined by BIP342. */
612-
bool IsOpSuccess(const opcodetype& opcode, SigVersion sigVersion);
592+
bool IsOpSuccess(const opcodetype& opcode);
613593

614594
bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode);
615595

src/script/script_error.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ std::string ScriptErrorString(const ScriptError serror)
115115
return "Using OP_CODESEPARATOR in non-witness script";
116116
case SCRIPT_ERR_SIG_FINDANDDELETE:
117117
return "Signature is found in scriptCode";
118-
case SCRIPT_ERR_EXPECTED_8BYTES:
119-
return "Arithmetic opcodes expect 8 bytes operands";
120118
case SCRIPT_ERR_ARITHMETIC64:
121119
return "Arithmetic opcode error";
122120
case SCRIPT_ERR_UNKNOWN_ERROR:

src/script/script_error.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ typedef enum ScriptError_t
8585
SCRIPT_ERR_ERROR_COUNT,
8686

8787
/* 64bit arithmetic opcode errors */
88-
SCRIPT_ERR_EXPECTED_8BYTES,
8988
SCRIPT_ERR_ARITHMETIC64
9089

9190
} ScriptError;

0 commit comments

Comments
 (0)