Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 5b41fa6

Browse files
Merge pull request #51 from NilFoundation/nil-core-concepts
Nil core concepts
2 parents f2d2b21 + 1392c48 commit 5b41fa6

29 files changed

+1435
-47
lines changed

docusaurus.config.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
import { themes as prismThemes } from 'prism-react-renderer';
88

9+
import remarkMath from 'remark-math';
10+
import rehypeKatex from 'rehype-katex';
11+
912
/** @type {import('@docusaurus/types').Config} */
1013
const config = {
1114
title: '=nil; Foundation Documentation Portal',
@@ -82,13 +85,24 @@ const config = {
8285
[
8386
'@docusaurus/plugin-content-docs',
8487
{
85-
id: 'zksharding',
86-
path: 'zksharding',
87-
routeBasePath: 'zksharding',
88-
sidebarPath: './sidebars.js'
88+
id: 'nil',
89+
path: 'nil',
90+
routeBasePath: 'nil',
91+
sidebarPath: './sidebar-nil.js',
92+
remarkPlugins: [remarkMath],
93+
rehypePlugins: [rehypeKatex],
8994
}
9095
],
9196
],
97+
stylesheets: [
98+
{
99+
href: 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
100+
type: 'text/css',
101+
integrity:
102+
'sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM',
103+
crossorigin: 'anonymous',
104+
},
105+
],
92106
themeConfig:
93107
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
94108
(
@@ -113,6 +127,11 @@ const config = {
113127
src: 'img/nil-logo.png',
114128
},
115129
items: [
130+
{
131+
position: 'left',
132+
label: '=nil;',
133+
to: '/nil/intro'
134+
},
116135
{
117136
position: 'left',
118137
label: 'zkLLVM',
@@ -124,11 +143,6 @@ const config = {
124143
label: 'Proof Market',
125144
to: '/proof-market/intro'
126145
},
127-
{
128-
position: 'left',
129-
label: 'zkSharding',
130-
to: 'https://nil.foundation/blog/post/nil_zkSharding'
131-
},
132146
{
133147
position: 'left',
134148
label: 'Crypto3',

nil/core-concepts/accounts.mdx

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Accounts
2+
3+
## Definition
4+
5+
In =nil;, an account is the minimal unit of data for sharding. An account consists of an address, its balance, its storage root and the hash of its source code.
6+
7+
Each execution shard handles only a dedicated part of all accounts in the global state of the cluster while the consensus shard stores the mapping of accounts and their corresponding shards.
8+
9+
:::info[Execution shards]
10+
11+
Each execution shard acts as a separate blockchain that starts from a genesis block and continues until a possible last block. When an account is placed in a shard, its location persists unless [**contract co-location**](./contract-co-location) is employed.
12+
13+
:::
14+
15+
## Security and rollbacks
16+
17+
In the case of malicious nodes taking over a shard (and forcing commitment to corrupted data), validators for all other execution shards must initiate a rollback of all affected accounts.
18+
19+
The rollback must revert accounts to their last verified state, meaning the state before the corrupted shard had started sending messages to other shards.
20+
21+
There exist two possible methods for rolling back accounts.
22+
23+
* The 'carpet' method where the entire state is reset to the last previous valid state
24+
* The 'surgical' method where only the corrupted accounts are rolled back
25+
26+
=nil; employs the 'carpet' method: during a rollback, all accounts are reset to their previous valid states regardless of whether they were affected by the attack.
27+
28+
:::tip[Justification]
29+
30+
Rolling back all accounts might seem excessive.
31+
32+
However, attacks propagate faster than state transition proofs are generated. While the cluster is figuring out what accounts to roll back, the attack might grow in size, making the 'surgical' method costly and risky.
33+
34+
For now, this makes the 'carpet' method preferable despite its limitations.
35+
36+
:::
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Contract co-location
2+
3+
## Definition
4+
5+
[**Cross-shard communications**](./shards-parallel-execution#message-passing-checks) are a built-in feature of the =nil; protocol ensuring horizontal scalability with no fragmentation.
6+
7+
However, =nil; also supports contract co-location, which is a technique for ensuring that two accounts are located on the same shard. In this case, interaction between these accounts does not require cross-shard communications.
8+
9+
In plain terms, co-location is a request made to change the value stored under the account's address in [**the mapping of accounts and shards**](./accounts) stored in the consensus shard.
10+
11+
:::note[Explanation]
12+
13+
When two accounts (Account 1 and Account 2) are co-located, communications between them can occur synchronously similarly to regular Ethereum transactions.
14+
15+
However, this is not the case if Account 1 and Account 2 are placed in different shards and Account 1 calls a function in Account 2. In this situation, the transaction from Account 1 must create another transaction that subsequently performs an async call to the function in Account 2. This async transaction could then be executed in a future block in the shard where Account 2 is located.
16+
17+
This ensures that sharding does not result in fragmentation.
18+
19+
:::
20+
21+
## Scalability considerations
22+
23+
On the one hand, contract co-location presents a valuable opportunity for developers wanting to ensure the lowest possible transaction processing times for their users.
24+
25+
On the other hand, co-location encourages having as many accounts as possible on one shard, undermining the benefits of horizontal scaling.
26+
27+
This concern, however, is mitigated by basic market mechanics:
28+
29+
* The more accounts exist on the same shard (and the more transactions are submitted by them), the higher the gas price
30+
* The higher the gas price, the higher the cost of each transaction
31+
* The higher the cost of each transaction, the lower the benefits-to-costs ratio of co-locating additional accounts
32+
33+
It is up to the market participants to determine whether co-location is worth incurring high transaction costs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Shards and parallelized execution
2+
3+
## Definition
4+
5+
Shards are smaller chains that are usually responsible for managing a portion of the global state of the main chain. In =nil;, there exist two types of shards.
6+
7+
* Execution shards process transactions of the accounts allocated to these shards
8+
* The consensus shard coordinates execution shards and submits ZKPs of the global state to Ethereum
9+
10+
## Execution shards
11+
12+
All work related to processing transactions, storing accounts, and managing the local state occurs at the execution shard level. Execution shards are also tasked with passing message passing checks.
13+
14+
:::info[Mempools]
15+
16+
Although each shard has its own mempool of transactions, there are no restrictions for the participants on what shard they can cooperate with.
17+
18+
:::
19+
20+
### Message passing checks
21+
22+
To support [**cross-shard communications**](../principles#cross-shard-communication), execution shards must record all necessary outgoing messages posted in other execution shards.
23+
24+
Each message contains information about its destination account. If a shard sees that a message targets one of the accounts in the shard, the shard must include this message in its next block. Such outgoing messages are called necessary messages and new blocks are considered invalid unless they include all necessary messages.
25+
26+
:::info
27+
28+
As the number of execution shards grows, this process may be changed so that shards are only tasked with tracking messages from their neighbors. The closeness of shards can be determined by their Hamming distance.
29+
30+
:::
31+
32+
33+
## Consensus shard
34+
35+
In contrast to execution shards, [**the consensus shard**](../principles#consensus-shard) is responsible for the following functions:
36+
37+
* Managing global consensus
38+
* Producing 'master' ZKPs for verifying global state changes
39+
* Setting the protocol rules and parameters
40+
41+
:::note[Security guarantees]
42+
43+
Although =nil; relies on ZKPs to verify state transitions statelessly, ZKPs can be costly to generate. As a result, a standard security protocol is used to provide security guarantees while ZKPs are generated.
44+
45+
The committee of an execution shard runs a [**Multi-Threshold BFT security protocol**](https://dl.acm.org/doi/10.1145/3460120.3484554) which is a varioation of Sync HotStuff. This is done so that the safety threshold at the local level is not tied to the safety threshold of the cluster.
46+
47+
After running the local consensus protocol, leaders of all committees transmit block digests and quorum certificates to the leader of the consensus shard. The consensus shard leader then proposes a new block to the consensus shard committee, which includes the entire set of validators. These validators run a HotStuff-2 consensus protocol to achieve global consensus.
48+
49+
:::
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Transaction lifecycle
2+
3+
## Definition
4+
5+
In =nil;, a transaction passes the following stages before reaching finality.
6+
7+
1. A transaction is submitted by an account
8+
2. Execution shards survey other execution shards to determine the shard where the transaction should be included in a block
9+
3. The transaction goes to the mempool of an execution shard
10+
4. The transaction is picked up by a collator that bundles it with other transactions and sends the resulting batch for execution
11+
5. The transaction is executed and is sent into a block
12+
6. The block passes local consensus while the shard generates a ZKP
13+
7. The block with the transaction is sent into storage and the transaction reaches soft finality
14+
8. The ZKP and the block are sent to the consensus shard that produces a 'master' ZKP
15+
16+
Additional remarks about each of the above stages are given below.
17+
18+
## Stages
19+
20+
### Transaction submission and processing
21+
22+
Execution shards poll other execution shards about outgoing messages. After a new transaction is submitted, its destination shard retrieves it from its shard of origin and places it in its mempool for subsequent execution.
23+
24+
To learn more about cross-shard communication, [**click here**](./shards-parallel-execution#message-passing-checks).
25+
26+
### Passing the collator
27+
28+
The collator then retrieves the transaction from the mempool and bundles it together with other transactions. The resulting bundle is executed, and the transaction is included in the new block produced by the execution shard.
29+
30+
At the end of this stage, the block with the transaction is sent for verification via local consensus. [**Click here**](./shards-parallel-execution#consensus-shard) to learn more about local consensus.
31+
32+
### Achieving soft finality
33+
34+
After the block containing the transaction is built, execution shards produce a ZKP and send it to the consensus shard along with block hashes. In the meantime, the block with the transaction reaches storage, and the transaction achieves soft finality.
35+
36+
:::info
37+
38+
When =nil; supports communications with L1, a special application running on top of the consensus shard will submit [**data availability transactions**](../specification/data-availability) to Ethereum.
39+
40+
In this case, transactions will reach soft finality when the corresponding data availability transactions are verified in Ethereum slots.
41+
42+
:::
43+
44+
:::note[ZKPs]
45+
46+
ZKPs allow for trustless verification of state transitions inside execution shards and the consensus shard. ZKP generation is handled by dedicated participants (proof producers). To learn more about this process, [**click here**](../specification/finality).
47+
48+
:::
49+
50+
### Achieving hard finality
51+
52+
The consensus shard also verifies the proof from the shard with the transaction and creates a 'master' ZKP.
53+
54+
When this feature is supported, the 'master' ZKP will be sent to the =nil; smart contract on Ethereum where it will be verified. At this stage, the transaction will achieve absolute finality.

nil/intro.mdx

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import Thesis from '@site/static/img/nil/nil-icons/thesis.png'
2+
import Principles from '@site/static/img/nil/nil-icons/principles.png'
3+
import {Card, CardSection} from '@site/src/components/CardSection'
4+
import Accounts from '@site/static/img/nil/nil-icons/accounts.png'
5+
import Transaction from '@site/static/img/nil/nil-icons/transaction.png'
6+
import Shards from '@site/static/img/nil/nil-icons/shards.png'
7+
import Finality from '@site/static/img/nil/nil-icons/finality.png'
8+
import Data from '@site/static/img/nil/nil-icons/data.png'
9+
import Contract from '@site/static/img/nil/nil-icons/contract.png'
10+
import Sequencing from '@site/static/img/nil/nil-icons/sequencing.png'
11+
12+
# Overview
13+
14+
## Definition
15+
16+
=nil; is an Ethereum layer-2 blockchain powered by zkSharding. The design of =nil; embodies three core qualities:
17+
18+
* **Horizontal scalability**. =nil; unlocks the power of many machines by partitioning state across shards with cross-shard communications being a built-in feature of the protocol.
19+
* **Modularity**. =nil; acts as an execution layer while using Ethereum for data availability and consensus.
20+
* **Verifiable security**. The entire =nil; network can be verified with a single zero-knowledge proof attesting to the correctness of all shards.
21+
22+
The design of =nil; transcends the typical monolithic vs. modular discourse as it emphasizes horizontal scalability above all else. =nil; scales out beyond the constraints of a single machine's processing power, by leveraging zkSharding, a new type of sharding architecture. In zkSharding, execution shards produce zero-knowledge proofs (ZKPs) verifying intra-shard state transitions while the state of the cluster is managed by a designated consensus shard. The consensus shard is responsible for synchronizing execution shards and producing a 'master' ZKP that is sent to Ethereum for global state verification.
23+
24+
=nil; offers an effective strategy for scaling Ethereum while avoiding the limitations typically associated with the modular approach such as state and liquidity fragmentation.
25+
26+
## Structure of the documentation
27+
28+
### Introduction
29+
30+
Learn the basics of what =nil; is and how it works.
31+
32+
<CardSection>
33+
<Card icon={<img src={Thesis}/>} id='thesis' title='Thesis' description='Read about the "how" and "why" of =nil;' to='./thesis'/>
34+
<Card icon={<img src={Principles}/>} id='principles' title='Principles' description='Grasp the fundamentals of the architecture of =nil;' to='./principles'/>
35+
</CardSection>
36+
37+
### Core concepts
38+
39+
Familiarize yourself with the key components of the architecture of =nil;.
40+
41+
<CardSection>
42+
<Card icon={<img src={Accounts}/>} id='accounts' title='Accounts' description='Learn about how =nil; handles accounts' to='./core-concepts/accounts'/>
43+
<Card icon={<img src={Transaction}/>} id='lifecycle' title='Transaction lifecycle' description='Follow a transaction to finality' to='./core-concepts/transaction-lifecycle'/>
44+
<Card icon={<img src={Shards}/>} id='shards' title='Shards and parallelized execution' description='See how =nil; achieves scalability' to='./core-concepts/shards-parallel-execution'/>
45+
<Card icon={<img src={Contract}/>} id='contract' title='Contract co-location' description='Ensure account placement on the same shard' to='./core-concepts/contract-co-location'/>
46+
</CardSection>
47+
48+
### Specification
49+
50+
Learn more about how =nil; plans to resolve issues central to any blockchain.
51+
52+
:::info[WIP provisions]
53+
54+
The materials in this section may describe features and components that are not yet part of =nil;.
55+
56+
:::
57+
58+
<CardSection>
59+
<Card icon={<img src={Sequencing}/>} id='sequencing' title='Sequencing' description='Read about how =nil; adopts the PBS model' to='./specification/sequencing'/>
60+
<Card icon={<img src={Finality}/>} id='finality' title='Finality' description='Learn about the strong security guarantees of =nil;' to='./specification/finality'/>
61+
<Card icon={<img src={Data}/>} id='data' title='Data availability' description='See how =nil; achieves DA at all levels' to='./specification/data-availability'/>
62+
</CardSection>

nil/principles.mdx

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import Flows from '@site/static/img/nil/flows.png'
2+
3+
# Principles
4+
5+
This page offers a high-level explanation of the architecture of =nil;.
6+
7+
## Flows
8+
9+
The following diagram shows how =nil; organizes execution shards, the main shard, the transfer of ZKPs, and communications with Ethereum.
10+
11+
<img src={Flows}/ >
12+
13+
Each execution shard is responsible for generating a ZKP for their respective state change. While ZKPs are generated, execution shards employ a protocol based on [**Sync HotStuff**](https://eprint.iacr.org/2019/270.pdf) to reach consensus. Afterward, the proofs are verified via a [**HotStuff2-based**](https://eprint.iacr.org/2023/397.pdf) global consensus protocol.
14+
15+
The main shard uses all received ZKPs to create a 'master' ZKP that is then transmitted to Ethereum. The global state of =nil; is verified and transactions reach finality.
16+
17+
## Consensus shard
18+
19+
The consensus shard performs two essential functions:
20+
21+
* The shard stores and sets consensus rules and parameters
22+
* The shard stores hashes of the most recent blocks from execution shards and ensures synchronization between execution shards
23+
24+
:::info
25+
26+
There is only one consensus shard in the cluster.
27+
28+
:::
29+
30+
## Execution shards
31+
32+
As implied by their name, execution shards process transactions.
33+
34+
Each shard is allocated with a subset of accounts from the global state. The shard is responsible for executing transactions made to and from these accounts. Consensus is handled by a committee of randomly selected validators.
35+
36+
To learn more about execution shards, [**click here**](./core-concepts/shards-parallel-execution#execution-shards).
37+
38+
:::info[Validator rotation]
39+
40+
At the end of each epoch, a new set of validators is generated for each execution shard based on the Verifiable Secret Sharing (VSS) scheme.
41+
42+
:::
43+
44+
## Cross-shard communication
45+
46+
Instead of handling cross-shard communication via bridges (which are often insecure and unstable), =nil; integrates such communications in its protocol.
47+
48+
Each execution shard is tasked with surveying other execution shards and retrieving necessary transactions. A transaction is necessary for a shard if the shard holds the account that the transaction calls. Blocks within a shard are considered invalid unless they include all necessary messages.
49+
50+
To learn more about cross-shard communication, [**click here**](./core-concepts/shards-parallel-execution#message-passing-checks).
51+
52+
## Contract co-location
53+
54+
=nil; also offers participants the option of contract co-location, which is a request for two accounts to be placed in the same shard.
55+
56+
Co-location ensures that transaction execution speeds remain high. To learn more about contract co-location and its benefits, [**click here**](./core-concepts/contract-co-location).

0 commit comments

Comments
 (0)