• Fantom Logo
  • Technology Tools Enterprise Ecosystem Developers
  • Fantom DeFi
      • Sub menu

        Intro to Fantom

        Fantom is a fast, scalable and secure platform for digital assets.

      • Sub menu

        Stake on Fantom

        Earn rewards by securing the network.

      • Sub menu

        FTM token

        FTM is the primary token of the Fantom ecosystem.

      • Sub menu

        The Consensus

        Discover Lachesis, Fantom’s ultra-fast consensus protocol.

      • Sub menu

        Opera Chain

        The Fantom mainnet, with staking and EVM support.

    • WALLETS

      • Sub menu

        Fantom Wallets

        Store, send, receive, and stake FTM on desktop, mobile, and hardware wallets.

      EXPLORER

      • Sub menu

        FTMScan

        A new Fantom explorer built by the Etherscan team.

      • Sub menu

        Opera Explorer

        Explore the network transactions, blocks, and nodes on Opera.

      • Sub menu

        OKLink

        OKLink is an alternative explorer for the Fantom network

    • GUIDES

      • How to use Fantom Wallet

      • How to set up Ledger Nano with Fantom

    • Sub menu

      Enterprise

      Discover Fantom’s solutions for enterprise clients.

    • Sub menu

      Solutions

      Take a deep dive in real world use cases.

      • Sub menu

        About us

        Meet the people behind Fantom.

      • Sub menu

        Partners and integrations

        Learn how we're creating a cross-chain ecosystem on our innovative platform.

      • Sub menu

        Blog

        Learn about Fantom through our general and tech articles.

      • Sub menu

        Podcasts and interviews

        Check out all the Fantom related interviews and AMAs.

      • Sub menu

        FAQ

        Do you have questions? We have answers!

      • Sub menu

        Community

        Join our wonderful community and share ideas.

      • Sub menu

        Careers

        Come work with us!

    • Sub menu

      Documentation

      Start building on Fantom

      GET STARTED

      Deploy a smart contract Create a fixed-cap asset Create a local test network GraphQL API docs

      GUIDES

      Set up Metamask Run a validator node
    • Sub menu

      Technical papers

      Read our technical papers and latest research essays.

      Covalent API
      The Graph's Subgraphs
      Verified contracts
      Frontend JS Utilities
      DeFi Smart Contracts
      Developers’ chat
Fantom Logo
menu
Fantom Logo close
  • Technology
        • Sub menu

          Intro to Fantom

        • Sub menu

          Stake on Fantom

        • Sub menu

          FTM token

        • Sub menu

          The Consensus

        • Sub menu

          Opera Chain

  • Tools
      • WALLETS

        • Sub menu

          Fantom Wallets

        EXPLORER

        • Sub menu

          FTMScan

        • Sub menu

          Opera Explorer

        • Sub menu

          OKLink

        GUIDES

        • How to use Fantom Wallet

        • How to set up Ledger Nano with Fantom

  • Enterprise
        • Sub menu

          Enterprise

        • Sub menu

          Solutions

  • Ecosystem
      • Sub menu

        About us

      • Sub menu

        Partners and integrations

      • Sub menu

        Blog

      • Sub menu

        Podcasts and interviews

      • Sub menu

        FAQ

      • Sub menu

        Community

      • Sub menu

        Careers

  • Developers
      • Sub menu

        Documentation

      • GET STARTED

      • Deploy a smart contract

      • Create a fixed-cap asset

      • Create a local test network

      • GraphQL API docs

      • GUIDES

      • Set up Metamask

      • Run a validator node

      • Covalent API

      • Verified contracts

      • DeFi Smart Contracts

      • The Graph's Subgraphs

      • Frontend JS Utilities

      • Developers’ chat

      • Sub menu

        Technical papers

blog-image
February 3, 2023

Fantom Virtual Machine & Storage: The Roadmap

Education

Ash V. Khatibi

Content Writer at Fantom.

Quantum Miami was a blast filled with exciting insights into the bright future of Fantom, including promising upgrades that will elevate the platform to new heights, such as the Fantom Virtual Machine.

In his presentation, Michael Kong, the CEO of the Fantom Foundation, outlined the projects that will lead to faster block processing on Fantom, and hence a more scalable network.

Let’s unwrap the presentation to see what’s in store for Fantom!

Blockchain’s scalability problem

Before we continue, let’s look at the inherent scalability issues with current blockchain-based systems.

The United States sees a staggering 100 million credit card transactions daily, with VISA reportedly handling 24,000 transactions per second, around 2 billion daily transactions. To reach these speeds, blockchain systems often trade scalability, decentralization, and security. However, the long-term goal for Fantom is to achieve all three goals at the same time.

The Fantom mainnet is a decentralized network run by nodes and uses an asynchronous and leaderless consensus mechanism; similar to other smart contract platforms, Fantom verifies blocks and transactions, executes smart contracts, and stores their states. The state of a smart contract is its current data at a particular point in time, such as its balance of FTM.

Smart contracts on Fantom store their state in a StateDB database containing the contract states. The Ethereum Virtual Machine executes the code of these contracts and updates their states in the StateDB.

Given that the current release of Fantom leverages Ethereum technology, including its storage system and virtual machine, the network is not optimized for scalability. Hence, identifying the exact bottlenecks that slow down Fantom is critical to upgrading the platform, which is the focus of the testing framework named Project Aida.

Aida: Identifying the bottlenecks

Aida is a testing framework for finding bottlenecks and testing. As part of this effort, we conducted an experiment for the first 40 million blocks of the mainnet and successfully identified block processing components dominating the runtime.

As illustrated in the chart, the EVM consumed 13% of the time on processing and executing smart contracts. The StateDB consumed 84%, spent on the EVM accessing and updating the state of the smart contracts.

The excessive time taken by the EVM to access the storage in the StateDB necessitates an improved storage system, which is the goal of Project Carmen.

Carmen: New storage system

Currently, the StateDB stores the current state of the blockchain in a key-value database (e.g., LevelDB, PebbleDB). The state is encoded with a complex data structure called Merkle Patricia Trie (MPT) that is used by Ethereum and Fantom’s mainnets. For example, a Fantom contract address could have a specific key that accesses the database entry for the contract’s total FTM balance, which is the value.

The currently-used key-value database with MPT results in slow StateDB accesses. To address this, Fantom came up with a radical new design for StateDB and has implemented  a new file-based StateDB using ideas of address/key value translations via an index.

The file-based StateDB allows for a more flexible and scalable way of storing state information compared to key-value stores as it eliminates the need to map the information to tries that are later mapped to key-value pairs in the StateDB. It also eliminates the need for complex traversals and management of the key-value data, making it easier to manage and update the state information more efficiently.

Let’s look at an example. Currently, looking up the totalSupply variable (which is a 256-bit address) of a smart contract in the StateDB requires the following steps:

(contract address, storage key) -> storage value = (0x0DE2f6ff6887579593702a0bC573be0bC6BB0f80, "totalSupply") -> 1000

The first part, contract address and storage key, will be encoded as paths in the Merkel Patricia Trie. The trie will be fragmented into various key-value pairs. As a consequence, up to approximately 100 key-value pairs could be accessed in the key-value database for this example.

(contract address, storage key) -> storage value = (123, 456) -> 1000

In this example, the contract address and storage key are both represented by numbers in a compact range or rather, ordinal numbers. The use of ordinal numbers in the set of addresses/keys instead of storing addresses/keys verbatim reduces the amount of storage required and ensures that there are no gaps in the address space.

The new storage system will also not use RLP encoding, which saves space, and will not actively prune MPT, which saves processing time and works similarly to virtual memory in modern operating systems.

MPT, short for Merkle Patricia Tree, is the data structure used by Ethereum and the current Fantom mainnet to store the states of smart contracts. However, it consumes a significant amount of storage space and requires many operations to read and write data.

An improved storage system is great, but it also requires a high-speed virtual machine to execute smart contracts and update their state in storage, which is the focus of Project Tosca, or the Fantom Virtual Machine.

Tosca: Fantom Virtual Machine

The Fantom Virtual Machine (FVM) is the upgrade that will replace the EVM and increase the speed of execution on Fantom.

For our developer community, there’s no need to worry! The FVM will be fully Solidity and Vyper compatible, allowing you to continue using the same development tools.

The Fantom Virtual Machine uses dynamic translation, where the code is translated into a more efficient instruction format inside the client, allowing for more efficient execution of the smart contract. This is achieved through more efficient implementation techniques and “super-instructions” which are efficient representations of frequently occurring patterns in code.

The super-instructions consist of multiple instructions that can be executed in one instance. For example, three instructions can be merged into one, so the FVM would only have to execute one instruction, rather than three. They are adaptable and can change over time to reflect changing patterns in the code.

This results in an efficient dispatch and execution of smart contracts, meaning the system is optimized for running the smart contract as efficiently as possible, reducing the processing time and resources required.

Experiment

Outlining the theory is fine, but proving it in practice is better. We conducted an experiment on the Fantom mainnet data, using a fully pruned version of the current Fantom mainnet (i.e. what validators use) compared to the new FVM and fully pruned storage system.  

The experiment used the first 40 million mainnet blocks and focused solely on block processing. The findings are shown in the charts below:

Transactions per Second
Transaction Rate (8.1x faster)
Storage Use (98% less storage)

As depicted above, there were significant improvements in transactions per second, averaging approximately 4500 per second in our experiment alone. The transactions were 8.1x faster and the blocks used 98% less storage.

This speed could theoretically allow for approximately 400 million daily transactions, four times the number processed daily by VISA in the United States.

The results speak for themselves. The implementation of a new storage system and virtual machine could significantly improve the performance of the Fantom network and make it easier for people to run nodes at a significantly lower cost with much faster syncing times.

Read more

Card image cap
Simplify DeFi – Fantom Community Spotlight
READ STORY
Card image cap
Gitcoin Grants Round 1: Distribution Announcement
READ STORY
Card image cap
Mummy Finance – Fantom Ecosystem Spotlight
READ STORY
Card image cap
Simplify DeFi – Fantom Community Spotlight
READ STORY
Card image cap
Gitcoin Grants Round 1: Distribution Announcement
READ STORY
Card image cap
Mummy Finance – Fantom Ecosystem Spotlight
READ STORY
  • Technology
    • Intro to Fantom
    • Stake on Fantom
    • FTM token
    • The Consensus
    • Opera Chain
  • Tools
    • Fantom Wallets
    • Opera Explorer
  • Enterprise
    • Enterprise
    • Solutions
  • Ecosystem
    • About us
    • Partners and integrations
    • Blog
    • Podcasts and interviews
    • FAQ
    • Community
    • Careers
    • Media kit
  • Developers
    • Documentation
    • Technical papers
    • Covalent API
    • Verified contracts
    • DeFi Smart Contracts
    • GraphQL API
    • Frontend JS utilities
    • Developers’ chat
Social
  • Twitter
  • Discord
  • Telegram
  • Telegram ANN
  • Reddit
Fantom Logo

© 2023 Fantom Foundation

  • Cookie Policy
  • Privacy Policy
  • Terms of Service
  • Cookie Policy

The information on this website is for informational purposes only. It contains high-level summaries and is not intended to include all material information regarding the Fantom ecosystem and risk factors associated with holding FTM.