The NEAR Protocol team pulled off one of the riskiest engineering operations in blockchain history: replacing the smart contract engine on a live mainnet, with the vast majority of users not even noticing. As former NEAR core developer Vadim explained, this seamless transition was the primary goal of the update.

For years, NEAR used its own forked engine, Wasmer — NearVM. This "private compiler," as Vadim called it, acted as a kind of "tax" on development: every Rust language update, every new security feature fell solely on the internal team's shoulders. The project was once simply lucky — it stopped syncing with the original Wasmer just before a critical vulnerability was discovered in it. In essence, NEAR was sitting on a powder keg.

The replacement with Wasmtime — an industry standard from the Bytecode Alliance — was inevitable. To confirm the safety of the migration, network nodes ran real traffic through both virtual machines in parallel and cross-checked every result. The results are impressive: execution output matched completely, while the discrepancy in fees was less than 0.002%. At the same time, contract execution itself sped up by roughly four times.

A Forbidden Solution and an Engineering Gambit

The main challenge was not even execution speed, but compilation. On the NEAR network, contract deployment is compiled directly within a 600-millisecond block. An optimizing compiler has no upper time limit, which opened a path for attack. The team created a test contract of 128 KB, whose compilation took about 7 seconds — enough to miss the block and slow down the entire network.

The obvious solution — setting a time limit on compilation — turned out to be forbidden. As Vadim explained, different validators spend different amounts of time on compilation, so a borderline contract would be accepted by some nodes and rejected by others. The consequence would be a network split caused solely by a compiler setting. Consensus requires complete predictability, even in build time.

The team found another way out. They implemented Winch — a single-pass backend for Wasmtime — and added the missing features to it. As a result, the "worst-case compilation" dropped from 7.6 seconds to 36 milliseconds. Working off-chain provided a "luxury unavailable to the protocol": compilation can be outsourced to a separate type of handler not tied to executing nodes.

The Nearcore 2.12 release switched NEAR's execution environment from NearVM to Wasmtime. As developer Anton emphasized, nothing changed for developers and users — and that's the whole point: "The team closed critical technical debt without breaking anything."

Analyst's comment: This operation is a brilliant example of the maturity of NEAR's engineering culture. Replacing the VM under mainnet load without a single failure is a level achievable by only a few. A 4x speedup and the elimination of a consensus attack vector is not just an update, but a fundamental strengthening of the network's security and performance.