LCOV - code coverage report
Current view: top level - src/script - script.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 260 286 90.9 %
Date: 2022-04-21 14:51:19 Functions: 13 13 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 345 372 92.7 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
#       2                 :            : // Copyright (c) 2009-2020 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                 :            : #include <script/script.h>
#       7                 :            : 
#       8                 :            : #include <util/strencodings.h>
#       9                 :            : 
#      10                 :            : #include <string>
#      11                 :            : 
#      12                 :            : std::string GetOpName(opcodetype opcode)
#      13                 :      23118 : {
#      14                 :      23118 :     switch (opcode)
#      15                 :      23118 :     {
#      16                 :            :     // push value
#      17         [ -  + ]:          0 :     case OP_0                      : return "0";
#      18         [ -  + ]:          0 :     case OP_PUSHDATA1              : return "OP_PUSHDATA1";
#      19         [ -  + ]:          0 :     case OP_PUSHDATA2              : return "OP_PUSHDATA2";
#      20         [ -  + ]:          0 :     case OP_PUSHDATA4              : return "OP_PUSHDATA4";
#      21         [ -  + ]:          0 :     case OP_1NEGATE                : return "-1";
#      22         [ +  + ]:          3 :     case OP_RESERVED               : return "OP_RESERVED";
#      23         [ +  + ]:       4119 :     case OP_1                      : return "1";
#      24         [ +  + ]:        151 :     case OP_2                      : return "2";
#      25         [ +  + ]:         13 :     case OP_3                      : return "3";
#      26         [ -  + ]:          0 :     case OP_4                      : return "4";
#      27         [ -  + ]:          0 :     case OP_5                      : return "5";
#      28         [ -  + ]:          0 :     case OP_6                      : return "6";
#      29         [ -  + ]:          0 :     case OP_7                      : return "7";
#      30         [ -  + ]:          0 :     case OP_8                      : return "8";
#      31         [ -  + ]:          0 :     case OP_9                      : return "9";
#      32         [ -  + ]:          0 :     case OP_10                     : return "10";
#      33         [ -  + ]:          0 :     case OP_11                     : return "11";
#      34         [ -  + ]:          0 :     case OP_12                     : return "12";
#      35         [ -  + ]:          0 :     case OP_13                     : return "13";
#      36         [ -  + ]:          0 :     case OP_14                     : return "14";
#      37         [ -  + ]:          0 :     case OP_15                     : return "15";
#      38         [ -  + ]:          0 :     case OP_16                     : return "16";
#      39                 :            : 
#      40                 :            :     // control
#      41         [ +  + ]:          2 :     case OP_NOP                    : return "OP_NOP";
#      42         [ +  + ]:          2 :     case OP_VER                    : return "OP_VER";
#      43         [ +  + ]:          3 :     case OP_IF                     : return "OP_IF";
#      44         [ +  + ]:          2 :     case OP_NOTIF                  : return "OP_NOTIF";
#      45         [ +  + ]:          2 :     case OP_VERIF                  : return "OP_VERIF";
#      46         [ +  + ]:          2 :     case OP_VERNOTIF               : return "OP_VERNOTIF";
#      47         [ +  + ]:          3 :     case OP_ELSE                   : return "OP_ELSE";
#      48         [ +  + ]:          3 :     case OP_ENDIF                  : return "OP_ENDIF";
#      49         [ +  + ]:          2 :     case OP_VERIFY                 : return "OP_VERIFY";
#      50         [ +  + ]:      14899 :     case OP_RETURN                 : return "OP_RETURN";
#      51                 :            : 
#      52                 :            :     // stack ops
#      53         [ +  + ]:          2 :     case OP_TOALTSTACK             : return "OP_TOALTSTACK";
#      54         [ +  + ]:          2 :     case OP_FROMALTSTACK           : return "OP_FROMALTSTACK";
#      55         [ +  + ]:          2 :     case OP_2DROP                  : return "OP_2DROP";
#      56         [ +  + ]:          2 :     case OP_2DUP                   : return "OP_2DUP";
#      57         [ +  + ]:          2 :     case OP_3DUP                   : return "OP_3DUP";
#      58         [ +  + ]:          2 :     case OP_2OVER                  : return "OP_2OVER";
#      59         [ +  + ]:          2 :     case OP_2ROT                   : return "OP_2ROT";
#      60         [ +  + ]:          2 :     case OP_2SWAP                  : return "OP_2SWAP";
#      61         [ +  + ]:          2 :     case OP_IFDUP                  : return "OP_IFDUP";
#      62         [ +  + ]:          2 :     case OP_DEPTH                  : return "OP_DEPTH";
#      63         [ +  + ]:         18 :     case OP_DROP                   : return "OP_DROP";
#      64         [ +  + ]:        500 :     case OP_DUP                    : return "OP_DUP";
#      65         [ +  + ]:          2 :     case OP_NIP                    : return "OP_NIP";
#      66         [ +  + ]:          2 :     case OP_OVER                   : return "OP_OVER";
#      67         [ +  + ]:          2 :     case OP_PICK                   : return "OP_PICK";
#      68         [ +  + ]:          2 :     case OP_ROLL                   : return "OP_ROLL";
#      69         [ +  + ]:          2 :     case OP_ROT                    : return "OP_ROT";
#      70         [ +  + ]:          2 :     case OP_SWAP                   : return "OP_SWAP";
#      71         [ +  + ]:          2 :     case OP_TUCK                   : return "OP_TUCK";
#      72                 :            : 
#      73                 :            :     // splice ops
#      74         [ +  + ]:          2 :     case OP_CAT                    : return "OP_CAT";
#      75         [ +  + ]:          2 :     case OP_SUBSTR                 : return "OP_SUBSTR";
#      76         [ +  + ]:          2 :     case OP_LEFT                   : return "OP_LEFT";
#      77         [ +  + ]:          2 :     case OP_RIGHT                  : return "OP_RIGHT";
#      78         [ +  + ]:          2 :     case OP_SIZE                   : return "OP_SIZE";
#      79                 :            : 
#      80                 :            :     // bit logic
#      81         [ +  + ]:          2 :     case OP_INVERT                 : return "OP_INVERT";
#      82         [ +  + ]:          2 :     case OP_AND                    : return "OP_AND";
#      83         [ +  + ]:          2 :     case OP_OR                     : return "OP_OR";
#      84         [ +  + ]:          2 :     case OP_XOR                    : return "OP_XOR";
#      85         [ +  + ]:        563 :     case OP_EQUAL                  : return "OP_EQUAL";
#      86         [ +  + ]:        496 :     case OP_EQUALVERIFY            : return "OP_EQUALVERIFY";
#      87         [ +  + ]:          2 :     case OP_RESERVED1              : return "OP_RESERVED1";
#      88         [ +  + ]:          2 :     case OP_RESERVED2              : return "OP_RESERVED2";
#      89                 :            : 
#      90                 :            :     // numeric
#      91         [ +  + ]:          2 :     case OP_1ADD                   : return "OP_1ADD";
#      92         [ +  + ]:          2 :     case OP_1SUB                   : return "OP_1SUB";
#      93         [ +  + ]:          2 :     case OP_2MUL                   : return "OP_2MUL";
#      94         [ +  + ]:          2 :     case OP_2DIV                   : return "OP_2DIV";
#      95         [ +  + ]:          2 :     case OP_NEGATE                 : return "OP_NEGATE";
#      96         [ +  + ]:          2 :     case OP_ABS                    : return "OP_ABS";
#      97         [ +  + ]:         50 :     case OP_NOT                    : return "OP_NOT";
#      98         [ +  + ]:          2 :     case OP_0NOTEQUAL              : return "OP_0NOTEQUAL";
#      99         [ +  + ]:          2 :     case OP_ADD                    : return "OP_ADD";
#     100         [ +  + ]:          2 :     case OP_SUB                    : return "OP_SUB";
#     101         [ +  + ]:          2 :     case OP_MUL                    : return "OP_MUL";
#     102         [ +  + ]:          2 :     case OP_DIV                    : return "OP_DIV";
#     103         [ +  + ]:          2 :     case OP_MOD                    : return "OP_MOD";
#     104         [ +  + ]:          2 :     case OP_LSHIFT                 : return "OP_LSHIFT";
#     105         [ +  + ]:          2 :     case OP_RSHIFT                 : return "OP_RSHIFT";
#     106         [ +  + ]:          2 :     case OP_BOOLAND                : return "OP_BOOLAND";
#     107         [ +  + ]:          2 :     case OP_BOOLOR                 : return "OP_BOOLOR";
#     108         [ +  + ]:          2 :     case OP_NUMEQUAL               : return "OP_NUMEQUAL";
#     109         [ +  + ]:          2 :     case OP_NUMEQUALVERIFY         : return "OP_NUMEQUALVERIFY";
#     110         [ +  + ]:          2 :     case OP_NUMNOTEQUAL            : return "OP_NUMNOTEQUAL";
#     111         [ +  + ]:          2 :     case OP_LESSTHAN               : return "OP_LESSTHAN";
#     112         [ +  + ]:          2 :     case OP_GREATERTHAN            : return "OP_GREATERTHAN";
#     113         [ +  + ]:          2 :     case OP_LESSTHANOREQUAL        : return "OP_LESSTHANOREQUAL";
#     114         [ +  + ]:          2 :     case OP_GREATERTHANOREQUAL     : return "OP_GREATERTHANOREQUAL";
#     115         [ +  + ]:          2 :     case OP_MIN                    : return "OP_MIN";
#     116         [ +  + ]:          2 :     case OP_MAX                    : return "OP_MAX";
#     117         [ +  + ]:          2 :     case OP_WITHIN                 : return "OP_WITHIN";
#     118                 :            : 
#     119                 :            :     // crypto
#     120         [ +  + ]:          2 :     case OP_RIPEMD160              : return "OP_RIPEMD160";
#     121         [ +  + ]:          2 :     case OP_SHA1                   : return "OP_SHA1";
#     122         [ +  + ]:          2 :     case OP_SHA256                 : return "OP_SHA256";
#     123         [ +  + ]:       1057 :     case OP_HASH160                : return "OP_HASH160";
#     124         [ +  + ]:          2 :     case OP_HASH256                : return "OP_HASH256";
#     125         [ +  + ]:          2 :     case OP_CODESEPARATOR          : return "OP_CODESEPARATOR";
#     126         [ +  + ]:        938 :     case OP_CHECKSIG               : return "OP_CHECKSIG";
#     127         [ +  + ]:          3 :     case OP_CHECKSIGVERIFY         : return "OP_CHECKSIGVERIFY";
#     128         [ +  + ]:        128 :     case OP_CHECKMULTISIG          : return "OP_CHECKMULTISIG";
#     129         [ +  + ]:          2 :     case OP_CHECKMULTISIGVERIFY    : return "OP_CHECKMULTISIGVERIFY";
#     130                 :            : 
#     131                 :            :     // expansion
#     132         [ +  + ]:          2 :     case OP_NOP1                   : return "OP_NOP1";
#     133         [ +  + ]:         11 :     case OP_CHECKLOCKTIMEVERIFY    : return "OP_CHECKLOCKTIMEVERIFY";
#     134         [ +  + ]:          2 :     case OP_CHECKSEQUENCEVERIFY    : return "OP_CHECKSEQUENCEVERIFY";
#     135         [ +  + ]:          2 :     case OP_NOP4                   : return "OP_NOP4";
#     136         [ +  + ]:          2 :     case OP_NOP5                   : return "OP_NOP5";
#     137         [ +  + ]:          2 :     case OP_NOP6                   : return "OP_NOP6";
#     138         [ +  + ]:          2 :     case OP_NOP7                   : return "OP_NOP7";
#     139         [ +  + ]:         10 :     case OP_NOP8                   : return "OP_NOP8";
#     140         [ +  + ]:          2 :     case OP_NOP9                   : return "OP_NOP9";
#     141         [ +  + ]:          2 :     case OP_NOP10                  : return "OP_NOP10";
#     142                 :            : 
#     143                 :            :     // Opcode added by BIP 342 (Tapscript)
#     144         [ +  + ]:          1 :     case OP_CHECKSIGADD            : return "OP_CHECKSIGADD";
#     145                 :            : 
#     146         [ -  + ]:          0 :     case OP_INVALIDOPCODE          : return "OP_INVALIDOPCODE";
#     147                 :            : 
#     148         [ +  + ]:          1 :     default:
#     149                 :          1 :         return "OP_UNKNOWN";
#     150                 :      23118 :     }
#     151                 :      23118 : }
#     152                 :            : 
#     153                 :            : unsigned int CScript::GetSigOpCount(bool fAccurate) const
#     154                 :    1931779 : {
#     155                 :    1931779 :     unsigned int n = 0;
#     156                 :    1931779 :     const_iterator pc = begin();
#     157                 :    1931779 :     opcodetype lastOpcode = OP_INVALIDOPCODE;
#     158         [ +  + ]:  299314160 :     while (pc < end())
#     159                 :  297384250 :     {
#     160                 :  297384250 :         opcodetype opcode;
#     161         [ +  + ]:  297384250 :         if (!GetOp(pc, opcode))
#     162                 :       1869 :             break;
#     163 [ +  + ][ +  + ]:  297382381 :         if (opcode == OP_CHECKSIG || opcode == OP_CHECKSIGVERIFY)
#     164                 :  263697653 :             n++;
#     165 [ +  + ][ +  + ]:   33684728 :         else if (opcode == OP_CHECKMULTISIG || opcode == OP_CHECKMULTISIGVERIFY)
#     166                 :      26873 :         {
#     167 [ +  + ][ +  + ]:      26873 :             if (fAccurate && lastOpcode >= OP_1 && lastOpcode <= OP_16)
#                 [ +  + ]
#     168                 :       1207 :                 n += DecodeOP_N(lastOpcode);
#     169                 :      25666 :             else
#     170                 :      25666 :                 n += MAX_PUBKEYS_PER_MULTISIG;
#     171                 :      26873 :         }
#     172                 :  297382381 :         lastOpcode = opcode;
#     173                 :  297382381 :     }
#     174                 :    1931779 :     return n;
#     175                 :    1931779 : }
#     176                 :            : 
#     177                 :            : unsigned int CScript::GetSigOpCount(const CScript& scriptSig) const
#     178                 :      10152 : {
#     179         [ -  + ]:      10152 :     if (!IsPayToScriptHash())
#     180                 :          0 :         return GetSigOpCount(true);
#     181                 :            : 
#     182                 :            :     // This is a pay-to-script-hash scriptPubKey;
#     183                 :            :     // get the last item that the scriptSig
#     184                 :            :     // pushes onto the stack:
#     185                 :      10152 :     const_iterator pc = scriptSig.begin();
#     186                 :      10152 :     std::vector<unsigned char> vData;
#     187         [ +  + ]:      28237 :     while (pc < scriptSig.end())
#     188                 :      18085 :     {
#     189                 :      18085 :         opcodetype opcode;
#     190         [ -  + ]:      18085 :         if (!scriptSig.GetOp(pc, opcode, vData))
#     191                 :          0 :             return 0;
#     192         [ -  + ]:      18085 :         if (opcode > OP_16)
#     193                 :          0 :             return 0;
#     194                 :      18085 :     }
#     195                 :            : 
#     196                 :            :     /// ... and return its opcount:
#     197                 :      10152 :     CScript subscript(vData.begin(), vData.end());
#     198                 :      10152 :     return subscript.GetSigOpCount(true);
#     199                 :      10152 : }
#     200                 :            : 
#     201                 :            : bool CScript::IsPayToScriptHash() const
#     202                 :    6563009 : {
#     203                 :            :     // Extra-fast test for pay-to-script-hash CScripts:
#     204         [ +  + ]:    6563009 :     return (this->size() == 23 &&
#     205         [ +  + ]:    6563009 :             (*this)[0] == OP_HASH160 &&
#     206         [ +  + ]:    6563009 :             (*this)[1] == 0x14 &&
#     207         [ +  + ]:    6563009 :             (*this)[22] == OP_EQUAL);
#     208                 :    6563009 : }
#     209                 :            : 
#     210                 :            : bool CScript::IsPayToWitnessScriptHash() const
#     211                 :      25471 : {
#     212                 :            :     // Extra-fast test for pay-to-witness-script-hash CScripts:
#     213         [ +  + ]:      25471 :     return (this->size() == 34 &&
#     214         [ +  + ]:      25471 :             (*this)[0] == OP_0 &&
#     215         [ +  - ]:      25471 :             (*this)[1] == 0x20);
#     216                 :      25471 : }
#     217                 :            : 
#     218                 :            : // A witness program is any valid CScript that consists of a 1-byte push opcode
#     219                 :            : // followed by a data push between 2 and 40 bytes.
#     220                 :            : bool CScript::IsWitnessProgram(int& version, std::vector<unsigned char>& program) const
#     221                 :    6524431 : {
#     222 [ +  + ][ +  + ]:    6524431 :     if (this->size() < 4 || this->size() > 42) {
#     223                 :     197131 :         return false;
#     224                 :     197131 :     }
#     225 [ +  + ][ +  + ]:    6327300 :     if ((*this)[0] != OP_0 && ((*this)[0] < OP_1 || (*this)[0] > OP_16)) {
#                 [ +  + ]
#     226                 :    2997632 :         return false;
#     227                 :    2997632 :     }
#     228         [ +  + ]:    3329668 :     if ((size_t)((*this)[1] + 2) == this->size()) {
#     229                 :    3326430 :         version = DecodeOP_N((opcodetype)(*this)[0]);
#     230                 :    3326430 :         program = std::vector<unsigned char>(this->begin() + 2, this->end());
#     231                 :    3326430 :         return true;
#     232                 :    3326430 :     }
#     233                 :       3238 :     return false;
#     234                 :    3329668 : }
#     235                 :            : 
#     236                 :            : bool CScript::IsPushOnly(const_iterator pc) const
#     237                 :     769944 : {
#     238         [ +  + ]:   27718308 :     while (pc < end())
#     239                 :   26950103 :     {
#     240                 :   26950103 :         opcodetype opcode;
#     241         [ +  + ]:   26950103 :         if (!GetOp(pc, opcode))
#     242                 :         43 :             return false;
#     243                 :            :         // Note that IsPushOnly() *does* consider OP_RESERVED to be a
#     244                 :            :         // push-type opcode, however execution of OP_RESERVED fails, so
#     245                 :            :         // it's not relevant to P2SH/BIP62 as the scriptSig would fail prior to
#     246                 :            :         // the P2SH special validation code being executed.
#     247         [ +  + ]:   26950060 :         if (opcode > OP_16)
#     248                 :       1696 :             return false;
#     249                 :   26950060 :     }
#     250                 :     768205 :     return true;
#     251                 :     769944 : }
#     252                 :            : 
#     253                 :            : bool CScript::IsPushOnly() const
#     254                 :     425434 : {
#     255                 :     425434 :     return this->IsPushOnly(begin());
#     256                 :     425434 : }
#     257                 :            : 
#     258                 :            : std::string CScriptWitness::ToString() const
#     259                 :       5061 : {
#     260                 :       5061 :     std::string ret = "CScriptWitness(";
#     261         [ +  + ]:      17156 :     for (unsigned int i = 0; i < stack.size(); i++) {
#     262         [ +  + ]:      12095 :         if (i) {
#     263                 :       8122 :             ret += ", ";
#     264                 :       8122 :         }
#     265                 :      12095 :         ret += HexStr(stack[i]);
#     266                 :      12095 :     }
#     267                 :       5061 :     return ret + ")";
#     268                 :       5061 : }
#     269                 :            : 
#     270                 :            : bool CScript::HasValidOps() const
#     271                 :     240673 : {
#     272                 :     240673 :     CScript::const_iterator it = begin();
#     273         [ +  + ]:   15659431 :     while (it < end()) {
#     274                 :   15418801 :         opcodetype opcode;
#     275                 :   15418801 :         std::vector<unsigned char> item;
#     276 [ +  + ][ +  + ]:   15418801 :         if (!GetOp(it, opcode, item) || opcode > MAX_OPCODE || item.size() > MAX_SCRIPT_ELEMENT_SIZE) {
#                 [ +  + ]
#     277                 :         43 :             return false;
#     278                 :         43 :         }
#     279                 :   15418801 :     }
#     280                 :     240630 :     return true;
#     281                 :     240673 : }
#     282                 :            : 
#     283                 :            : bool GetScriptOp(CScriptBase::const_iterator& pc, CScriptBase::const_iterator end, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet)
#     284                 :  363706923 : {
#     285                 :  363706923 :     opcodeRet = OP_INVALIDOPCODE;
#     286         [ +  + ]:  363706923 :     if (pvchRet)
#     287                 :   30898504 :         pvchRet->clear();
#     288         [ +  + ]:  363706923 :     if (pc >= end)
#     289                 :    1286708 :         return false;
#     290                 :            : 
#     291                 :            :     // Read instruction
#     292         [ -  + ]:  362420215 :     if (end - pc < 1)
#     293                 :          0 :         return false;
#     294                 :  362420215 :     unsigned int opcode = *pc++;
#     295                 :            : 
#     296                 :            :     // Immediate operand
#     297         [ +  + ]:  362420215 :     if (opcode <= OP_PUSHDATA4)
#     298                 :   85099127 :     {
#     299                 :   85099127 :         unsigned int nSize = 0;
#     300         [ +  + ]:   85099127 :         if (opcode < OP_PUSHDATA1)
#     301                 :   84776982 :         {
#     302                 :   84776982 :             nSize = opcode;
#     303                 :   84776982 :         }
#     304         [ +  + ]:     322145 :         else if (opcode == OP_PUSHDATA1)
#     305                 :       6546 :         {
#     306         [ +  + ]:       6546 :             if (end - pc < 1)
#     307                 :        408 :                 return false;
#     308                 :       6138 :             nSize = *pc++;
#     309                 :       6138 :         }
#     310         [ +  + ]:     315599 :         else if (opcode == OP_PUSHDATA2)
#     311                 :     313797 :         {
#     312         [ -  + ]:     313797 :             if (end - pc < 2)
#     313                 :          0 :                 return false;
#     314                 :     313797 :             nSize = ReadLE16(&pc[0]);
#     315                 :     313797 :             pc += 2;
#     316                 :     313797 :         }
#     317         [ +  + ]:       1802 :         else if (opcode == OP_PUSHDATA4)
#     318                 :       4729 :         {
#     319         [ -  + ]:       4729 :             if (end - pc < 4)
#     320                 :          0 :                 return false;
#     321                 :       4729 :             nSize = ReadLE32(&pc[0]);
#     322                 :       4729 :             pc += 4;
#     323                 :       4729 :         }
#     324 [ +  + ][ +  + ]:   85173080 :         if (end - pc < 0 || (unsigned int)(end - pc) < nSize)
#     325                 :       2146 :             return false;
#     326         [ +  + ]:   85096573 :         if (pvchRet)
#     327                 :   24236471 :             pvchRet->assign(pc, pc + nSize);
#     328                 :   85096573 :         pc += nSize;
#     329                 :   85096573 :     }
#     330                 :            : 
#     331                 :  362417661 :     opcodeRet = static_cast<opcodetype>(opcode);
#     332                 :  362417661 :     return true;
#     333                 :  362420215 : }
#     334                 :            : 
#     335                 :            : bool IsOpSuccess(const opcodetype& opcode)
#     336                 :    1110738 : {
#     337 [ +  + ][ +  + ]:    1110738 :     return opcode == 80 || opcode == 98 || (opcode >= 126 && opcode <= 129) ||
#         [ +  + ][ +  + ]
#     338 [ +  + ][ +  + ]:    1110738 :            (opcode >= 131 && opcode <= 134) || (opcode >= 137 && opcode <= 138) ||
#         [ +  + ][ +  + ]
#     339 [ +  + ][ +  + ]:    1110738 :            (opcode >= 141 && opcode <= 142) || (opcode >= 149 && opcode <= 153) ||
#         [ +  + ][ +  + ]
#     340 [ +  + ][ +  + ]:    1110738 :            (opcode >= 187 && opcode <= 254);
#     341                 :    1110738 : }
#     342                 :            : 
#     343                 :    4295341 : bool CheckMinimalPush(const std::vector<unsigned char>& data, opcodetype opcode) {
#     344                 :            :     // Excludes OP_1NEGATE, OP_1-16 since they are by definition minimal
#     345                 :    4295341 :     assert(0 <= opcode && opcode <= OP_PUSHDATA4);
#     346         [ +  + ]:    4295341 :     if (data.size() == 0) {
#     347                 :            :         // Should have used OP_0.
#     348                 :     923285 :         return opcode == OP_0;
#     349 [ +  + ][ +  + ]:    3372056 :     } else if (data.size() == 1 && data[0] >= 1 && data[0] <= 16) {
#                 [ +  + ]
#     350                 :            :         // Should have used OP_1 .. OP_16.
#     351                 :        275 :         return false;
#     352 [ +  + ][ +  + ]:    3371781 :     } else if (data.size() == 1 && data[0] == 0x81) {
#     353                 :            :         // Should have used OP_1NEGATE.
#     354                 :         40 :         return false;
#     355         [ +  + ]:    3371741 :     } else if (data.size() <= 75) {
#     356                 :            :         // Must have used a direct push (opcode indicating number of bytes pushed + those bytes).
#     357                 :    3370029 :         return opcode == data.size();
#     358         [ +  + ]:    3370029 :     } else if (data.size() <= 255) {
#     359                 :            :         // Must have used OP_PUSHDATA.
#     360                 :       1148 :         return opcode == OP_PUSHDATA1;
#     361         [ +  - ]:       1148 :     } else if (data.size() <= 65535) {
#     362                 :            :         // Must have used OP_PUSHDATA2.
#     363                 :        564 :         return opcode == OP_PUSHDATA2;
#     364                 :        564 :     }
#     365                 :          0 :     return true;
#     366                 :    4295341 : }

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a