The Transaction Sieve: Verifying Inputs in `CheckInputScripts`
9. The Transaction Sieve: Verifying Inputs in CheckInputScripts
We have seen how the node validates the "Block" (the Crate). Now, we must look at how it validates the "Items" inside the crate: the Transactions. The most critical part of this is CheckInputScripts. This is the "Transaction Sieve." Its job is to take every single input of a transaction and "Prove" that the person spending it has the right to do so. This is where the "Cryptography" of Bitcoin meets the "Consensus" of Bitcoin.
For the Sovereign Architect, CheckInputScripts is the "Final Proof." This function is what actually runs the Bitcoin Script engine. It combines the "Unlocking Script" (the signature you provide) with the "Locking Script" (the rules set by the previous owner) and checks if the result is "True." It is the "Math of the Permission."
Analyzing the Sieve: CheckInputScripts
In the source code (src/validation.cpp), we see how the node prepares to "Execute" the scripts for a transaction.
/**
* PEDAGOGICAL ANALYSIS: THE TRANSACTION SIEVE
* This logic verifies that every "Spent Coin" is authorized by its owner.
*/
bool CheckInputScripts(const CTransaction& tx, TxValidationState& state, const CCoinsViewCache& inputs, ...)
{
// 1. We loop through every "Input" in the transaction.
for (unsigned int i = 0; i < tx.vin.size(); i++) {
// 2. We fetch the "Locking Script" (ScriptPubKey) from the UTXO set.
const CTxOut& prevout = inputs.AccessCoin(tx.vin[i].prevout).out;
// 3. We create a "Script Check" object.
// This object contains the "Lock" (prevout.scriptPubKey)
// and the "Key" (tx.vin[i].scriptSig).
CScriptCheck check(prevout, tx, i, ...);
// 4. We "Execute" the check.
// This is the moment the computer runs the "Bitcoin Virtual Machine".
if (!check()) {
return state.Invalid(TxValidationResult::TX_CONSENSUS, "mandatory-script-verify-flag-failed");
}
}
return true; // Every input is legally authorized!
}
Explaining the Sieve: The Lock and the Key
-
prevout.scriptPubKey(The Lock): When someone sent you Bitcoin in the past, they "Locked" it with a script. This script usually says: "Only the person with the private key corresponding to this public key can move these coins." It is the Requirement of the Sovereign. -
tx.vin[i].scriptSig(The Key): When you spend those coins, you provide an "Unlocking Script." This script contains your "Digital Signature" and your "Public Key." It is the Evidence of the Authority. -
CScriptCheck: This is the "Judge." It takes the Lock and the Key and "Smrashes" them together. If the key fits the lock perfectly, the judge returns "True." If even one bit is wrong, the judge returns "False," and the transaction is rejected. It is the Execution of the Logic. -
mandatory-script-verify-flag-failed: If the judge says "False," the node marks the entire block as invalid. This is why "Bad Signatures" are so rare on the network—no miner wants to risk their 6.25 BTC reward by including a transaction with a broken signature. It is the Discipline of the Network.
The Sovereignty of the Proof
When your node runs CheckInputScripts, it is not "Assuming" you own your money; it is "Proving" it. This is the difference between a "Bank Account" and "Bitcoin." In a bank, the bank "Allows" you to spend your money. In Bitcoin, the "Math" allows you to spend your money. As a Sovereign Architect, you are the "Master of the Proof," ensuring that every movement of your wealth is backed by the unbreakable laws of cryptography. You are the "Engineer of the Sieve."
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: