Massa Labs

Massa Labs

Massa Labs is a company that has developed its own Layer 1 and is also dedicated to contributing to leading Rust projects, including Madara. The company has innovatively created a system, called Bonsai-trie, for efficiently storing the chain's state data and calculating the root hash.

Massa Labs has played a crucial role in enhancing the Madara project by eliminating the constraint of no_std.

Bonsai trie

The Bonsai Trie library (opens in a new tab) enables the storage of the Starknet state (opens in a new tab) as a Trie with various optimizations. This work draws inspiration from the bonsai library found in the Besu client for Ethereum.

Key optimizations include:

  • Organizing trie nodes in the database by location to enable implicit pruning.
  • Storing key/value pairs in a separate database section from the trie branches, facilitating instant reads.
  • Recording only one state in the database alongside patches describing changes made in the latest blocks, allowing for state rollback.

These optimizations in state trie management will enable Madara to consume fewer resources and spend less time computing the root hash for each block.

The allows to store the state of Starknet as a Trie (opens in a new tab) with multiple optimizations. This work is deeply inspired by the bonsai library that exists on the Besu client for Ethereum (opens in a new tab). The main optimizations are :

  • We have the nodes of the trie by location in the database allowing implicit pruning.
  • We save the key/value pair in a different part of the database than the trie branches allowing instant read.
  • We save only one state on the database along with patches describing the changes made in the latests blocks allowing to rollback the state. These optimizations on the state trie management will allow Madara to use less resources and spend less time computing the root hash for each block.

Modifications on Madara source code

Massa Labs has actively contributed to Madara by removing the constraint of using no_std versions of the blockifier and the cairo-vm. In a pull request (PR) (opens in a new tab), Massa Labs utilized a fork of the Polkadot SDK that executed the runtime in native code instead of WASM. Consequently, the code used does not require compatibility with no_std. These changes provide more flexibility during development and enhance the project's capabilities.

Future work

Massa Labs plans to continue collaborating with the Starknet Exploration Team to further enhance Madara and the ecosystem. Explore all of their projects on GitHub (opens in a new tab).