Bitcoin Core 28.99.0
P2P Digital Currency
script.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-present The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_SCRIPT_SCRIPT_H
7#define BITCOIN_SCRIPT_SCRIPT_H
8
9#include <attributes.h>
10#include <crypto/common.h>
11#include <prevector.h> // IWYU pragma: export
12#include <serialize.h>
13#include <uint256.h>
14#include <util/hash_type.h>
15
16#include <cassert>
17#include <cstdint>
18#include <cstring>
19#include <limits>
20#include <span>
21#include <stdexcept>
22#include <string>
23#include <type_traits>
24#include <utility>
25#include <vector>
26
27// Maximum number of bytes pushable to the stack
28static const unsigned int MAX_SCRIPT_ELEMENT_SIZE = 520;
29
30// Maximum number of non-push operations per script
31static const int MAX_OPS_PER_SCRIPT = 201;
32
33// Maximum number of public keys per multisig
34static const int MAX_PUBKEYS_PER_MULTISIG = 20;
35
37static constexpr unsigned int MAX_PUBKEYS_PER_MULTI_A = 999;
38
39// Maximum script length in bytes
40static const int MAX_SCRIPT_SIZE = 10000;
41
42// Maximum number of values on script interpreter stack
43static const int MAX_STACK_SIZE = 1000;
44
45// Threshold for nLockTime: below this value it is interpreted as block number,
46// otherwise as UNIX timestamp.
47static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
48
49// Maximum nLockTime. Since a lock time indicates the last invalid timestamp, a
50// transaction with this lock time will never be valid unless lock time
51// checking is disabled (by setting all input sequence numbers to
52// SEQUENCE_FINAL).
53static const uint32_t LOCKTIME_MAX = 0xFFFFFFFFU;
54
55// Tag for input annex. If there are at least two witness elements for a transaction input,
56// and the first byte of the last element is 0x50, this last element is called annex, and
57// has meanings independent of the script
58static constexpr unsigned int ANNEX_TAG = 0x50;
59
60// Validation weight per passing signature (Tapscript only, see BIP 342).
61static constexpr int64_t VALIDATION_WEIGHT_PER_SIGOP_PASSED{50};
62
63// How much weight budget is added to the witness size (Tapscript only, see BIP 342).
64static constexpr int64_t VALIDATION_WEIGHT_OFFSET{50};
65
66template <typename T>
67std::vector<unsigned char> ToByteVector(const T& in)
68{
69 return std::vector<unsigned char>(in.begin(), in.end());
70}
71
74{
75 // push value
76 OP_0 = 0x00,
81 OP_1NEGATE = 0x4f,
83 OP_1 = 0x51,
85 OP_2 = 0x52,
86 OP_3 = 0x53,
87 OP_4 = 0x54,
88 OP_5 = 0x55,
89 OP_6 = 0x56,
90 OP_7 = 0x57,
91 OP_8 = 0x58,
92 OP_9 = 0x59,
93 OP_10 = 0x5a,
94 OP_11 = 0x5b,
95 OP_12 = 0x5c,
96 OP_13 = 0x5d,
97 OP_14 = 0x5e,
98 OP_15 = 0x5f,
99 OP_16 = 0x60,
100
101 // control
102 OP_NOP = 0x61,
103 OP_VER = 0x62,
104 OP_IF = 0x63,
105 OP_NOTIF = 0x64,
106 OP_VERIF = 0x65,
108 OP_ELSE = 0x67,
109 OP_ENDIF = 0x68,
110 OP_VERIFY = 0x69,
111 OP_RETURN = 0x6a,
112
113 // stack ops
116 OP_2DROP = 0x6d,
117 OP_2DUP = 0x6e,
118 OP_3DUP = 0x6f,
119 OP_2OVER = 0x70,
120 OP_2ROT = 0x71,
121 OP_2SWAP = 0x72,
122 OP_IFDUP = 0x73,
123 OP_DEPTH = 0x74,
124 OP_DROP = 0x75,
125 OP_DUP = 0x76,
126 OP_NIP = 0x77,
127 OP_OVER = 0x78,
128 OP_PICK = 0x79,
129 OP_ROLL = 0x7a,
130 OP_ROT = 0x7b,
131 OP_SWAP = 0x7c,
132 OP_TUCK = 0x7d,
133
134 // splice ops
135 OP_CAT = 0x7e,
136 OP_SUBSTR = 0x7f,
137 OP_LEFT = 0x80,
138 OP_RIGHT = 0x81,
139 OP_SIZE = 0x82,
140
141 // bit logic
142 OP_INVERT = 0x83,
143 OP_AND = 0x84,
144 OP_OR = 0x85,
145 OP_XOR = 0x86,
146 OP_EQUAL = 0x87,
150
151 // numeric
152 OP_1ADD = 0x8b,
153 OP_1SUB = 0x8c,
154 OP_2MUL = 0x8d,
155 OP_2DIV = 0x8e,
156 OP_NEGATE = 0x8f,
157 OP_ABS = 0x90,
158 OP_NOT = 0x91,
160
161 OP_ADD = 0x93,
162 OP_SUB = 0x94,
163 OP_MUL = 0x95,
164 OP_DIV = 0x96,
165 OP_MOD = 0x97,
166 OP_LSHIFT = 0x98,
167 OP_RSHIFT = 0x99,
168
170 OP_BOOLOR = 0x9b,
178 OP_MIN = 0xa3,
179 OP_MAX = 0xa4,
180
181 OP_WITHIN = 0xa5,
182
183 // crypto
185 OP_SHA1 = 0xa7,
186 OP_SHA256 = 0xa8,
194
195 // expansion
196 OP_NOP1 = 0xb0,
201 OP_NOP4 = 0xb3,
202 OP_NOP5 = 0xb4,
203 OP_NOP6 = 0xb5,
204 OP_NOP7 = 0xb6,
205 OP_NOP8 = 0xb7,
206 OP_NOP9 = 0xb8,
207 OP_NOP10 = 0xb9,
208
209 // Opcode added by BIP 342 (Tapscript)
211
213};
214
215// Maximum value that an opcode can be
216static const unsigned int MAX_OPCODE = OP_NOP10;
217
218std::string GetOpName(opcodetype opcode);
219
220class scriptnum_error : public std::runtime_error
221{
222public:
223 explicit scriptnum_error(const std::string& str) : std::runtime_error(str) {}
224};
225
227{
236public:
237
238 explicit CScriptNum(const int64_t& n)
239 {
240 m_value = n;
241 }
242
243 static const size_t nDefaultMaxNumSize = 4;
244
245 explicit CScriptNum(const std::vector<unsigned char>& vch, bool fRequireMinimal,
246 const size_t nMaxNumSize = nDefaultMaxNumSize)
247 {
248 if (vch.size() > nMaxNumSize) {
249 throw scriptnum_error("script number overflow");
250 }
251 if (fRequireMinimal && vch.size() > 0) {
252 // Check that the number is encoded with the minimum possible
253 // number of bytes.
254 //
255 // If the most-significant-byte - excluding the sign bit - is zero
256 // then we're not minimal. Note how this test also rejects the
257 // negative-zero encoding, 0x80.
258 if ((vch.back() & 0x7f) == 0) {
259 // One exception: if there's more than one byte and the most
260 // significant bit of the second-most-significant-byte is set
261 // it would conflict with the sign bit. An example of this case
262 // is +-255, which encode to 0xff00 and 0xff80 respectively.
263 // (big-endian).
264 if (vch.size() <= 1 || (vch[vch.size() - 2] & 0x80) == 0) {
265 throw scriptnum_error("non-minimally encoded script number");
266 }
267 }
268 }
269 m_value = set_vch(vch);
270 }
271
272 inline bool operator==(const int64_t& rhs) const { return m_value == rhs; }
273 inline bool operator!=(const int64_t& rhs) const { return m_value != rhs; }
274 inline bool operator<=(const int64_t& rhs) const { return m_value <= rhs; }
275 inline bool operator< (const int64_t& rhs) const { return m_value < rhs; }
276 inline bool operator>=(const int64_t& rhs) const { return m_value >= rhs; }
277 inline bool operator> (const int64_t& rhs) const { return m_value > rhs; }
278
279 inline bool operator==(const CScriptNum& rhs) const { return operator==(rhs.m_value); }
280 inline bool operator!=(const CScriptNum& rhs) const { return operator!=(rhs.m_value); }
281 inline bool operator<=(const CScriptNum& rhs) const { return operator<=(rhs.m_value); }
282 inline bool operator< (const CScriptNum& rhs) const { return operator< (rhs.m_value); }
283 inline bool operator>=(const CScriptNum& rhs) const { return operator>=(rhs.m_value); }
284 inline bool operator> (const CScriptNum& rhs) const { return operator> (rhs.m_value); }
285
286 inline CScriptNum operator+( const int64_t& rhs) const { return CScriptNum(m_value + rhs);}
287 inline CScriptNum operator-( const int64_t& rhs) const { return CScriptNum(m_value - rhs);}
288 inline CScriptNum operator+( const CScriptNum& rhs) const { return operator+(rhs.m_value); }
289 inline CScriptNum operator-( const CScriptNum& rhs) const { return operator-(rhs.m_value); }
290
291 inline CScriptNum& operator+=( const CScriptNum& rhs) { return operator+=(rhs.m_value); }
292 inline CScriptNum& operator-=( const CScriptNum& rhs) { return operator-=(rhs.m_value); }
293
294 inline CScriptNum operator&( const int64_t& rhs) const { return CScriptNum(m_value & rhs);}
295 inline CScriptNum operator&( const CScriptNum& rhs) const { return operator&(rhs.m_value); }
296
297 inline CScriptNum& operator&=( const CScriptNum& rhs) { return operator&=(rhs.m_value); }
298
299 inline CScriptNum operator-() const
300 {
301 assert(m_value != std::numeric_limits<int64_t>::min());
302 return CScriptNum(-m_value);
303 }
304
305 inline CScriptNum& operator=( const int64_t& rhs)
306 {
307 m_value = rhs;
308 return *this;
309 }
310
311 inline CScriptNum& operator+=( const int64_t& rhs)
312 {
313 assert(rhs == 0 || (rhs > 0 && m_value <= std::numeric_limits<int64_t>::max() - rhs) ||
314 (rhs < 0 && m_value >= std::numeric_limits<int64_t>::min() - rhs));
315 m_value += rhs;
316 return *this;
317 }
318
319 inline CScriptNum& operator-=( const int64_t& rhs)
320 {
321 assert(rhs == 0 || (rhs > 0 && m_value >= std::numeric_limits<int64_t>::min() + rhs) ||
322 (rhs < 0 && m_value <= std::numeric_limits<int64_t>::max() + rhs));
323 m_value -= rhs;
324 return *this;
325 }
326
327 inline CScriptNum& operator&=( const int64_t& rhs)
328 {
329 m_value &= rhs;
330 return *this;
331 }
332
333 int getint() const
334 {
335 if (m_value > std::numeric_limits<int>::max())
336 return std::numeric_limits<int>::max();
337 else if (m_value < std::numeric_limits<int>::min())
338 return std::numeric_limits<int>::min();
339 return m_value;
340 }
341
342 int64_t GetInt64() const { return m_value; }
343
344 std::vector<unsigned char> getvch() const
345 {
346 return serialize(m_value);
347 }
348
349 static std::vector<unsigned char> serialize(const int64_t& value)
350 {
351 if(value == 0)
352 return std::vector<unsigned char>();
353
354 std::vector<unsigned char> result;
355 const bool neg = value < 0;
356 uint64_t absvalue = neg ? ~static_cast<uint64_t>(value) + 1 : static_cast<uint64_t>(value);
357
358 while(absvalue)
359 {
360 result.push_back(absvalue & 0xff);
361 absvalue >>= 8;
362 }
363
364// - If the most significant byte is >= 0x80 and the value is positive, push a
365// new zero-byte to make the significant byte < 0x80 again.
366
367// - If the most significant byte is >= 0x80 and the value is negative, push a
368// new 0x80 byte that will be popped off when converting to an integral.
369
370// - If the most significant byte is < 0x80 and the value is negative, add
371// 0x80 to it, since it will be subtracted and interpreted as a negative when
372// converting to an integral.
373
374 if (result.back() & 0x80)
375 result.push_back(neg ? 0x80 : 0);
376 else if (neg)
377 result.back() |= 0x80;
378
379 return result;
380 }
381
382private:
383 static int64_t set_vch(const std::vector<unsigned char>& vch)
384 {
385 if (vch.empty())
386 return 0;
387
388 int64_t result = 0;
389 for (size_t i = 0; i != vch.size(); ++i)
390 result |= static_cast<int64_t>(vch[i]) << 8*i;
391
392 // If the input vector's most significant byte is 0x80, remove it from
393 // the result's msb and return a negative.
394 if (vch.back() & 0x80)
395 return -((int64_t)(result & ~(0x80ULL << (8 * (vch.size() - 1)))));
396
397 return result;
398 }
399
400 int64_t m_value;
401};
402
410
411bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator end, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet);
412
414class CScript : public CScriptBase
415{
416private:
417 inline void AppendDataSize(const uint32_t size)
418 {
419 if (size < OP_PUSHDATA1) {
420 insert(end(), static_cast<value_type>(size));
421 } else if (size <= 0xff) {
423 insert(end(), static_cast<value_type>(size));
424 } else if (size <= 0xffff) {
426 value_type data[2];
428 insert(end(), std::cbegin(data), std::cend(data));
429 } else {
431 value_type data[4];
433 insert(end(), std::cbegin(data), std::cend(data));
434 }
435 }
436
437 void AppendData(std::span<const value_type> data)
438 {
439 insert(end(), data.begin(), data.end());
440 }
441
442protected:
443 CScript& push_int64(int64_t n)
444 {
445 if (n == -1 || (n >= 1 && n <= 16))
446 {
447 push_back(n + (OP_1 - 1));
448 }
449 else if (n == 0)
450 {
452 }
453 else
454 {
455 *this << CScriptNum::serialize(n);
456 }
457 return *this;
458 }
459
460public:
461 CScript() = default;
462 template <std::input_iterator InputIterator>
463 CScript(InputIterator first, InputIterator last) : CScriptBase{first, last} { }
464
465 SERIALIZE_METHODS(CScript, obj) { READWRITE(AsBase<CScriptBase>(obj)); }
466
467 explicit CScript(int64_t b) { operator<<(b); }
468 explicit CScript(opcodetype b) { operator<<(b); }
469 explicit CScript(const CScriptNum& b) { operator<<(b); }
470 // delete non-existent constructor to defend against future introduction
471 // e.g. via prevector
472 explicit CScript(const std::vector<unsigned char>& b) = delete;
473
475 CScript& operator<<(const CScript& b) = delete;
476
477 CScript& operator<<(int64_t b) LIFETIMEBOUND { return push_int64(b); }
478
480 {
481 if (opcode < 0 || opcode > 0xff)
482 throw std::runtime_error("CScript::operator<<(): invalid opcode");
483 insert(end(), (unsigned char)opcode);
484 return *this;
485 }
486
488 {
489 *this << b.getvch();
490 return *this;
491 }
492
493 CScript& operator<<(std::span<const std::byte> b) LIFETIMEBOUND
494 {
495 AppendDataSize(b.size());
496 AppendData({reinterpret_cast<const value_type*>(b.data()), b.size()});
497 return *this;
498 }
499
500 // For compatibility reasons. In new code, prefer using std::byte instead of uint8_t.
501 CScript& operator<<(std::span<const value_type> b) LIFETIMEBOUND
502 {
503 return *this << std::as_bytes(b);
504 }
505
506 bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
507 {
508 return GetScriptOp(pc, end(), opcodeRet, &vchRet);
509 }
510
511 bool GetOp(const_iterator& pc, opcodetype& opcodeRet) const
512 {
513 return GetScriptOp(pc, end(), opcodeRet, nullptr);
514 }
515
517 static int DecodeOP_N(opcodetype opcode)
518 {
519 if (opcode == OP_0)
520 return 0;
521 assert(opcode >= OP_1 && opcode <= OP_16);
522 return (int)opcode - (int)(OP_1 - 1);
523 }
524 static opcodetype EncodeOP_N(int n)
525 {
526 assert(n >= 0 && n <= 16);
527 if (n == 0)
528 return OP_0;
529 return (opcodetype)(OP_1+n-1);
530 }
531
539 unsigned int GetSigOpCount(bool fAccurate) const;
540
545 unsigned int GetSigOpCount(const CScript& scriptSig) const;
546
547 /*
548 * OP_1 <0x4e73>
549 */
550 bool IsPayToAnchor() const;
553 static bool IsPayToAnchor(int version, const std::vector<unsigned char>& program);
554
555 bool IsPayToScriptHash() const;
556 bool IsPayToWitnessScriptHash() const;
557 bool IsWitnessProgram(int& version, std::vector<unsigned char>& program) const;
558
560 bool IsPushOnly(const_iterator pc) const;
561 bool IsPushOnly() const;
562
564 bool HasValidOps() const;
565
571 bool IsUnspendable() const
572 {
573 return (size() > 0 && *begin() == OP_RETURN) || (size() > MAX_SCRIPT_SIZE);
574 }
575
576 void clear()
577 {
578 // The default prevector::clear() does not release memory
581 }
582};
583
585{
586 // Note that this encodes the data elements being pushed, rather than
587 // encoding them as a CScript that pushes them.
588 std::vector<std::vector<unsigned char> > stack;
589
590 // Some compilers complain without a default constructor
591 CScriptWitness() = default;
592
593 bool IsNull() const { return stack.empty(); }
594
595 void SetNull() { stack.clear(); stack.shrink_to_fit(); }
596
597 std::string ToString() const;
598};
599
601class CScriptID : public BaseHash<uint160>
602{
603public:
605 explicit CScriptID(const CScript& in);
606 explicit CScriptID(const uint160& in) : BaseHash(in) {}
607};
608
610bool IsOpSuccess(const opcodetype& opcode);
611
612bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode);
613
615template<typename... Ts>
616CScript BuildScript(Ts&&... inputs)
617{
618 CScript ret;
619 int cnt{0};
620
621 ([&ret, &cnt] (Ts&& input) {
622 if constexpr (std::is_same_v<std::remove_cv_t<std::remove_reference_t<Ts>>, CScript>) {
623 // If it is a CScript, extend ret with it. Move or copy the first element instead.
624 if (cnt == 0) {
625 ret = std::forward<Ts>(input);
626 } else {
627 ret.insert(ret.end(), input.begin(), input.end());
628 }
629 } else {
630 // Otherwise invoke CScript::operator<<.
631 ret << input;
632 }
633 cnt++;
634 } (std::forward<Ts>(inputs)), ...);
635
636 return ret;
637}
638
639#endif // BITCOIN_SCRIPT_SCRIPT_H
#define LIFETIMEBOUND
Definition: attributes.h:16
int ret
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:415
bool IsPayToScriptHash() const
Definition: script.cpp:224
CScript(InputIterator first, InputIterator last)
Definition: script.h:463
bool IsUnspendable() const
Returns whether the script is guaranteed to fail at execution, regardless of the initial stack.
Definition: script.h:571
CScript()=default
CScript & operator<<(const CScript &b)=delete
Delete non-existent operator to defend against future introduction.
CScript(const CScriptNum &b)
Definition: script.h:469
void AppendData(std::span< const value_type > data)
Definition: script.h:437
CScript & push_int64(int64_t n)
Definition: script.h:443
CScript(int64_t b)
Definition: script.h:467
SERIALIZE_METHODS(CScript, obj)
Definition: script.h:465
CScript & operator<<(std::span< const value_type > b) LIFETIMEBOUND
Definition: script.h:501
void clear()
Definition: script.h:576
static int DecodeOP_N(opcodetype opcode)
Encode/decode small integers:
Definition: script.h:517
bool IsPushOnly() const
Definition: script.cpp:276
CScript(opcodetype b)
Definition: script.h:468
bool IsPayToWitnessScriptHash() const
Definition: script.cpp:233
void AppendDataSize(const uint32_t size)
Definition: script.h:417
unsigned int GetSigOpCount(bool fAccurate) const
Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs as 20 sigops.
Definition: script.cpp:159
bool HasValidOps() const
Check if the script contains valid OP_CODES.
Definition: script.cpp:293
CScript(const std::vector< unsigned char > &b)=delete
bool GetOp(const_iterator &pc, opcodetype &opcodeRet) const
Definition: script.h:511
CScript & operator<<(opcodetype opcode) LIFETIMEBOUND
Definition: script.h:479
CScript & operator<<(const CScriptNum &b) LIFETIMEBOUND
Definition: script.h:487
CScript & operator<<(std::span< const std::byte > b) LIFETIMEBOUND
Definition: script.h:493
bool IsPayToAnchor() const
Definition: script.cpp:207
bool GetOp(const_iterator &pc, opcodetype &opcodeRet, std::vector< unsigned char > &vchRet) const
Definition: script.h:506
bool IsWitnessProgram(int &version, std::vector< unsigned char > &program) const
Definition: script.cpp:243
CScript & operator<<(int64_t b) LIFETIMEBOUND
Definition: script.h:477
static opcodetype EncodeOP_N(int n)
Definition: script.h:524
A reference to a CScript: the Hash160 of its serialization.
Definition: script.h:602
CScriptID()
Definition: script.h:604
CScriptID(const uint160 &in)
Definition: script.h:606
int64_t m_value
Definition: script.h:400
static std::vector< unsigned char > serialize(const int64_t &value)
Definition: script.h:349
CScriptNum & operator-=(const CScriptNum &rhs)
Definition: script.h:292
CScriptNum & operator-=(const int64_t &rhs)
Definition: script.h:319
CScriptNum operator-(const int64_t &rhs) const
Definition: script.h:287
CScriptNum operator+(const int64_t &rhs) const
Definition: script.h:286
CScriptNum & operator+=(const CScriptNum &rhs)
Definition: script.h:291
CScriptNum operator-(const CScriptNum &rhs) const
Definition: script.h:289
bool operator==(const CScriptNum &rhs) const
Definition: script.h:279
CScriptNum & operator&=(const CScriptNum &rhs)
Definition: script.h:297
bool operator<=(const CScriptNum &rhs) const
Definition: script.h:281
bool operator==(const int64_t &rhs) const
Definition: script.h:272
bool operator<(const int64_t &rhs) const
Definition: script.h:275
CScriptNum(const std::vector< unsigned char > &vch, bool fRequireMinimal, const size_t nMaxNumSize=nDefaultMaxNumSize)
Definition: script.h:245
std::vector< unsigned char > getvch() const
Definition: script.h:344
static const size_t nDefaultMaxNumSize
Definition: script.h:243
CScriptNum operator&(const int64_t &rhs) const
Definition: script.h:294
CScriptNum operator&(const CScriptNum &rhs) const
Definition: script.h:295
CScriptNum & operator+=(const int64_t &rhs)
Definition: script.h:311
bool operator>=(const int64_t &rhs) const
Definition: script.h:276
bool operator<=(const int64_t &rhs) const
Definition: script.h:274
CScriptNum(const int64_t &n)
Numeric opcodes (OP_1ADD, etc) are restricted to operating on 4-byte integers.
Definition: script.h:238
int64_t GetInt64() const
Definition: script.h:342
bool operator!=(const int64_t &rhs) const
Definition: script.h:273
bool operator>=(const CScriptNum &rhs) const
Definition: script.h:283
bool operator>(const int64_t &rhs) const
Definition: script.h:277
static int64_t set_vch(const std::vector< unsigned char > &vch)
Definition: script.h:383
CScriptNum & operator&=(const int64_t &rhs)
Definition: script.h:327
int getint() const
Definition: script.h:333
CScriptNum operator-() const
Definition: script.h:299
bool operator!=(const CScriptNum &rhs) const
Definition: script.h:280
CScriptNum & operator=(const int64_t &rhs)
Definition: script.h:305
CScriptNum operator+(const CScriptNum &rhs) const
Definition: script.h:288
Implements a drop-in replacement for std::vector<T> which stores up to N elements directly (without h...
Definition: prevector.h:37
void shrink_to_fit()
Definition: prevector.h:351
void clear()
Definition: prevector.h:355
size_type size() const
Definition: prevector.h:294
value_type * data()
Definition: prevector.h:533
iterator begin()
Definition: prevector.h:302
T value_type
Definition: prevector.h:43
iterator end()
Definition: prevector.h:304
iterator insert(iterator pos, const T &value)
Definition: prevector.h:359
void push_back(const T &value)
Definition: prevector.h:444
scriptnum_error(const std::string &str)
Definition: script.h:223
160-bit opaque blob.
Definition: uint256.h:178
static void WriteLE16(unsigned char *ptr, uint16_t x)
Definition: common.h:34
static void WriteLE32(unsigned char *ptr, uint32_t x)
Definition: common.h:40
static constexpr int64_t VALIDATION_WEIGHT_PER_SIGOP_PASSED
Definition: script.h:61
static const unsigned int LOCKTIME_THRESHOLD
Definition: script.h:47
static const unsigned int MAX_OPCODE
Definition: script.h:216
std::string GetOpName(opcodetype opcode)
Definition: script.cpp:18
prevector< 28, unsigned char > CScriptBase
We use a prevector for the script to reduce the considerable memory overhead of vectors in cases wher...
Definition: script.h:409
bool CheckMinimalPush(const std::vector< unsigned char > &data, opcodetype opcode)
Definition: script.cpp:366
static const unsigned int MAX_SCRIPT_ELEMENT_SIZE
Definition: script.h:28
static const int MAX_SCRIPT_SIZE
Definition: script.h:40
opcodetype
Script opcodes.
Definition: script.h:74
@ OP_NUMNOTEQUAL
Definition: script.h:173
@ OP_RESERVED1
Definition: script.h:148
@ OP_2
Definition: script.h:85
@ OP_SHA256
Definition: script.h:186
@ OP_PUSHDATA4
Definition: script.h:80
@ OP_NOP5
Definition: script.h:202
@ OP_RIGHT
Definition: script.h:138
@ OP_BOOLAND
Definition: script.h:169
@ OP_CHECKMULTISIG
Definition: script.h:192
@ OP_NEGATE
Definition: script.h:156
@ OP_IF
Definition: script.h:104
@ OP_13
Definition: script.h:96
@ OP_ROT
Definition: script.h:130
@ OP_SWAP
Definition: script.h:131
@ OP_1NEGATE
Definition: script.h:81
@ OP_VERNOTIF
Definition: script.h:107
@ OP_CHECKSIG
Definition: script.h:190
@ OP_CHECKLOCKTIMEVERIFY
Definition: script.h:197
@ OP_LESSTHAN
Definition: script.h:174
@ OP_16
Definition: script.h:99
@ OP_LEFT
Definition: script.h:137
@ OP_14
Definition: script.h:97
@ OP_NOP10
Definition: script.h:207
@ OP_2DIV
Definition: script.h:155
@ OP_INVALIDOPCODE
Definition: script.h:212
@ OP_NOT
Definition: script.h:158
@ OP_EQUAL
Definition: script.h:146
@ OP_NUMEQUAL
Definition: script.h:171
@ OP_MOD
Definition: script.h:165
@ OP_NOTIF
Definition: script.h:105
@ OP_4
Definition: script.h:87
@ OP_10
Definition: script.h:93
@ OP_SIZE
Definition: script.h:139
@ OP_3DUP
Definition: script.h:118
@ OP_ENDIF
Definition: script.h:109
@ OP_NOP1
Definition: script.h:196
@ OP_DUP
Definition: script.h:125
@ OP_GREATERTHAN
Definition: script.h:175
@ OP_NOP
Definition: script.h:102
@ OP_NOP2
Definition: script.h:198
@ OP_VERIF
Definition: script.h:106
@ OP_TOALTSTACK
Definition: script.h:114
@ OP_CODESEPARATOR
Definition: script.h:189
@ OP_RIPEMD160
Definition: script.h:184
@ OP_MIN
Definition: script.h:178
@ OP_HASH256
Definition: script.h:188
@ OP_MAX
Definition: script.h:179
@ OP_1SUB
Definition: script.h:153
@ OP_FROMALTSTACK
Definition: script.h:115
@ OP_SUB
Definition: script.h:162
@ OP_FALSE
Definition: script.h:77
@ OP_NUMEQUALVERIFY
Definition: script.h:172
@ OP_OVER
Definition: script.h:127
@ OP_NOP8
Definition: script.h:205
@ OP_DIV
Definition: script.h:164
@ OP_HASH160
Definition: script.h:187
@ OP_2DUP
Definition: script.h:117
@ OP_NIP
Definition: script.h:126
@ OP_2MUL
Definition: script.h:154
@ OP_NOP4
Definition: script.h:201
@ OP_NOP3
Definition: script.h:200
@ OP_1
Definition: script.h:83
@ OP_LESSTHANOREQUAL
Definition: script.h:176
@ OP_2DROP
Definition: script.h:116
@ OP_TRUE
Definition: script.h:84
@ OP_DEPTH
Definition: script.h:123
@ OP_NOP9
Definition: script.h:206
@ OP_VER
Definition: script.h:103
@ OP_VERIFY
Definition: script.h:110
@ OP_RESERVED2
Definition: script.h:149
@ OP_12
Definition: script.h:95
@ OP_ADD
Definition: script.h:161
@ OP_CHECKMULTISIGVERIFY
Definition: script.h:193
@ OP_NOP7
Definition: script.h:204
@ OP_8
Definition: script.h:91
@ OP_BOOLOR
Definition: script.h:170
@ OP_XOR
Definition: script.h:145
@ OP_DROP
Definition: script.h:124
@ OP_MUL
Definition: script.h:163
@ OP_WITHIN
Definition: script.h:181
@ OP_CHECKSIGADD
Definition: script.h:210
@ OP_ELSE
Definition: script.h:108
@ OP_15
Definition: script.h:98
@ OP_CHECKSIGVERIFY
Definition: script.h:191
@ OP_PUSHDATA1
Definition: script.h:78
@ OP_TUCK
Definition: script.h:132
@ OP_2OVER
Definition: script.h:119
@ OP_0NOTEQUAL
Definition: script.h:159
@ OP_9
Definition: script.h:92
@ OP_3
Definition: script.h:86
@ OP_11
Definition: script.h:94
@ OP_SHA1
Definition: script.h:185
@ OP_SUBSTR
Definition: script.h:136
@ OP_GREATERTHANOREQUAL
Definition: script.h:177
@ OP_RSHIFT
Definition: script.h:167
@ OP_2SWAP
Definition: script.h:121
@ OP_PUSHDATA2
Definition: script.h:79
@ OP_2ROT
Definition: script.h:120
@ OP_6
Definition: script.h:89
@ OP_INVERT
Definition: script.h:142
@ OP_0
Definition: script.h:76
@ OP_ABS
Definition: script.h:157
@ OP_LSHIFT
Definition: script.h:166
@ OP_RETURN
Definition: script.h:111
@ OP_IFDUP
Definition: script.h:122
@ OP_PICK
Definition: script.h:128
@ OP_AND
Definition: script.h:143
@ OP_EQUALVERIFY
Definition: script.h:147
@ OP_CAT
Definition: script.h:135
@ OP_RESERVED
Definition: script.h:82
@ OP_1ADD
Definition: script.h:152
@ OP_7
Definition: script.h:90
@ OP_OR
Definition: script.h:144
@ OP_ROLL
Definition: script.h:129
@ OP_NOP6
Definition: script.h:203
@ OP_5
Definition: script.h:88
@ OP_CHECKSEQUENCEVERIFY
Definition: script.h:199
static constexpr unsigned int MAX_PUBKEYS_PER_MULTI_A
The limit of keys in OP_CHECKSIGADD-based scripts.
Definition: script.h:37
bool GetScriptOp(CScriptBase::const_iterator &pc, CScriptBase::const_iterator end, opcodetype &opcodeRet, std::vector< unsigned char > *pvchRet)
Definition: script.cpp:306
static const int MAX_STACK_SIZE
Definition: script.h:43
bool IsOpSuccess(const opcodetype &opcode)
Test for OP_SUCCESSx opcodes as defined by BIP342.
Definition: script.cpp:358
static const int MAX_OPS_PER_SCRIPT
Definition: script.h:31
static constexpr int64_t VALIDATION_WEIGHT_OFFSET
Definition: script.h:64
CScript BuildScript(Ts &&... inputs)
Build a script by concatenating other scripts, or any argument accepted by CScript::operator<<.
Definition: script.h:616
static const int MAX_PUBKEYS_PER_MULTISIG
Definition: script.h:34
std::vector< unsigned char > ToByteVector(const T &in)
Definition: script.h:67
static const uint32_t LOCKTIME_MAX
Definition: script.h:53
static constexpr unsigned int ANNEX_TAG
Definition: script.h:58
#define READWRITE(...)
Definition: serialize.h:156
CScriptWitness()=default
std::string ToString() const
Definition: script.cpp:281
std::vector< std::vector< unsigned char > > stack
Definition: script.h:588
bool IsNull() const
Definition: script.h:593
void SetNull()
Definition: script.h:595
assert(!tx.IsCoinBase())