|
|
@ -25,22 +25,13 @@ typedef vector<unsigned char> valtype; |
|
|
|
static const valtype vchFalse(0); |
|
|
|
static const valtype vchFalse(0); |
|
|
|
static const valtype vchZero(0); |
|
|
|
static const valtype vchZero(0); |
|
|
|
static const valtype vchTrue(1, 1); |
|
|
|
static const valtype vchTrue(1, 1); |
|
|
|
static const CBigNum bnZero(0); |
|
|
|
static const CScriptNum bnZero(0); |
|
|
|
static const CBigNum bnOne(1); |
|
|
|
static const CScriptNum bnOne(1); |
|
|
|
static const CBigNum bnFalse(0); |
|
|
|
static const CScriptNum bnFalse(0); |
|
|
|
static const CBigNum bnTrue(1); |
|
|
|
static const CScriptNum bnTrue(1); |
|
|
|
static const size_t nMaxNumSize = 4; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CheckSig(vector<unsigned char> vchSig, const vector<unsigned char> &vchPubKey, const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, int flags); |
|
|
|
bool CheckSig(vector<unsigned char> vchSig, const vector<unsigned char> &vchPubKey, const CScript &scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType, int flags); |
|
|
|
|
|
|
|
|
|
|
|
CBigNum CastToBigNum(const valtype& vch) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (vch.size() > nMaxNumSize) |
|
|
|
|
|
|
|
throw runtime_error("CastToBigNum() : overflow"); |
|
|
|
|
|
|
|
// Get rid of extra leading zeros
|
|
|
|
|
|
|
|
return CBigNum(CBigNum(vch).getvch()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CastToBool(const valtype& vch) |
|
|
|
bool CastToBool(const valtype& vch) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (unsigned int i = 0; i < vch.size(); i++) |
|
|
|
for (unsigned int i = 0; i < vch.size(); i++) |
|
|
@ -306,7 +297,6 @@ bool IsCanonicalSignature(const valtype &vchSig, unsigned int flags) { |
|
|
|
|
|
|
|
|
|
|
|
bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType) |
|
|
|
bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CAutoBN_CTX pctx; |
|
|
|
|
|
|
|
CScript::const_iterator pc = script.begin(); |
|
|
|
CScript::const_iterator pc = script.begin(); |
|
|
|
CScript::const_iterator pend = script.end(); |
|
|
|
CScript::const_iterator pend = script.end(); |
|
|
|
CScript::const_iterator pbegincodehash = script.begin(); |
|
|
|
CScript::const_iterator pbegincodehash = script.begin(); |
|
|
@ -380,7 +370,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co |
|
|
|
case OP_16: |
|
|
|
case OP_16: |
|
|
|
{ |
|
|
|
{ |
|
|
|
// ( -- value)
|
|
|
|
// ( -- value)
|
|
|
|
CBigNum bn((int)opcode - (int)(OP_1 - 1)); |
|
|
|
CScriptNum bn((int)opcode - (int)(OP_1 - 1)); |
|
|
|
stack.push_back(bn.getvch()); |
|
|
|
stack.push_back(bn.getvch()); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -556,7 +546,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co |
|
|
|
case OP_DEPTH: |
|
|
|
case OP_DEPTH: |
|
|
|
{ |
|
|
|
{ |
|
|
|
// -- stacksize
|
|
|
|
// -- stacksize
|
|
|
|
CBigNum bn(stack.size()); |
|
|
|
CScriptNum bn(stack.size()); |
|
|
|
stack.push_back(bn.getvch()); |
|
|
|
stack.push_back(bn.getvch()); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -606,7 +596,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co |
|
|
|
// (xn ... x2 x1 x0 n - ... x2 x1 x0 xn)
|
|
|
|
// (xn ... x2 x1 x0 n - ... x2 x1 x0 xn)
|
|
|
|
if (stack.size() < 2) |
|
|
|
if (stack.size() < 2) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
int n = CastToBigNum(stacktop(-1)).getint(); |
|
|
|
int n = CScriptNum(stacktop(-1)).getint(); |
|
|
|
popstack(stack); |
|
|
|
popstack(stack); |
|
|
|
if (n < 0 || n >= (int)stack.size()) |
|
|
|
if (n < 0 || n >= (int)stack.size()) |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -654,7 +644,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co |
|
|
|
// (in -- in size)
|
|
|
|
// (in -- in size)
|
|
|
|
if (stack.size() < 1) |
|
|
|
if (stack.size() < 1) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
CBigNum bn(stacktop(-1).size()); |
|
|
|
CScriptNum bn(stacktop(-1).size()); |
|
|
|
stack.push_back(bn.getvch()); |
|
|
|
stack.push_back(bn.getvch()); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -705,7 +695,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co |
|
|
|
// (in -- out)
|
|
|
|
// (in -- out)
|
|
|
|
if (stack.size() < 1) |
|
|
|
if (stack.size() < 1) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
CBigNum bn = CastToBigNum(stacktop(-1)); |
|
|
|
CScriptNum bn(stacktop(-1)); |
|
|
|
switch (opcode) |
|
|
|
switch (opcode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case OP_1ADD: bn += bnOne; break; |
|
|
|
case OP_1ADD: bn += bnOne; break; |
|
|
@ -738,9 +728,9 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co |
|
|
|
// (x1 x2 -- out)
|
|
|
|
// (x1 x2 -- out)
|
|
|
|
if (stack.size() < 2) |
|
|
|
if (stack.size() < 2) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
CBigNum bn1 = CastToBigNum(stacktop(-2)); |
|
|
|
CScriptNum bn1(stacktop(-2)); |
|
|
|
CBigNum bn2 = CastToBigNum(stacktop(-1)); |
|
|
|
CScriptNum bn2(stacktop(-1)); |
|
|
|
CBigNum bn; |
|
|
|
CScriptNum bn(0); |
|
|
|
switch (opcode) |
|
|
|
switch (opcode) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case OP_ADD: |
|
|
|
case OP_ADD: |
|
|
@ -783,9 +773,9 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co |
|
|
|
// (x min max -- out)
|
|
|
|
// (x min max -- out)
|
|
|
|
if (stack.size() < 3) |
|
|
|
if (stack.size() < 3) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
CBigNum bn1 = CastToBigNum(stacktop(-3)); |
|
|
|
CScriptNum bn1(stacktop(-3)); |
|
|
|
CBigNum bn2 = CastToBigNum(stacktop(-2)); |
|
|
|
CScriptNum bn2(stacktop(-2)); |
|
|
|
CBigNum bn3 = CastToBigNum(stacktop(-1)); |
|
|
|
CScriptNum bn3(stacktop(-1)); |
|
|
|
bool fValue = (bn2 <= bn1 && bn1 < bn3); |
|
|
|
bool fValue = (bn2 <= bn1 && bn1 < bn3); |
|
|
|
popstack(stack); |
|
|
|
popstack(stack); |
|
|
|
popstack(stack); |
|
|
|
popstack(stack); |
|
|
@ -882,7 +872,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co |
|
|
|
if ((int)stack.size() < i) |
|
|
|
if ((int)stack.size() < i) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
int nKeysCount = CastToBigNum(stacktop(-i)).getint(); |
|
|
|
int nKeysCount = CScriptNum(stacktop(-i)).getint(); |
|
|
|
if (nKeysCount < 0 || nKeysCount > 20) |
|
|
|
if (nKeysCount < 0 || nKeysCount > 20) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
nOpCount += nKeysCount; |
|
|
|
nOpCount += nKeysCount; |
|
|
@ -893,7 +883,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co |
|
|
|
if ((int)stack.size() < i) |
|
|
|
if ((int)stack.size() < i) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
int nSigsCount = CastToBigNum(stacktop(-i)).getint(); |
|
|
|
int nSigsCount = CScriptNum(stacktop(-i)).getint(); |
|
|
|
if (nSigsCount < 0 || nSigsCount > nKeysCount) |
|
|
|
if (nSigsCount < 0 || nSigsCount > nKeysCount) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
int isig = ++i; |
|
|
|
int isig = ++i; |
|
|
|