Update transaction verification protocol
[novacoin.git] / src / script.h
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef H_BITCOIN_SCRIPT
6 #define H_BITCOIN_SCRIPT
7
8 #include <string>
9 #include <vector>
10
11 #include <boost/foreach.hpp>
12 #include <boost/variant.hpp>
13
14 #include "keystore.h"
15 #include "bignum.h"
16
17 class CCoins;
18 class CTransaction;
19
20 typedef std::vector<unsigned char> valtype;
21
22 /** Signature hash types/flags */
23 enum
24 {
25     SIGHASH_ALL = 1,
26     SIGHASH_NONE = 2,
27     SIGHASH_SINGLE = 3,
28     SIGHASH_ANYONECANPAY = 0x80,
29 };
30
31
32 enum txnouttype
33 {
34     TX_NONSTANDARD,
35     // 'standard' transaction types:
36     TX_PUBKEY,
37     TX_PUBKEYHASH,
38     TX_SCRIPTHASH,
39     TX_MULTISIG,
40     TX_NULL_DATA,
41 };
42
43 class CNoDestination {
44 public:
45     friend bool operator==(const CNoDestination &a, const CNoDestination &b) { return true; }
46     friend bool operator<(const CNoDestination &a, const CNoDestination &b) { return true; }
47 };
48
49 /** A txout script template with a specific destination. It is either:
50  *  * CNoDestination: no destination set
51  *  * CKeyID: TX_PUBKEYHASH destination
52  *  * CScriptID: TX_SCRIPTHASH destination
53  *  A CTxDestination is the internal data type encoded in a CBitcoinAddress
54  */
55 typedef boost::variant<CNoDestination, CKeyID, CScriptID> CTxDestination;
56
57 const char* GetTxnOutputType(txnouttype t);
58
59 /** Script opcodes */
60 enum opcodetype
61 {
62     // push value
63     OP_0 = 0x00,
64     OP_FALSE = OP_0,
65     OP_PUSHDATA1 = 0x4c,
66     OP_PUSHDATA2 = 0x4d,
67     OP_PUSHDATA4 = 0x4e,
68     OP_1NEGATE = 0x4f,
69     OP_RESERVED = 0x50,
70     OP_1 = 0x51,
71     OP_TRUE=OP_1,
72     OP_2 = 0x52,
73     OP_3 = 0x53,
74     OP_4 = 0x54,
75     OP_5 = 0x55,
76     OP_6 = 0x56,
77     OP_7 = 0x57,
78     OP_8 = 0x58,
79     OP_9 = 0x59,
80     OP_10 = 0x5a,
81     OP_11 = 0x5b,
82     OP_12 = 0x5c,
83     OP_13 = 0x5d,
84     OP_14 = 0x5e,
85     OP_15 = 0x5f,
86     OP_16 = 0x60,
87
88     // control
89     OP_NOP = 0x61,
90     OP_VER = 0x62,
91     OP_IF = 0x63,
92     OP_NOTIF = 0x64,
93     OP_VERIF = 0x65,
94     OP_VERNOTIF = 0x66,
95     OP_ELSE = 0x67,
96     OP_ENDIF = 0x68,
97     OP_VERIFY = 0x69,
98     OP_RETURN = 0x6a,
99
100     // stack ops
101     OP_TOALTSTACK = 0x6b,
102     OP_FROMALTSTACK = 0x6c,
103     OP_2DROP = 0x6d,
104     OP_2DUP = 0x6e,
105     OP_3DUP = 0x6f,
106     OP_2OVER = 0x70,
107     OP_2ROT = 0x71,
108     OP_2SWAP = 0x72,
109     OP_IFDUP = 0x73,
110     OP_DEPTH = 0x74,
111     OP_DROP = 0x75,
112     OP_DUP = 0x76,
113     OP_NIP = 0x77,
114     OP_OVER = 0x78,
115     OP_PICK = 0x79,
116     OP_ROLL = 0x7a,
117     OP_ROT = 0x7b,
118     OP_SWAP = 0x7c,
119     OP_TUCK = 0x7d,
120
121     // splice ops
122     OP_CAT = 0x7e,
123     OP_SUBSTR = 0x7f,
124     OP_LEFT = 0x80,
125     OP_RIGHT = 0x81,
126     OP_SIZE = 0x82,
127
128     // bit logic
129     OP_INVERT = 0x83,
130     OP_AND = 0x84,
131     OP_OR = 0x85,
132     OP_XOR = 0x86,
133     OP_EQUAL = 0x87,
134     OP_EQUALVERIFY = 0x88,
135     OP_RESERVED1 = 0x89,
136     OP_RESERVED2 = 0x8a,
137
138     // numeric
139     OP_1ADD = 0x8b,
140     OP_1SUB = 0x8c,
141     OP_2MUL = 0x8d,
142     OP_2DIV = 0x8e,
143     OP_NEGATE = 0x8f,
144     OP_ABS = 0x90,
145     OP_NOT = 0x91,
146     OP_0NOTEQUAL = 0x92,
147
148     OP_ADD = 0x93,
149     OP_SUB = 0x94,
150     OP_MUL = 0x95,
151     OP_DIV = 0x96,
152     OP_MOD = 0x97,
153     OP_LSHIFT = 0x98,
154     OP_RSHIFT = 0x99,
155
156     OP_BOOLAND = 0x9a,
157     OP_BOOLOR = 0x9b,
158     OP_NUMEQUAL = 0x9c,
159     OP_NUMEQUALVERIFY = 0x9d,
160     OP_NUMNOTEQUAL = 0x9e,
161     OP_LESSTHAN = 0x9f,
162     OP_GREATERTHAN = 0xa0,
163     OP_LESSTHANOREQUAL = 0xa1,
164     OP_GREATERTHANOREQUAL = 0xa2,
165     OP_MIN = 0xa3,
166     OP_MAX = 0xa4,
167
168     OP_WITHIN = 0xa5,
169
170     // crypto
171     OP_RIPEMD160 = 0xa6,
172     OP_SHA1 = 0xa7,
173     OP_SHA256 = 0xa8,
174     OP_HASH160 = 0xa9,
175     OP_HASH256 = 0xaa,
176     OP_CODESEPARATOR = 0xab,
177     OP_CHECKSIG = 0xac,
178     OP_CHECKSIGVERIFY = 0xad,
179     OP_CHECKMULTISIG = 0xae,
180     OP_CHECKMULTISIGVERIFY = 0xaf,
181
182     // expansion
183     OP_NOP1 = 0xb0,
184     OP_NOP2 = 0xb1,
185     OP_NOP3 = 0xb2,
186     OP_NOP4 = 0xb3,
187     OP_NOP5 = 0xb4,
188     OP_NOP6 = 0xb5,
189     OP_NOP7 = 0xb6,
190     OP_NOP8 = 0xb7,
191     OP_NOP9 = 0xb8,
192     OP_NOP10 = 0xb9,
193
194
195
196     // template matching params
197     OP_SMALLDATA = 0xf9,
198     OP_SMALLINTEGER = 0xfa,
199     OP_PUBKEYS = 0xfb,
200     OP_PUBKEYHASH = 0xfd,
201     OP_PUBKEY = 0xfe,
202
203     OP_INVALIDOPCODE = 0xff,
204 };
205
206 const char* GetOpName(opcodetype opcode);
207
208
209
210 inline std::string ValueString(const std::vector<unsigned char>& vch)
211 {
212     if (vch.size() <= 4)
213         return strprintf("%d", CBigNum(vch).getint());
214     else
215         return HexStr(vch);
216 }
217
218 inline std::string StackString(const std::vector<std::vector<unsigned char> >& vStack)
219 {
220     std::string str;
221     BOOST_FOREACH(const std::vector<unsigned char>& vch, vStack)
222     {
223         if (!str.empty())
224             str += " ";
225         str += ValueString(vch);
226     }
227     return str;
228 }
229
230
231
232
233
234
235
236
237 /** Serialized script, used inside transaction inputs and outputs */
238 class CScript : public std::vector<unsigned char>
239 {
240 protected:
241     CScript& push_int64(int64 n)
242     {
243         if (n == -1 || (n >= 1 && n <= 16))
244         {
245             push_back(n + (OP_1 - 1));
246         }
247         else
248         {
249             CBigNum bn(n);
250             *this << bn.getvch();
251         }
252         return *this;
253     }
254
255     CScript& push_uint64(uint64 n)
256     {
257         if (n >= 1 && n <= 16)
258         {
259             push_back(n + (OP_1 - 1));
260         }
261         else
262         {
263             CBigNum bn(n);
264             *this << bn.getvch();
265         }
266         return *this;
267     }
268
269 public:
270     CScript() { }
271     CScript(const CScript& b) : std::vector<unsigned char>(b.begin(), b.end()) { }
272     CScript(const_iterator pbegin, const_iterator pend) : std::vector<unsigned char>(pbegin, pend) { }
273 #ifndef _MSC_VER
274     CScript(const unsigned char* pbegin, const unsigned char* pend) : std::vector<unsigned char>(pbegin, pend) { }
275 #endif
276
277     CScript& operator+=(const CScript& b)
278     {
279         insert(end(), b.begin(), b.end());
280         return *this;
281     }
282
283     friend CScript operator+(const CScript& a, const CScript& b)
284     {
285         CScript ret = a;
286         ret += b;
287         return ret;
288     }
289
290
291     //explicit CScript(char b) is not portable.  Use 'signed char' or 'unsigned char'.
292     explicit CScript(signed char b)    { operator<<(b); }
293     explicit CScript(short b)          { operator<<(b); }
294     explicit CScript(int b)            { operator<<(b); }
295     explicit CScript(long b)           { operator<<(b); }
296     explicit CScript(int64 b)          { operator<<(b); }
297     explicit CScript(unsigned char b)  { operator<<(b); }
298     explicit CScript(unsigned int b)   { operator<<(b); }
299     explicit CScript(unsigned short b) { operator<<(b); }
300     explicit CScript(unsigned long b)  { operator<<(b); }
301     explicit CScript(uint64 b)         { operator<<(b); }
302
303     explicit CScript(opcodetype b)     { operator<<(b); }
304     explicit CScript(const uint256& b) { operator<<(b); }
305     explicit CScript(const CBigNum& b) { operator<<(b); }
306     explicit CScript(const std::vector<unsigned char>& b) { operator<<(b); }
307
308
309     //CScript& operator<<(char b) is not portable.  Use 'signed char' or 'unsigned char'.
310     CScript& operator<<(signed char b)    { return push_int64(b); }
311     CScript& operator<<(short b)          { return push_int64(b); }
312     CScript& operator<<(int b)            { return push_int64(b); }
313     CScript& operator<<(long b)           { return push_int64(b); }
314     CScript& operator<<(int64 b)          { return push_int64(b); }
315     CScript& operator<<(unsigned char b)  { return push_uint64(b); }
316     CScript& operator<<(unsigned int b)   { return push_uint64(b); }
317     CScript& operator<<(unsigned short b) { return push_uint64(b); }
318     CScript& operator<<(unsigned long b)  { return push_uint64(b); }
319     CScript& operator<<(uint64 b)         { return push_uint64(b); }
320
321     CScript& operator<<(opcodetype opcode)
322     {
323         if (opcode < 0 || opcode > 0xff)
324             throw std::runtime_error("CScript::operator<<() : invalid opcode");
325         insert(end(), (unsigned char)opcode);
326         return *this;
327     }
328
329     CScript& operator<<(const uint160& b)
330     {
331         insert(end(), sizeof(b));
332         insert(end(), (unsigned char*)&b, (unsigned char*)&b + sizeof(b));
333         return *this;
334     }
335
336     CScript& operator<<(const uint256& b)
337     {
338         insert(end(), sizeof(b));
339         insert(end(), (unsigned char*)&b, (unsigned char*)&b + sizeof(b));
340         return *this;
341     }
342
343     CScript& operator<<(const CPubKey& key)
344     {
345         std::vector<unsigned char> vchKey = key.Raw();
346         return (*this) << vchKey;
347     }
348
349     CScript& operator<<(const CBigNum& b)
350     {
351         *this << b.getvch();
352         return *this;
353     }
354
355     CScript& operator<<(const std::vector<unsigned char>& b)
356     {
357         if (b.size() < OP_PUSHDATA1)
358         {
359             insert(end(), (unsigned char)b.size());
360         }
361         else if (b.size() <= 0xff)
362         {
363             insert(end(), OP_PUSHDATA1);
364             insert(end(), (unsigned char)b.size());
365         }
366         else if (b.size() <= 0xffff)
367         {
368             insert(end(), OP_PUSHDATA2);
369             unsigned short nSize = b.size();
370             insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
371         }
372         else
373         {
374             insert(end(), OP_PUSHDATA4);
375             unsigned int nSize = b.size();
376             insert(end(), (unsigned char*)&nSize, (unsigned char*)&nSize + sizeof(nSize));
377         }
378         insert(end(), b.begin(), b.end());
379         return *this;
380     }
381
382     CScript& operator<<(const CScript& b)
383     {
384         // I'm not sure if this should push the script or concatenate scripts.
385         // If there's ever a use for pushing a script onto a script, delete this member fn
386         assert(!"Warning: Pushing a CScript onto a CScript with << is probably not intended, use + to concatenate!");
387         return *this;
388     }
389
390
391     bool GetOp(iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet)
392     {
393          // Wrapper so it can be called with either iterator or const_iterator
394          const_iterator pc2 = pc;
395          bool fRet = GetOp2(pc2, opcodeRet, &vchRet);
396          pc = begin() + (pc2 - begin());
397          return fRet;
398     }
399
400     bool GetOp(iterator& pc, opcodetype& opcodeRet)
401     {
402          const_iterator pc2 = pc;
403          bool fRet = GetOp2(pc2, opcodeRet, NULL);
404          pc = begin() + (pc2 - begin());
405          return fRet;
406     }
407
408     bool GetOp(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>& vchRet) const
409     {
410         return GetOp2(pc, opcodeRet, &vchRet);
411     }
412
413     bool GetOp(const_iterator& pc, opcodetype& opcodeRet) const
414     {
415         return GetOp2(pc, opcodeRet, NULL);
416     }
417
418     bool GetOp2(const_iterator& pc, opcodetype& opcodeRet, std::vector<unsigned char>* pvchRet) const
419     {
420         opcodeRet = OP_INVALIDOPCODE;
421         if (pvchRet)
422             pvchRet->clear();
423         if (pc >= end())
424             return false;
425
426         // Read instruction
427         if (end() - pc < 1)
428             return false;
429         unsigned int opcode = *pc++;
430
431         // Immediate operand
432         if (opcode <= OP_PUSHDATA4)
433         {
434             unsigned int nSize;
435             if (opcode < OP_PUSHDATA1)
436             {
437                 nSize = opcode;
438             }
439             else if (opcode == OP_PUSHDATA1)
440             {
441                 if (end() - pc < 1)
442                     return false;
443                 nSize = *pc++;
444             }
445             else if (opcode == OP_PUSHDATA2)
446             {
447                 if (end() - pc < 2)
448                     return false;
449                 nSize = 0;
450                 memcpy(&nSize, &pc[0], 2);
451                 pc += 2;
452             }
453             else if (opcode == OP_PUSHDATA4)
454             {
455                 if (end() - pc < 4)
456                     return false;
457                 memcpy(&nSize, &pc[0], 4);
458                 pc += 4;
459             }
460             if (end() - pc < 0 || (unsigned int)(end() - pc) < nSize)
461                 return false;
462             if (pvchRet)
463                 pvchRet->assign(pc, pc + nSize);
464             pc += nSize;
465         }
466
467         opcodeRet = (opcodetype)opcode;
468         return true;
469     }
470
471     // Encode/decode small integers:
472     static int DecodeOP_N(opcodetype opcode)
473     {
474         if (opcode == OP_0)
475             return 0;
476         assert(opcode >= OP_1 && opcode <= OP_16);
477         return (int)opcode - (int)(OP_1 - 1);
478     }
479     static opcodetype EncodeOP_N(int n)
480     {
481         assert(n >= 0 && n <= 16);
482         if (n == 0)
483             return OP_0;
484         return (opcodetype)(OP_1+n-1);
485     }
486
487     int FindAndDelete(const CScript& b)
488     {
489         int nFound = 0;
490         if (b.empty())
491             return nFound;
492         iterator pc = begin();
493         opcodetype opcode;
494         do
495         {
496             while (end() - pc >= (long)b.size() && memcmp(&pc[0], &b[0], b.size()) == 0)
497             {
498                 erase(pc, pc + b.size());
499                 ++nFound;
500             }
501         }
502         while (GetOp(pc, opcode));
503         return nFound;
504     }
505     int Find(opcodetype op) const
506     {
507         int nFound = 0;
508         opcodetype opcode;
509         for (const_iterator pc = begin(); pc != end() && GetOp(pc, opcode);)
510             if (opcode == op)
511                 ++nFound;
512         return nFound;
513     }
514
515     // Pre-version-0.6, Bitcoin always counted CHECKMULTISIGs
516     // as 20 sigops. With pay-to-script-hash, that changed:
517     // CHECKMULTISIGs serialized in scriptSigs are
518     // counted more accurately, assuming they are of the form
519     //  ... OP_N CHECKMULTISIG ...
520     unsigned int GetSigOpCount(bool fAccurate) const;
521
522     // Accurately count sigOps, including sigOps in
523     // pay-to-script-hash transactions:
524     unsigned int GetSigOpCount(const CScript& scriptSig) const;
525
526     bool IsPayToScriptHash() const;
527
528     // Called by CTransaction::IsStandard
529     bool IsPushOnly() const
530     {
531         const_iterator pc = begin();
532         while (pc < end())
533         {
534             opcodetype opcode;
535             if (!GetOp(pc, opcode))
536                 return false;
537             if (opcode > OP_16)
538                 return false;
539         }
540         return true;
541     }
542
543     // Called by CTransaction::IsStandard.
544     bool HasCanonicalPushes() const;
545
546     void SetDestination(const CTxDestination& address);
547     void SetMultisig(int nRequired, const std::vector<CKey>& keys);
548
549
550     void PrintHex() const
551     {
552         printf("CScript(%s)\n", HexStr(begin(), end(), true).c_str());
553     }
554
555     std::string ToString() const
556     {
557         std::string str;
558         opcodetype opcode;
559         std::vector<unsigned char> vch;
560         const_iterator pc = begin();
561         while (pc < end())
562         {
563             if (!str.empty())
564                 str += " ";
565             if (!GetOp(pc, opcode, vch))
566             {
567                 str += "[error]";
568                 return str;
569             }
570             if (0 <= opcode && opcode <= OP_PUSHDATA4)
571                 str += ValueString(vch);
572             else
573                 str += GetOpName(opcode);
574         }
575         return str;
576     }
577
578     void print() const
579     {
580         printf("%s\n", ToString().c_str());
581     }
582
583     CScriptID GetID() const
584     {
585         return CScriptID(Hash160(*this));
586     }
587 };
588
589 /** Compact serializer for scripts.
590  *
591  *  It detects common cases and encodes them much more efficiently.
592  *  3 special cases are defined:
593  *  * Pay to pubkey hash (encoded as 21 bytes)
594  *  * Pay to script hash (encoded as 21 bytes)
595  *  * Pay to pubkey starting with 0x02, 0x03 or 0x04 (encoded as 33 bytes)
596  *
597  *  Other scripts up to 121 bytes require 1 byte + script length. Above
598  *  that, scripts up to 16505 bytes require 2 bytes + script length.
599  */
600 class CScriptCompressor
601 {
602 private:
603     // make this static for now (there are only 6 special scripts defined)
604     // this can potentially be extended together with a new nVersion for
605     // transactions, in which case this value becomes dependent on nVersion
606     // and nHeight of the enclosing transaction.
607     static const unsigned int nSpecialScripts = 6;
608
609     CScript &script;
610 protected:
611     // These check for scripts for which a special case with a shorter encoding is defined.
612     // They are implemented separately from the CScript test, as these test for exact byte
613     // sequence correspondences, and are more strict. For example, IsToPubKey also verifies
614     // whether the public key is valid (as invalid ones cannot be represented in compressed
615     // form).
616     bool IsToKeyID(CKeyID &hash) const;
617     bool IsToScriptID(CScriptID &hash) const;
618     bool IsToPubKey(std::vector<unsigned char> &pubkey) const;
619
620     bool Compress(std::vector<unsigned char> &out) const;
621     unsigned int GetSpecialSize(unsigned int nSize) const;
622     bool Decompress(unsigned int nSize, const std::vector<unsigned char> &out);
623 public:
624     CScriptCompressor(CScript &scriptIn) : script(scriptIn) { }
625
626     unsigned int GetSerializeSize(int nType, int nVersion) const {
627         std::vector<unsigned char> compr;
628         if (Compress(compr))
629             return compr.size();
630         unsigned int nSize = script.size() + nSpecialScripts;
631         return script.size() + VARINT(nSize).GetSerializeSize(nType, nVersion);
632     }
633
634     template<typename Stream>
635     void Serialize(Stream &s, int nType, int nVersion) const {
636         std::vector<unsigned char> compr;
637         if (Compress(compr)) {
638             s << CFlatData(&compr[0], &compr[compr.size()]);
639             return;
640         }
641         unsigned int nSize = script.size() + nSpecialScripts;
642         s << VARINT(nSize);
643         s << CFlatData(&script[0], &script[script.size()]);
644     }
645
646     template<typename Stream>
647     void Unserialize(Stream &s, int nType, int nVersion) {
648         unsigned int nSize;
649         s >> VARINT(nSize);
650         if (nSize < nSpecialScripts) {
651             std::vector<unsigned char> vch(GetSpecialSize(nSize), 0x00);
652             s >> REF(CFlatData(&vch[0], &vch[vch.size()]));
653             Decompress(nSize, vch);
654             return;
655         }
656         nSize -= nSpecialScripts;
657         script.resize(nSize);
658         s >> REF(CFlatData(&script[0], &script[script.size()]));
659     }
660 };
661
662 bool IsCanonicalPubKey(const std::vector<unsigned char> &vchPubKey);
663 bool IsCanonicalSignature(const std::vector<unsigned char> &vchSig);
664
665 uint256 SignatureHash(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType);
666
667 bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, bool fStrictEncodings, int nHashType);
668 bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<std::vector<unsigned char> >& vSolutionsRet);
669 int ScriptSigArgsExpected(txnouttype t, const std::vector<std::vector<unsigned char> >& vSolutions);
670 bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
671 bool IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
672 bool IsMine(const CKeyStore& keystore, const CTxDestination &dest);
673
674 void ExtractAffectedKeys(const CKeyStore &keystore, const CScript& scriptPubKey, std::vector<CKeyID> &vKeys);
675 bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
676 bool ExtractDestinations(const CScript& scriptPubKey, txnouttype& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
677 bool SignSignature(const CKeyStore& keystore, const CScript& fromPubKey, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL);
678 bool SignSignature(const CKeyStore& keystore, const CTransaction& txFrom, CTransaction& txTo, unsigned int nIn, int nHashType=SIGHASH_ALL);
679 bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const CTransaction& txTo, unsigned int nIn,
680                   bool fValidatePayToScriptHash, bool fStrictEncodings, int nHashType);
681 bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned int nIn, bool fValidatePayToScriptHash, bool fStrictEncodings, int nHashType);
682
683 // Given two sets of signatures for scriptPubKey, possibly with OP_0 placeholders,
684 // combine them intelligently and return the result.
685 CScript CombineSignatures(CScript scriptPubKey, const CTransaction& txTo, unsigned int nIn, const CScript& scriptSig1, const CScript& scriptSig2);
686
687 #endif