Architecture

1) What

Madara is built by the Starkware Exploration Team a.k.a Keep Starknet Strange (opens in a new tab) in order to support the fractal scaling vision (opens in a new tab) brought up by Starkware years ago.

There are many reasons why one would want to have their own L3 rather than building directly on Starknet:

  • Hyper-scalability
  • Better Control
  • Privacy
  • Cheaper/Simpler interoperability

fractal-scaling

Madara opens for a whole new field of innovation; application developers can experiment with different data availability solutions, consensus algorithms, proving schemes.

You will find in the Build On Madara section details about these different solutions being explored and trade-offs.

2) H

The core component of Madara is the starknet pallet. It provides a Starknet compatibility layer for Substrate. Existing Cairo code can be executed seamlessly thanks to this.

This pallet, in addition to the RPC module, enables Starknet block emulation, validates starknet-encoded transactions and makes it possible to deploy an existing Starknet DApp on Madara without any changes.

3) A

You might be asking, how are we able to map Substrate blocks to Starknet blocks ?
Well we use the wrapper block (opens in a new tab) method first used by Parity in frontier, the EVM compatibility layer for Substrate.

Wrapper block is a strategy in Substrate to allow it processing blocks that were not originally designed with Substrate in mind.

It does add a slight performance overhead but it's negligible compared to other components of the runtime.

The Madara Stack

For now, let's focus on the high level overview and scrap the surface of each of these layers.

stack

Execution

The execution layer defines the way blocks are executed and state diffs are produced. Madara makes it easy to switch between two different execution crates, blockifier (opens in a new tab) by Starkware and starknet_in_rust (opens in a new tab) by LambdaClass.

Cairo VM

Under the hood, it will always run the Cairo VM (opens in a new tab) which is being maintained by Starkware and LambdaClass in Rust. Cairo (CPU Algebraic Intermediate Representation) is a programming language for writing provable programs, where one party can prove to another that a certain computation was executed correctly.

ℹ️

There are on-going experiments to tweak the Cairo VM by changing for example the field size to Goldilocks which could lead to a major performance increase.

Settlement

As a Validity Rollup, any madara-chain's state should be able to be built solely by looking at its settlement layer.
Madara itself doesn't make any assumption regarding the settlement layer chosen.
If we take the example of an L3, then it would regularly send a proof to Starknet for a batch of L3 blocks.

ℹ️

For example Starknet currently settles every ~5 hours mostly because its cost to settle on Ethereum. While an L3 could in practice settle way more often on Starknet for a fraction of the cost.

The settlement term can be misleading, it's important ultimately to make the difference between SOFT and HARD finality.

Once HARD finality is reached, meaning the transaction has been proven and verified on the settlement layer then it's set in the stone. SOFT finality is ultimately about improving the user experience, however we will see that by decentralizing the sequencing layer we can aim for a quite strong soft finality.

Sequencing

The sequencing is done by Madara and can be tweaked in different ways to fit your own needs.
For instance it could be a simple FCFS, PGA or more complex schemes such as Narwhall & Bullshark or HotStuff (opens in a new tab).

The ordering of transactions is fairly important to ensure a good MEV protection and ensure a fair ordering of transactions. Although, in some cases such as app-specific chains, encrypted mempools can be implemented to ensure a fair order.

Madara is by default a decentralized sequencer, multiple nodes can join the network and the default consensus is GRANDPA & BABE (opens in a new tab), the one used by most of polkadot parachains. We believe that while centralized sequencers is the industry standard for now, decentralizing the sequencing layer is of the upmost importance to have actual censorship-resistant systems.

Data Availability

Currently, Starknet operates in rollup mode as described here (opens in a new tab). Data availability (DA) means that the full state tree is always available, which provides users with the security of knowing that if StarkEx ever stops functioning, they can prove custody of their funds.

Many different DA schemes are being experimented as we speak for Madara:

  • Validium mode: Data is available off-chain. The Data Availability Committee (DAC) stores it, providing a trusted solution
  • Avail
  • Celestia
  • Eigen DA
  • Rollup Mode

Each DA mode comes with its own set of assumptions and app developers are free to experiment and go with whatever they feel the most comfortable with.

Governance

Snapshot X would be the main choice for governance in Madara as it's a fully on-chain governance system which is built upon storage proofs. You will see in the different Madara hacks such as the Turbo VM one why storage proofs will be the first choice of bridging mechanism within the Madara ecosystem.

Other governance mechanisms are also being explored such as native substrate governance pallet (opens in a new tab). Given what we witnessed in the past, one of the core value Madara comes with is on-chain governance. We truly believe that governance should always be enforceable on-chain as it is the case within the Cosmos and Polkadot ecosystems.

🧩

One of the best features Madara offers thanks to being built with Substrate is forkless upgrades. You can read more about it here (opens in a new tab).