MCPcopy
hub / github.com/bcoin-org/bcoin / execute

Method execute

lib/script/script.js:517–1290  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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

Callers 12

app.jsFile · 0.45
verifyMethod · 0.45
verifyProgramMethod · 0.45
helpMethod · 0.45
script-test.jsFile · 0.45
indexer-test.jsFile · 0.45
node-http-test.jsFile · 0.45
node-rpc-test.jsFile · 0.45
wallet-rpc-test.jsFile · 0.45
fnFunction · 0.45
fuzzSimpleFunction · 0.45
callNodeApiFunction · 0.45

Calls 15

getSubscriptMethod · 0.95
validateSignatureFunction · 0.85
validateKeyFunction · 0.85
checksigFunction · 0.85
isDisabledMethod · 0.80
isBranchMethod · 0.80
verifyLocktimeMethod · 0.80
verifySequenceMethod · 0.80
swapMethod · 0.80
findAndDeleteMethod · 0.80
signatureHashMethod · 0.80
isMinimalMethod · 0.45

Tested by

no test coverage detected