| 268 | } |
| 269 | |
| 270 | bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror) |
| 271 | { |
| 272 | static const CScriptNum bnZero(0); |
| 273 | static const CScriptNum bnOne(1); |
| 274 | static const CScriptNum bnFalse(0); |
| 275 | static const CScriptNum bnTrue(1); |
| 276 | static const valtype vchFalse(0); |
| 277 | static const valtype vchZero(0); |
| 278 | static const valtype vchTrue(1, 1); |
| 279 | |
| 280 | CScript::const_iterator pc = script.begin(); |
| 281 | CScript::const_iterator pend = script.end(); |
| 282 | CScript::const_iterator pbegincodehash = script.begin(); |
| 283 | opcodetype opcode; |
| 284 | valtype vchPushValue; |
| 285 | vector<bool> vfExec; |
| 286 | vector<valtype> altstack; |
| 287 | set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR); |
| 288 | if (script.size() > MAX_SCRIPT_SIZE) |
| 289 | return set_error(serror, SCRIPT_ERR_SCRIPT_SIZE); |
| 290 | int nOpCount = 0; |
| 291 | bool fRequireMinimal = (flags & SCRIPT_VERIFY_MINIMALDATA) != 0; |
| 292 | |
| 293 | try |
| 294 | { |
| 295 | while (pc < pend) |
| 296 | { |
| 297 | bool fExec = !count(vfExec.begin(), vfExec.end(), false); |
| 298 | |
| 299 | // |
| 300 | // Read instruction |
| 301 | // |
| 302 | if (!script.GetOp(pc, opcode, vchPushValue)) |
| 303 | return set_error(serror, SCRIPT_ERR_BAD_OPCODE); |
| 304 | if (vchPushValue.size() > MAX_SCRIPT_ELEMENT_SIZE) |
| 305 | return set_error(serror, SCRIPT_ERR_PUSH_SIZE); |
| 306 | |
| 307 | // Note how OP_RESERVED does not count towards the opcode limit. |
| 308 | if (opcode > OP_16 && ++nOpCount > MAX_OPS_PER_SCRIPT) |
| 309 | return set_error(serror, SCRIPT_ERR_OP_COUNT); |
| 310 | |
| 311 | if (opcode == OP_CAT || |
| 312 | opcode == OP_SUBSTR || |
| 313 | opcode == OP_LEFT || |
| 314 | opcode == OP_RIGHT || |
| 315 | opcode == OP_INVERT || |
| 316 | opcode == OP_AND || |
| 317 | opcode == OP_OR || |
| 318 | opcode == OP_XOR || |
| 319 | opcode == OP_2MUL || |
| 320 | opcode == OP_2DIV || |
| 321 | opcode == OP_MUL || |
| 322 | opcode == OP_DIV || |
| 323 | opcode == OP_MOD || |
| 324 | opcode == OP_LSHIFT || |
| 325 | opcode == OP_RSHIFT) |
| 326 | return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); // Disabled opcodes. |
| 327 | |