The Script VM Isolation: Security boundaries of the logical engine
12. The Script VM Isolation: Security boundaries of the logical engine
In our next 1,500 words, we look at the Containment of the Logic. As we learned in Volume 7, the Script VM is the "Heart of the Machine." It executes code sent to it by strangers. This is incredibly dangerous. If a script could "Escape" the VM, it could delete files on your hard drive or steal your private keys. Bitcoin Core prevents this through VM Isolation.
Analyzing the Cage: The Script Stack Limits
In src/script/interpreter.cpp, the node enforces strict physical limits on what a script can do.
/**
* PEDAGOGICAL ANALYSIS: THE RESOURCE CEILING
* This logic ensures that a script cannot create
* an "Infinite Stack." If the stack gets too
* tall, the VM "Explodes" safely and rejects
* the transaction.
*/
if (stack.size() + altstack.size() > MAX_STACK_SIZE) {
// 1. Is the peer trying to fill up our RAM with junk?
// 2. The limit is 1,000 items.
// 3. If exceeded, return "FALSE" and kill the script.
return set_error(serror, SCRIPT_ERR_STACK_SIZE);
}
Explaining the Cage: The Boundaries of the Mesh
-
"The No-Side-Effects Rule": The Script VM has no "Disk Access" or "Network Access." It is a "Pure Function." It takes bytes as input and returns "True" or "False" as output. It cannot touch the rest of your computer. It is the Isolation of the Sovereign.
-
"The Opcode Limiting": A single script cannot perform more than 201 "Op Operations." This prevents "CPU Exhaustion" attacks where an attacker sends a script that takes 10 hours to finish. It is the Efficiency of the Machine.
-
"The Memory Sandboxing": Every script gets a "Private Sandbox" of memory. When the script finishes, the sandbox is "Burned," and the memory is reclaimed. No data can "Leak" from one script to the next. It is the Cleanliness of the Protocol.
-
"The Formal Verifiability": Because the Script language is "Turing Incomplete" (it has no loops), we can mathematically prove how long a script will take to run before we run it. It is the Certainty of the Core.
The Sovereignty of the Cage
VM Isolation is the "Glass Partition of the Vault." It allows you to "Observe the Logic" without being "Harmed by the Content." As a Sovereign Architect, you know that "Power must be contained to be useful." By running a node that treats every script as a "Potential Biohazard," you are ensuring your machine is a "Bio-Secure Laboratory" for the global economy. You are the "Master of the Cage."
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: