Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
501case OP_2:502case OP_3:503case OP_4:504case OP_5:505case OP_6:506case OP_7:507case OP_8:508case OP_9:509case OP_10:510case OP_11:511case OP_12:512case OP_13:513case OP_14:514case OP_15:515case OP_16:516{517// ( -- value)518CScriptNum bn((int)opcode - (int)(OP_1 - 1));519stack.push_back(bn.getvch());520// The result of these opcodes should always be the minimal way to push the data521// they push, so no need for a CheckMinimalPush here.522}523break;526//527// Control528//529case OP_NOP:530break;532case OP_CHECKLOCKTIMEVERIFY:533{534if (!(flags & SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY)) {535// not enabled; treat as a NOP2536break;537}539if (stack.size() < 1)540return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);542// Note that elsewhere numeric opcodes are limited to543// operands in the range -2**31+1 to 2**31-1, however it is544// legal for opcodes to produce results exceeding that545// range. This limitation is implemented by CScriptNum's546// default 4-byte limit.547//548// If we kept to that limit we'd have a year 2038 problem,549// even though the nLockTime field in transactions550// themselves is uint32 which only becomes meaningless551// after the year 2106.552//553// Thus as a special case we tell CScriptNum to accept up554// to 5-byte bignums, which are good until 2**39-1, well555// beyond the 2**32-1 limit of the nLockTime field itself.556const CScriptNum nLockTime(stacktop(-1), fRequireMinimal, 5);558// In the rare event that the argument may be < 0 due to559// some arithmetic being done first, you can always use560// 0 MAX CHECKLOCKTIMEVERIFY.561if (nLockTime < 0)562return set_error(serror, SCRIPT_ERR_NEGATIVE_LOCKTIME);564// Actually compare the specified lock time with the transaction.565if (!checker.CheckLockTime(nLockTime))566return set_error(serror, SCRIPT_ERR_UNSATISFIED_LOCKTIME);568break;569}571case OP_CHECKSEQUENCEVERIFY:572{573if (!(flags & SCRIPT_VERIFY_CHECKSEQUENCEVERIFY)) {574// not enabled; treat as a NOP3575break;576}578if (stack.size() < 1)579return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);581// nSequence, like nLockTime, is a 32-bit unsigned integer582// field. See the comment in CHECKLOCKTIMEVERIFY regarding583// 5-byte numeric operands.584const CScriptNum nSequence(stacktop(-1), fRequireMinimal, 5);586// In the rare event that the argument may be < 0 due to587// some arithmetic being done first, you can always use588// 0 MAX CHECKSEQUENCEVERIFY.589if (nSequence < 0)590return set_error(serror, SCRIPT_ERR_NEGATIVE_LOCKTIME);592// To provide for future soft-fork extensibility, if the593// operand has the disabled lock-time flag set,594// CHECKSEQUENCEVERIFY behaves as a NOP.595if ((nSequence & CTxIn::SEQUENCE_LOCKTIME_DISABLE_FLAG) != 0)596break;598// Compare the specified sequence number with the input.599if (!checker.CheckSequence(nSequence))600return set_error(serror, SCRIPT_ERR_UNSATISFIED_LOCKTIME);602break;603}605case OP_NOP1: case OP_NOP4: case OP_NOP5:606case OP_NOP6: case OP_NOP7: case OP_NOP8: case OP_NOP9: case OP_NOP10:607{608if (flags & SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS)609return set_error(serror, SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS);610}611break;613case OP_IF:614case OP_NOTIF:615{616// <expression> if [statements] [else [statements]] endif617bool fValue = false;618if (fExec)619{620if (stack.size() < 1)621return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);622valtype& vch = stacktop(-1);623// Tapscript requires minimal IF/NOTIF inputs as a consensus rule.624if (sigversion == SigVersion::TAPSCRIPT) {625// The input argument to the OP_IF and OP_NOTIF opcodes must be either626// exactly 0 (the empty vector) or exactly 1 (the one-byte vector with value 1).627if (vch.size() > 1 || (vch.size() == 1 && vch[0] != 1)) {628return set_error(serror, SCRIPT_ERR_TAPSCRIPT_MINIMALIF);629}630}631// Under witness v0 rules it is only a policy rule, enabled through SCRIPT_VERIFY_MINIMALIF.632if (sigversion == SigVersion::WITNESS_V0 && (flags & SCRIPT_VERIFY_MINIMALIF)) {633if (vch.size() > 1)634return set_error(serror, SCRIPT_ERR_MINIMALIF);635if (vch.size() == 1 && vch[0] != 1)636return set_error(serror, SCRIPT_ERR_MINIMALIF);637}638fValue = CastToBool(vch);639if (opcode == OP_NOTIF)640fValue = !fValue;641popstack(stack);642}643vfExec.push_back(fValue);644}645break;647case OP_ELSE:648{649if (vfExec.empty())650return set_error(serror, SCRIPT_ERR_UNBALANCED_CONDITIONAL);651vfExec.toggle_top();652}653break;655case OP_ENDIF:656{657if (vfExec.empty())658return set_error(serror, SCRIPT_ERR_UNBALANCED_CONDITIONAL);659vfExec.pop_back();660}661break;663case OP_VERIFY:664{665// (true -- ) or666// (false -- false) and return667if (stack.size() < 1)668return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);669bool fValue = CastToBool(stacktop(-1));670if (fValue)671popstack(stack);672else673return set_error(serror, SCRIPT_ERR_VERIFY);674}675break;677case OP_RETURN:678{679return set_error(serror, SCRIPT_ERR_OP_RETURN);680}681break;684//685// Stack ops686//687case OP_TOALTSTACK:688{689if (stack.size() < 1)690return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);691altstack.push_back(stacktop(-1));692popstack(stack);693}694break;696case OP_FROMALTSTACK:697{698if (altstack.size() < 1)699return set_error(serror, SCRIPT_ERR_INVALID_ALTSTACK_OPERATION);700stack.push_back(altstacktop(-1));701popstack(altstack);702}703break;705case OP_2DROP:706{707// (x1 x2 -- )708if (stack.size() < 2)709return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);710popstack(stack);711popstack(stack);712}713break;715case OP_2DUP:716{717// (x1 x2 -- x1 x2 x1 x2)718if (stack.size() < 2)719return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);720valtype vch1 = stacktop(-2);721valtype vch2 = stacktop(-1);722stack.push_back(vch1);723stack.push_back(vch2);724}725break;727case OP_3DUP:728{729// (x1 x2 x3 -- x1 x2 x3 x1 x2 x3)730if (stack.size() < 3)731return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);732valtype vch1 = stacktop(-3);733valtype vch2 = stacktop(-2);734valtype vch3 = stacktop(-1);735stack.push_back(vch1);736stack.push_back(vch2);737stack.push_back(vch3);738}739break;741case OP_2OVER:742{743// (x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2)744if (stack.size() < 4)745return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION);746valtype vch1 = stacktop(-4);747valtype vch2 = stacktop(-3);748stack.push_back(vch1);749stack.push_back(vch2);750}