TeachMeBitcoin

The Transaction Sieve: Verifying Inputs in `CheckInputScripts`

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

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

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."


☕ Help support TeachMeBitcoin

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:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!