| 307 | } |
| 308 | |
| 309 | bool EvalScript(std::vector<std::vector<unsigned char> >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptError* serror) |
| 310 | { |
| 311 | static const CScriptNum bnZero(0); |
| 312 | static const CScriptNum bnOne(1); |
| 313 | // static const CScriptNum bnFalse(0); |
| 314 | // static const CScriptNum bnTrue(1); |
| 315 | static const valtype vchFalse(0); |
| 316 | // static const valtype vchZero(0); |
| 317 | static const valtype vchTrue(1, 1); |
| 318 | |
| 319 | CScript::const_iterator pc = script.begin(); |
| 320 | CScript::const_iterator pend = script.end(); |
| 321 | CScript::const_iterator pbegincodehash = script.begin(); |
| 322 | opcodetype opcode; |
| 323 | valtype vchPushValue; |
| 324 | std::vector<bool> vfExec; |
| 325 | std::vector<valtype> altstack; |
| 326 | set_error(serror, SCRIPT_ERR_UNKNOWN_ERROR); |
| 327 | if (script.size() > MAX_SCRIPT_SIZE) |
| 328 | return set_error(serror, SCRIPT_ERR_SCRIPT_SIZE); |
| 329 | int nOpCount = 0; |
| 330 | bool fRequireMinimal = (flags & SCRIPT_VERIFY_MINIMALDATA) != 0; |
| 331 | |
| 332 | try |
| 333 | { |
| 334 | while (pc < pend) |
| 335 | { |
| 336 | bool fExec = !count(vfExec.begin(), vfExec.end(), false); |
| 337 | |
| 338 | // |
| 339 | // Read instruction |
| 340 | // |
| 341 | if (!script.GetOp(pc, opcode, vchPushValue)) |
| 342 | return set_error(serror, SCRIPT_ERR_BAD_OPCODE); |
| 343 | if (vchPushValue.size() > MAX_SCRIPT_ELEMENT_SIZE) |
| 344 | return set_error(serror, SCRIPT_ERR_PUSH_SIZE); |
| 345 | |
| 346 | // Note how OP_RESERVED does not count towards the opcode limit. |
| 347 | if (opcode > OP_16 && ++nOpCount > MAX_OPS_PER_SCRIPT) |
| 348 | return set_error(serror, SCRIPT_ERR_OP_COUNT); |
| 349 | |
| 350 | if (opcode == OP_CAT || |
| 351 | opcode == OP_SUBSTR || |
| 352 | opcode == OP_LEFT || |
| 353 | opcode == OP_RIGHT || |
| 354 | opcode == OP_INVERT || |
| 355 | opcode == OP_AND || |
| 356 | opcode == OP_OR || |
| 357 | opcode == OP_XOR || |
| 358 | opcode == OP_2MUL || |
| 359 | opcode == OP_2DIV || |
| 360 | opcode == OP_MUL || |
| 361 | opcode == OP_DIV || |
| 362 | opcode == OP_MOD || |
| 363 | opcode == OP_LSHIFT || |
| 364 | opcode == OP_RSHIFT) |
| 365 | return set_error(serror, SCRIPT_ERR_DISABLED_OPCODE); // Disabled opcodes. |
| 366 | |