Skip to content

Commit c5819e6

Browse files
author
jarrodwatts
committed
architecture and transaction lifecycle
1 parent ae55b36 commit c5819e6

12 files changed

+97
-2
lines changed

docs/cdk/concepts/architecture.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Architecture
2+
3+
While each chain built with the CDK is unique, they all share a common high-level architecture. Before diving into the specifics of how [transactions](./transaction-lifecycle.md) are processed, it’s helpful to first understand the role of each component in the system.
4+
5+
![CDK Architecture](../../img/cdk/architecture-overview.png)
6+
7+
## Users
8+
9+
Chains built with the CDK are EVM-compatible by default. While the [type of zkEVM](https://docs.polygon.technology/cdk/architecture/type-1-prover/intro-t1-prover/#type-definitions) you choose to implement is customizable, CDK chains are designed to be compatible with existing Ethereum tools and libraries.
10+
11+
This means both users and developers can use the same wallets (such as MetaMask) and libraries (such as Ethers.js) that they use to interact with Ethereum to interact with chains built with the CDK.
12+
13+
The process to submit transactions is the same as Ethereum, using the same [JSON-RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/) interface. Transactions are submitted directly to the L2 and go into a pending transaction pool.
14+
15+
## Sequencer
16+
17+
The sequencer is responsible for two vital tasks in the system:
18+
19+
1. Executing transactions submitted by users on the L2.
20+
2. Sending batches of transactions to the L1 smart contract.
21+
22+
The sequencer reads transactions from the pending transaction pool and executes them on the L2, effectively updating the state of the L2 and providing this information back to the user. Once this process is complete _(typically in a matter of seconds)_, users are free to continue interacting with the L2 as if the transaction was finalized.
23+
24+
In the background, the sequencer also periodically creates batches of transactions together and sends multiple batches of transactions to the L1 smart contract in a single transaction.
25+
26+
## L1 Smart Contracts
27+
28+
Deployed on the L1 (Ethereum), multiple smart contracts work together to finalize transactions received from the L2 on the L1. Typically there is a main “rollup” smart contract that is responsible for:
29+
30+
1. Receiving and storing batches of transactions from the L2 (depending on the design of the L2, it may not use Ethereum for [data availability](https://docs.polygon.technology/cdk/glossary/#data-availability)).
31+
32+
2. Receiving and verifying ZK-proofs from the aggregator.
33+
34+
## Aggregator & Prover
35+
36+
The aggregator is responsible for periodically reading batches of transactions from the L2 that have not been verified yet, and generating ZK-proofs for them to prove their validity.
37+
38+
To do this, the aggregator sends the batches of transactions to a **prover**. The prover generates ZK proofs and sends them back to the aggregator, which then posts the proofs back to the L1 smart contract.

docs/cdk/concepts/blocks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ By inspecting the transactions in the batch, we can see:
3939

4040
![Transaction found inside batch](../../img/cdk/transaction-in-batch.png)
4141

42-
If the L2 is a [rollup](./layer2s.md), it sends an array of batches to Ethereum, by providing the array as an argument to the `sequenceBatches` function of a smart contract on Ethereum.
42+
If the L2 is a [rollup](./layer2s.md) (meaning it uses Ethereum for it’s [data availability](https://docs.polygon.technology/cdk/glossary/#data-availability)), it sends an array of batches to Ethereum, by providing the array as an argument to the `sequenceBatches` function of a smart contract on Ethereum.
4343

4444
![Sequence Transaction](../../img/cdk/sequence-transaction.png)
4545

46-
By inspecting the `Sequence Tx Hash` transaction, we can see the `sequenceBatches` function is called with the array of batches as an argument. One of these batches is the batch we have been following, `2041736`, which contains our original example transaction.
46+
By inspecting the `Sequence Tx Hash` transaction, we can see the `sequenceBatches` function is called with the array of batches as an argument. One of these batches is the batch we have been following, `2041736`, which contains our original example transaction:
4747

4848
![Last Batch Sequenced](../../img/cdk/last-batch-sequenced.png)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Transaction Finality
2+
3+
Through the [transaction lifecycle](./transaction-lifecycle.md), transactions progress through three states of finality:
4+
5+
1. **Trusted**: The transaction has been **submitted** and **executed** on the L2. The user receives the result of the transaction and can continue to interact with the L2 chain.
6+
7+
2. **Virtual**: The transaction has been **batched** and **sequenced**, meaning the batch containing the transaction has been sent to Ethereum. However, the ZK-proof to verify the validity of the transaction has not yet been posted and verified on Ethereum.
8+
9+
3. **Consolidated**: A ZK-proof has been generated, posted, and verified on Ethereum. The transaction is now considered final at the L1 level. This means the user is free to withdraw their funds from the L2 chain back to Ethereum.
10+
11+
![Transaction Finality](../../img/cdk/transaction-finality.png)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Transaction Lifecycle
2+
3+
Chains built using the CDK go through a series of steps to eventually reach [finality](./transaction-finality.md) on Ethereum. Transactions submitted by users to an L2 built with the CDK go through the following lifecycle:
4+
5+
1. **Submitted**: The transaction is submitted to the L2.
6+
2. **Executed**: The transaction is executed on the L2 by the sequencer.
7+
3. **Batched**: The transaction is included in a batch of transactions.
8+
4. **Sequenced**: The batch containing the transaction is sent to Ethereum.
9+
5. **Aggregated**: A ZK-proof is generated, posted, and verified on Ethereum to prove the transaction is valid.
10+
11+
## Submitted
12+
13+
Just like Ethereum, users submit transactions to a “pool” of pending transactions on the L2. The transaction is submitted using the same interface as Ethereum, via [JSON-RPC](https://ethereum.org/en/developers/docs/apis/json-rpc/) which is implemented by tools such as MetaMask and developer libraries.
14+
15+
![User submitting transactions to L2](../../img/cdk/user-to-pending-pool.png)
16+
17+
## Executed
18+
19+
The [sequencer](./architecture.md#sequencer) reads transactions from the pending transaction pool and executes them on the L2. Once executed, transactions are added to [blocks](./blocks.md#block), then the blocks fill [batches](./blocks.md#batch), and the sequencer’s local L2 state is updated.
20+
21+
Once the state is updated, it is also broadcast to all other zkEVM nodes which provide the transaction information back to the user or application that submitted the transaction.
22+
23+
At this point, the transaction appears complete to users, as they are provided with the result of whether the transaction was executed or reverted. Users can continue to interact with the chain with the updated state.
24+
25+
![Transaction executed on L2](../../img/cdk/execution.png)
26+
27+
## Batched
28+
29+
As a background process, the [sequencer](./architecture.md#sequencer) is constantly creating [batches](./blocks.md#batch) of transactions. These batches contain multiple transactions from multiple [blocks](./blocks.md#block) on the L2.
30+
31+
One field in the batch data structure is `transactions`, which contains a [`bytes`](https://docs.soliditylang.org/en/latest/types.html#bytes-and-string-as-arrays) representation of the transactions in the batch. This is generated by serializing each transaction in the batch using [RLP serialization](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/) and then concatenating them together.
32+
33+
![Batch of transactions](../../img/cdk/batch-generation.png)
34+
35+
## Sequenced
36+
37+
Depending on the data availability design choices of the L2, if the L2 is a [rollup](./rollup-vs-validium.md#rollups), the sequencer sends arrays of batches to the [L1 smart contract](./architecture.md#l1-smart-contracts), where they are stored inside the state of the smart contract.
38+
39+
![Sequence Batches](../../img/cdk/sequence-batches.png)
40+
41+
## Aggregated
42+
43+
The final step of the transaction lifecycle is to generate a ZK-proof that proves the batch of transactions is valid. Batches of transactions are read by the [aggregator](./architecture.md#aggregator) which utilizes a [prover](./architecture.md#prover) to generate a ZK-proof that is posted back to Ethereum.
44+
45+
![Aggregator posting ZK-proof](../../img/cdk/aggregate-batches.png)

docs/img/cdk/aggregate-batches.png

75.4 KB
Loading
168 KB
Loading

docs/img/cdk/batch-generation.png

40.9 KB
Loading

docs/img/cdk/execution.png

71.9 KB
Loading

docs/img/cdk/sequence-batches.png

71.7 KB
Loading
27.8 KB
Loading

0 commit comments

Comments
 (0)