* Execute and interpret the script. * @param {Stack} stack - Script execution stack. * @param {Number?} flags - Script standard flags. * @param {TX?} tx - Transaction being verified. * @param {Number?} index - Index of input being verified. * @param {Amount?} value - Previous output v
(stack, flags, tx, index, value, version)
| 515 | */ |
| 516 | |
| 517 | execute(stack, flags, tx, index, value, version) { |
| 518 | if (flags == null) |
| 519 | flags = Script.flags.STANDARD_VERIFY_FLAGS; |
| 520 | |
| 521 | if (version == null) |
| 522 | version = 0; |
| 523 | |
| 524 | if (this.raw.length > consensus.MAX_SCRIPT_SIZE) |
| 525 | throw new ScriptError('SCRIPT_SIZE'); |
| 526 | |
| 527 | const state = []; |
| 528 | const alt = []; |
| 529 | |
| 530 | let lastSep = 0; |
| 531 | let opCount = 0; |
| 532 | let negate = 0; |
| 533 | let minimal = false; |
| 534 | |
| 535 | if (flags & Script.flags.VERIFY_MINIMALDATA) |
| 536 | minimal = true; |
| 537 | |
| 538 | for (let ip = 0; ip < this.code.length; ip++) { |
| 539 | const op = this.code[ip]; |
| 540 | |
| 541 | if (op.value === -1) |
| 542 | throw new ScriptError('BAD_OPCODE', op, ip); |
| 543 | |
| 544 | if (op.data && op.data.length > consensus.MAX_SCRIPT_PUSH) |
| 545 | throw new ScriptError('PUSH_SIZE', op, ip); |
| 546 | |
| 547 | if (op.value > opcodes.OP_16 && ++opCount > consensus.MAX_SCRIPT_OPS) |
| 548 | throw new ScriptError('OP_COUNT', op, ip); |
| 549 | |
| 550 | if (op.isDisabled()) |
| 551 | throw new ScriptError('DISABLED_OPCODE', op, ip); |
| 552 | |
| 553 | if (op.value === opcodes.OP_CODESEPARATOR && version === 0 && |
| 554 | (flags & Script.flags.VERIFY_CONST_SCRIPTCODE)) |
| 555 | throw new ScriptError('OP_CODESEPARATOR', op, ip); |
| 556 | |
| 557 | if (negate && !op.isBranch()) { |
| 558 | if (stack.length + alt.length > consensus.MAX_SCRIPT_STACK) |
| 559 | throw new ScriptError('STACK_SIZE', op, ip); |
| 560 | continue; |
| 561 | } |
| 562 | |
| 563 | if (op.data) { |
| 564 | if (minimal && !op.isMinimal()) |
| 565 | throw new ScriptError('MINIMALDATA', op, ip); |
| 566 | |
| 567 | stack.push(op.data); |
| 568 | |
| 569 | if (stack.length + alt.length > consensus.MAX_SCRIPT_STACK) |
| 570 | throw new ScriptError('STACK_SIZE', op, ip); |
| 571 | |
| 572 | continue; |
| 573 | } |
| 574 |
no test coverage detected