中文版 · Blockchain learning guide · Previous article
Blockchain learning · Article BC036

A blockchain virtual machine gives participating implementations a shared meaning for executable instructions. For a fixed rule version, starting state, ordered inputs and permitted environment, independent validators should derive the same prescribed result. They do not ask a majority vote to decide what an addition instruction means.
The difficult part is often establishing that the inputs really are the same. Two machines can run code with the same familiar name while using different bytes, state snapshots, transaction orders or block context. This lesson builds a replay record that exposes those differences before treating the output as a mystery.
Choose your reading route
In this guide
- 1. A virtual machine is an execution specification
- 2. Define the replay envelope before comparing outputs
- 3. The classroom program has one persistent counter
- 4. Validator N replays the ordered calls
- 5. Validator P independently obtains the same result
- 6. Mismatch case one: a different starting state
- 7. Mismatch case two: the same calls in a different order
- 8. Mismatch case three: a familiar name hides different code
- 9. Mismatch case four: the environment is different
- 10. Do not smuggle the host computer into consensus execution
- 11. Temporary working data is not automatically persistent state
- 12. A versioned rule is part of the input contract
- 13. Exercise: find the first divergence
- 14. Frequently asked questions
- 15. Sources and next reading
Start with the replay envelope and the two-call classroom example. Then inspect the four mismatch cases and the boundary between protocol inputs and a computer’s surroundings. Finish by writing a short diagnosis that identifies the first disagreement rather than merely comparing final numbers.
For stack instructions, types and linear-memory basics, use the existing WebAssembly mathematical foundation. This lesson has a different purpose: explaining why blockchain validators need reproducible state transitions and how to specify a meaningful comparison.
Back to contents · Next section
1. A virtual machine is an execution specification
A virtual machine defines an abstract execution environment. Its instructions have rules for interpreting values, accessing permitted data and changing machine state. Implementations can be written in different languages and run on different hardware while aiming to reproduce those prescribed effects.
The Ethereum EVM overview presents Ethereum execution as a state-transition process with deterministic output from defined input. Our classroom model uses that idea without claiming to reproduce the complete EVM or every part of Ethereum’s block processing.
Determinism is a conditional statement. “Same result” depends on the relevant inputs and rules being the same. It does not mean every call to a function always returns one fixed value regardless of state, caller, arguments or block context.
It also does not mean all implementations take the same number of milliseconds or store their internal data in the same host-memory layout. The protocol constrains the observable execution result and applicable accounting, not every physical detail of the computer performing the check.
Back to contents · Next section
2. Define the replay envelope before comparing outputs
For this lesson, a replay envelope means the complete supplied information needed to reproduce a particular classroom execution. The term is a teaching checklist, not a new transaction format.
- Rule version: the instruction and state-transition semantics being applied.
- Starting state: the persistent records before the first call.
- Executable identity: the exact program being interpreted, not just its display name.
- Ordered calls: the caller, operation and arguments for each step, in sequence.
- Permitted environment: shared contextual inputs such as the supplied block number.
- Resource assumptions: enough permitted execution budget for the stated successful path.
A comparison that omits one of these fields may accidentally test two different computations. The right response to a mismatch is first to align the envelope, then inspect the implementations.
Real systems require more detailed representations and verification than this list. An account’s state, code and transaction fields must be obtained from trustworthy, correctly identified data. The checklist helps organise the evidence; it does not authenticate the evidence by itself.
Back to contents · Next section
3. The classroom program has one persistent counter
The fictional program is called ArchiveCounter-C1. Its persistent record starts with counter=10 and permitted caller=K. It has two operations: add(n), which stores counter+n, and multiply(n), which stores counter×n.
The supplied rule version R1 first checks that the caller is K. It then checks that the supplied block number is at least 50. If both checks pass, it performs the requested operation using non-negative classroom integers and stores the result. All values used below are within the supplied range, so no overflow issue occurs.
A failed gate leaves the counter unchanged and returns a classroom rejection result. We do not model fees, account nonces, emitted logs or a real transaction’s failure semantics. These are deliberately excluded so that the persistent counter is the only state variable being calculated.
The permitted environment supplies block number 50. Both calls are from K. The ordered call list is first add(3), then multiply(2). There is enough execution budget for both calls, and no other transaction changes the counter between them.
These are non-financial records. The example does not deploy a contract, generate keys or authorise any real update. The program names and K are symbolic teaching identifiers, not on-chain addresses or code hashes.
Back to contents · Next section
4. Validator N replays the ordered calls
Validator N begins with the supplied persistent counter 10. For add(3), it checks caller K and block number 50. Both gates pass. It computes a temporary result 10+3=13 and stores 13 as the new persistent counter.
The second call begins from that updated state. multiply(2) therefore reads 13, not the original 10. The same gates pass, the temporary result is 13×2=26, and N stores counter=26.
The trace contains three persistent checkpoints: 10 before the calls, 13 after the first call and 26 after the second. Recording the intermediate 13 is valuable because it lets a later comparison identify whether disagreement began before or after the multiplication.
A final number alone hides this information. If another result is 26 for a different reason, equality of the final counter would not prove every intermediate effect agreed in a richer system. Here the complete supplied trace is small enough to inspect directly.
Back to contents · Next section
5. Validator P independently obtains the same result
Validator P runs a separate implementation. It receives the same R1 rules, ArchiveCounter-C1 program, starting counter 10, ordered calls and block number 50.
P checks the gates and derives 10+3=13, then 13×2=26. Its persistent checkpoints match N’s. That agreement is the expected result under the shared model, even if P’s processor is slower or its internal representation uses different host-language objects.
Neither validator needs to copy the other’s answer to complete this exercise. They each apply the rules. Nor does the example permit them to average 25 and 27 into 26 if their implementations disagree; averaging is not part of R1.
Agreement supplies evidence of consistent execution on this test. It does not prove that every possible input is handled correctly. The implementations might share a bug, the test might omit an important case, or both might be using the same wrong envelope. Broader testing and specification work remain necessary.
Back to contents · Next section
6. Mismatch case one: a different starting state
Suppose P starts from counter=11 while every other supplied field remains unchanged. P now computes 11+3=14, then 14×2=28. N still computes 26 from counter=10.
The first disagreement appears before executing the first call: the pre-state differs. This is not evidence that addition or multiplication is nondeterministic. The two validators have been asked to process different starting records.
A practical investigation should identify the state snapshot and its relationship to the selected parent block. A file named “latest-state” does not establish that two machines loaded the same content. Likewise, matching block height alone does not prove matching block identity or state.
Once the wrong pre-state is identified, do not hide the discrepancy by changing the final answer manually. A meaningful repair restores the correct input context and replays the computation. The exercise demonstrates diagnosis, not a procedure for modifying a live chain database.
Back to contents · Next section
7. Mismatch case two: the same calls in a different order
Now let P use the original counter 10 but reverse the calls. multiply(2) first produces 20; add(3) afterward produces 23. N’s original order still produces 26.
Both runs use the same two operation names and arguments, but not the same ordered input. Addition followed by multiplication is different from multiplication followed by addition. The complete state transition therefore depends on sequence.
This is why a replay record should preserve order rather than merely listing a set of transactions. A set containing add(3) and multiply(2) does not tell the reader which call observes the other’s state update.
The classroom result does not imply that every pair of operations is order-sensitive. Some commute under particular conditions. The point is that independence or commutativity must be established, not assumed from the fact that both transactions are individually well formed.
Choosing an accepted transaction order and executing that order consistently are related but different jobs. This lesson begins with the order supplied; it does not replace the consensus and fork-choice rules that determine which ordered history a node follows.
Back to contents · Next section
8. Mismatch case three: a familiar name hides different code
Suppose P’s program is incorrectly labelled ArchiveCounter-C1 but implements the second supplied call as multiplication by 3 rather than 2. It computes 10+3=13, then 13×3=39.
Here the first checkpoint matches, but the second diverges. The executable behavior is different. Matching a website label, source-file name or friendly contract title is insufficient to establish executable identity.
The Solidity 0.8.30 introduction distinguishes contract code and the data used during execution. In an EVM workflow, executable bytecode matters; a high-level source description alone is not the exact object the virtual machine interprets.
A reproducible build or source-verification process can help connect readable source to deployed code, but that is a separate evidence task. For our exercise, exact program identity is simply supplied. We do not claim that comparing names or seeing a source-code badge completes that verification.
Back to contents · Next section
9. Mismatch case four: the environment is different
Keep the original program, counter and call order, but supply block number 49 to P. Under R1, both calls fail the block-number gate and leave counter=10. At block number 50, N’s calls pass and end at 26.
Again, the inputs differ. The rule is deterministic in both cases. A test that records only caller and arguments while omitting the permitted environment has left out a value that changes the path.
The Solidity 0.8.30 global-variable reference identifies contextual values such as block.number, block.timestamp and msg.sender. For on-chain execution these must be interpreted in the appropriate execution context, not replaced with whichever values a validator’s operating system happens to provide.
The same reference cautions that off-chain evaluation can supply its own context. A simulated call is therefore not automatically a replay of a particular real block merely because the operation name and arguments match.
The block number gate in this worksheet is a simple protocol-input example. It does not prove that a physical event happened at a particular time, and it is not a scheduling service that wakes the program by itself.
Back to contents · Next section
10. Do not smuggle the host computer into consensus execution
Imagine changing the program so that it adds 1 when the validator’s local wall clock shows an even second and adds 2 otherwise. Two validators could then receive identical recorded chain inputs but produce different results because of their private clocks.
Our R1 model does not allow that hidden input. To reproduce a result, any relevant environment value must come from the permitted, shared execution context under defined rules. Replacing the local clock with a supplied block-context value changes the design question; it does not make that value an infallible real-world clock.
Similarly, asking each validator to fetch a website during execution would introduce availability, timing and response differences unless the protocol explicitly defined a shared input mechanism. A web page could change between requests or return different content to different observers.
The pinned Solidity introduction describes EVM execution as isolated from direct host-network and filesystem access. External facts require an appropriate mechanism for bringing data into the system; the oracle lesson examines that boundary. Reproducible processing cannot by itself establish the truth of the external fact supplied.
This is a scope rule, not a claim that blockchain software never uses networks. Nodes exchange transactions and blocks outside the contract’s execution environment. Network communication around a virtual machine is different from an unrestricted website request inside consensus-critical contract code.
Back to contents · Next section
11. Temporary working data is not automatically persistent state
The classroom calculation uses temporary results 13 and 26 before storing them. A temporary value and a persistent record have different lifetimes, even when they contain the same integer at one moment.
The Solidity 0.8.30 introduction separates stack, memory, persistent storage and transient storage. In the EVM, these are distinct areas with different rules. This lesson does not need their full layouts; it needs the discipline of asking which data survives the relevant execution boundary.
In our model, only the explicit store changes the persistent counter. If an implementation calculates 13 in a temporary variable but forgets the store, the next call cannot correctly assume that persistent state became 13. The replay trace should show both the computed value and the committed classroom record.
Do not equate all temporary data with one category in a real virtual machine. Call-frame memory and transaction-scoped transient storage have different lifetimes. Nor should the toy’s word “store” be confused with a complete description of blockchain commitment or finality.
We are tracking a supplied successful application-state update. Whether the containing block remains selected or becomes final belongs to the chain-evidence layer, not to the lifetime of a local variable.
Back to contents · Next section
12. A versioned rule is part of the input contract
An executable instruction has meaning under a specified set of rules. A network upgrade may change available operations, accounting or other execution behavior. Replaying historical data under an unspecified “current” rule set can therefore be an ill-defined comparison.
The official Ethereum execution-specifications repository tracks execution-layer rules and network upgrades. Its development contents are not, by themselves, proof that every listed change is active on a particular network. Identify the applicable fork and context before using a rule in a claim.
For our example, R1 is fixed throughout the main replay. A hypothetical R2 that changes the gate or operation semantics would define a different test. Agreement under R1 does not establish agreement under R2 without checking what changed.
Version labels alone also need unambiguous references. Two documents both called “R1” but containing different instructions defeat the purpose. A useful record identifies the actual specification and executable artifacts used, along with the input state and ordered calls.
Back to contents · Next section
13. Exercise: find the first divergence
Start from the main envelope: R1, ArchiveCounter-C1, counter 10, caller K, block number 50, add(3) then multiply(2), sufficient budget and no intervening calls.
- What persistent counter values should N and P record after each call?
- P instead starts from counter 11 and ends at 28. Is the first discrepancy an arithmetic instruction or the pre-state?
- P reverses the calls and ends at 23. Were the complete inputs identical?
- Both reach 13 after the first call, but P then multiplies by 3 and reaches 39. Which part of the replay envelope should be checked?
- P uses block number 49 and remains at 10. Does this show that R1 is nondeterministic?
- Both implementations return 26. Does this prove the program correctly represents a real archive process or that the containing block is final?
Answers and reasoning
- Both should record 13, then 26. The second call reads the updated persistent state.
- The pre-state. It differs before any call executes: 11 rather than 10.
- No. The ordered sequence differs, even though the unordered collection of operation names and arguments matches.
- Check executable identity and the applied operation semantics. The first matching checkpoint narrows the investigation but does not authenticate the code.
- No. A permitted environment input differs, causing the defined gate to reject both calls in this classroom model.
- No. Agreement on one execution does not prove application truth, general implementation correctness or finality. Those require different evidence.
Extension: omit the first persistent write
Assume a faulty implementation computes 13 after add(3) but leaves the persistent counter at 10. The next multiply(2) reads 10 and stores 20. The correct main trace ends at 26.
The first divergence is the missing persistent write after the first call, not the multiplication arithmetic. This is why a useful trace records state transitions rather than only temporary calculator answers.
Back to contents · Next section
14. Frequently asked questions
Do all validators need identical computers?
No. They need conforming behavior under the applicable rules and inputs. Hardware speed and implementation language can differ without changing the prescribed result.
Does deterministic mean secure?
Not by itself. A deterministic program can consistently compute the wrong application result or enforce an inadequate permission rule. Determinism is one property with a specific scope.
Can code use the block timestamp?
Where the execution rules expose it, code can read that contextual value. It is not the validator’s arbitrary wall clock and does not independently prove a real-world event’s timing.
Is the EVM the same virtual machine as WebAssembly?
No. They have different specifications and environments. The linked WebAssembly lesson teaches useful abstract-machine foundations; this replay exercise focuses on blockchain execution evidence.
Back to contents · Next section
15. Sources and next reading
Sources checked on 12 October 2026, Singapore time. Solidity references are pinned to version 0.8.30; they are not presented as the latest release or a complete specification of every active network rule.
- Ethereum EVM overview: deterministic state-transition framing.
- Solidity 0.8.30 introduction: executable code, isolation and data-area distinctions.
- Solidity 0.8.30 global variables: permitted execution context and off-chain-context caveats.
- Ethereum execution specifications: versioned execution rules and upgrade context.
- WebAssembly mathematical foundation: prerequisite stack, type and memory reasoning.
Continue to smart-contract conditions for a fuller application-state machine, and to storage, events and indexing for the difference between persistent records and observation interfaces. When two results disagree, preserve the replay envelope and locate the first differing input or transition before proposing a cause.
