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