TeachMeBitcoin

The Self-Audit: Ensuring Integrity with `verifychain`

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The Self-Audit: Ensuring Integrity with verifychain

Trust is the enemy of security. Even though your node verifies every block as it arrives, what if your hard drive fails? What if a stray cosmic ray flips a single bit in your database? To be "Absolutely Certain," you must perform a "Self-Audit." The command for this is verifychain. It is the "Deep Scan of the Vault," the "Price of Certainty."

Analyzing the "Auditor" Code

In the source code (src/rpc/blockchain.cpp), this command calls the VerifyDB class, which performs a hierarchical set of checks, from simple header links to full script verification.

/**
 * This function triggers a "Manual Audit" of the local database.
 */
static RPCMethod verifychain()
{
 // ... (Arguments omitted)
 [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue
{
 int check_level = request.params[0].isNull() ? 3 : request.params[0].getInt<int>();
 int check_depth = request.params[1].isNull() ? 6 : request.params[1].getInt<int>();

 ChainstateManager& chainman = EnsureAnyChainman(request.context);
 LOCK(cs_main);

 // We run the 'VerifyDB' engine.
 CVerifyDB vdb;
 return vdb.VerifyDB(chainman.ActiveChainstate(), chainman.GetParams().GetConsensus(), chainman.ActiveChainstate().CoinsTip(), check_level, check_depth);
}

Explaining the Audit Levels to a Non-Coder

The Vigilance of the Vault

verifychain is a slow and heavy process. It uses a lot of CPU power. But it is the only way to be "Sovereign." By running this command, you are telling the universe: "I don't even trust my own hard drive. I only trust the Math." It is the "Ultimate Act of Verification."


☕ 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!