Innovating the Fantom Virtual Machine
First introduced by CEO Michael Kong at Consensus 2022, the FVM (Fantom Virtual Machine) is by far the most anticipated upgrade to the Fantom protocol.
The FVM will evolve the Fantom blockchain into a massively scalable Layer-1, with the same fast transaction finality, low fees, and atomicity – a single-state ledger – that you are used to. This means no fragmenting of the main chain with Layer-2s or subnets that sacrifice decentralization, raise security risks, and complicate the overall user experience.
Current state-of-the-art technology limits the number of achievable blockchain transactions to fewer than 10M/day. Greater performance conventionally requires centralizing validators or resorting to sidechains or Layer 2s.
FVM development is guided by the conviction that the user journey must remain seamless and straightforward, with none of the added complications of the usual scaling solutions. Moreover, blockchain infrastructure needs to keep pace with the increasing popularity and sophistication of dApps and the continuing influx of crypto adopters.
In this article, we dive into ongoing work on the FVM to explain how Fantom R&D and engineering are meeting vital crypto industry needs. Crucially, we also address how building is being done with an approach Fantom Chief Research Officer Bernhard Scholz has called an innovation-first development model.
Faster, efficient databases
Fundamentally, decentralized ledgers are databases stored in local nodes running the blockchain. Conventionally, the Merkel Patricia Trie (MPT) has been the go-to data structure as it provides both cryptographic hashes for the state of a database and database versioning.
But the MPT is limited by two factors. It is inherently slow, and second, as a tree data structure, any value changes in leaf nodes must reflect through to parent nodes via hash calculations, which can be expensive. The Fantom solution organizes all the changes to a block into a change set, for which the hash is calculated more efficiently and at less cost.
The solution
The Fantom solution rests on adopting an entirely new data structure that compacts storage addresses and relies on files rather than key-value databases.
We start with the basic observation that the keys of blockchain databases are too long, which makes the lookup mechanism very slow. As a point of comparison, note that old computers have 4 -byte address spaces, and modern 64-bit computers (such as Intel/Arm) have an 8-byte address space. The Ethereum Virtual Machine has a 52-byte address space comprised of the contract address (20 bytes) and the storage address (32 bytes).
As a simple example, think of a long list of addresses that looks like {100005 … 100000, 1E16 … 1E232, 1E34}.
To condense the large address space of the EVM, we propose a new specialized approach that assigns ordinal numbers to contract/storage addresses. Take the example above: the first observable address would receive the number one, the second observable address the number two, and so on.
With this new numbering scheme, we can do away with key-value stores and directly input the storage values of the EVM into a file that references the ordinal numbers. Access is fast because the record size is fixed-length, and effective caching techniques can be deployed. This kind of technology can be compared with virtual memory and swapping in modern operating systems such as Linux.
This elegant solution via compaction makes address lookups significantly faster than key-value stores, and the overall result also speeds up read/write storage operations by several orders of magnitude.
Adaptive smart contract execution
Current EVM smart contract execution works as a naive interpreter, running a simple loop that sequentially fetches instructions from the EVM byte code, decodes it, and executes instruction operations. The overall process is inefficient since the sheer volumes of instructions that generally need to be executed in a contract create instruction dispatch performance bottlenecks.
The solution
The Fantom approach is two-part, including “super-instructions” and implementation of C++.
Super-instructions might be easily understood through the concept of “dynamic translation.” Consider a complex smart contract with a sequence of uninterrupted instructions – called a “basic block.”
The FVM can translate sub-sequences of this basic block into a new, single “super instruction” that can execute the basic block in a single dispatch, which is much faster than executing multiple instructions one by one. The translation of a basic block to the new super instruction format can be stored in the cache/code buffer for future use so that when a basic block occurs again, the translation to super-instructions does not need to be repeated.
Super-instructions are incredibly powerful amalgamations, but one can’t create an unlimited number of them. Drawing on the principles of discrete optimization theory, Fantom engineers are configuring the system to identify the best super instructions for future blocks from previously executed blocks.
Another consideration is that the EVM dispatch mechanism tends to be slow in its current iteration in the GO language. The R&D team is experimenting with code rewritten in C++. The new version is in testing, where the benchmark for success is speed with uncompromised security.
Accelerated block processing
Post consensus, blockchains conventionally process transactions sequentially. However, we notice that many transactions inside a block do not depend on each other and could be executed in parallel to accelerate block processing further.
The solution
Researchers have discovered, however, that two to three transactions in a block can be processed in parallel without clashing – instances where transactions needto be processed sequentially because they are connected or influence each other.
Ongoing experimentation centers on concurrent transaction control to enable parallel processing but with an automatic rollback function that corrects for clashing transactions. Initial testing indicates a 2X or 3X performance increase over the current system.
Performance engineering
A major development hurdle in blockchain R&D has been the development of tools that enable rapid testing.
Until now, evaluating even small changes has taken impossibly long since testing demands running data from the entire blockchain.
The solution
Thanks to the team's efforts, testing that once took weeks now takes minutes or, at most, an hour. The key is to extract minimally required blockchain data in a process described in an earlier blog post focused on off-the chain testing.
Collections of simplified data represent what in Computer Science is called an “embarrassingly parallel workload,” where the problem – here of processing data – can be divided into parallel tasks. Rather than processing data block by block for testing, simplified data can be bulk processed rapidly and in parallel.
Efficient analytical tools are critical to the agile development environment at Fantom, and performance engineering underpins the entire FVM development process.
An orchestrated, iterative approach
The development of the FVM has brought with it a realignment of the team philosophy that can be described as moving from the integration of Ethereum code into Go Opera to the innovation of an entirely novel EVM-compatible platform.
The clearest sign of this shift is reflected in the team's development practices. Breakthrough technology does not emerge from nothing; it rests on extensive experimentation, failure, and revision.
Accordingly, the goal at Fantom is to focus much more intensely on agile testing and iteration of solutions. The overall aim is to experiment with many different possibilities and quickly isolate those that work best.
It is an ethos that draws on the creative potential of the entire team rather than an individual and equates success with consistent progress rather than a determinate goal.
Progress is happening at a steady clip. Follow our Twitter and blog to keep up with the latest developments.