You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/cdk/architecture/type-1-prover/intro-t1-prover.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,4 +27,4 @@ The figure below gives a visual summary of the types, contrasting compatibility
27
27
28
28
Ultimately, choosing which type of ZK-EVM to develop involves a trade-off between EVM-equivalence and performance.
29
29
30
-
The challenge this poses for developers who favor exact Ethereum-equivalence is to devise ingenious designs and clever techniques to implement faster zk-provers. Vitalik mentions one mitigation strategy to improve proof generation times: Cleverly engineered, and massively parallelized provers.
30
+
The challenge this poses for developers who favor exact Ethereum-equivalence is to devise ingenious designs and clever techniques to implement faster zk-provers. Vitalik mentions one mitigation strategy to improve proof generation times: cleverly engineered, and massively parallelized provers.
Copy file name to clipboardExpand all lines: docs/cdk/architecture/type-1-prover/t1-cpu-component.md
+11-16Lines changed: 11 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,16 @@
1
-
The CPU is the central component of Polygon Zero zkEVM. Like any central processing unit, it reads instructions, executes them, and modifies the state (registers and the memory) accordingly.
1
+
The CPU is the central component of the Polygon CDK type-1 prover. Like any central processing unit, it reads instructions, executes them, and modifies the state (registers and the memory) accordingly.
2
2
3
3
Other complex instructions, such as Keccak hashing, are delegated to specialized STARK tables.
4
4
5
5
This section briefly presents the CPU and its columns. However, details on the CPU logic can be found [here](https://github.com/0xPolygonZero/plonky2/blob/main/evm/spec/cpulogic.tex).
6
6
7
-
8
-
### CPU flow
7
+
## CPU flow
9
8
10
9
CPU execution can be decomposed into two distinct phases; CPU cycles, and padding.
11
10
12
11
This first phase of the CPU execution is a lot bulkier than the second, more so that padding comes only at the end of the execution.
13
12
14
-
####CPU cycles
13
+
### CPU cycles
15
14
16
15
In each row, the CPU reads code at a given program counter (PC) address, executes it, and writes outputs to memory. The code could be kernel code or any context-based code.
17
16
@@ -28,23 +27,21 @@ Subsequent contexts are created when executing user code.
28
27
29
28
Syscalls, which are specific instructions written in the kernel, may be executed in a non-zero user context. They don't change the context but the code context, which is where the instructions are read from.
30
29
31
-
####Padding
30
+
### Padding
32
31
33
32
At the end of any execution, the length of the CPU trace is padded to the next power of two.
34
33
35
34
When the program counter reaches the special halting label in the kernel, execution halts. And that's when padding should follow.
36
35
37
36
There are special constraints responsible for ensuring that every row subsequent to execution halting is a padded row, and that execution does not automatically resume. That is, execution cannot resume without further instructions.
38
37
38
+
## CPU columns
39
39
40
-
41
-
### CPU columns
42
-
43
-
This document discusses CPU columns as they relate to all relevant operations being executed, as well as how some of the constraints are checked.
40
+
We now have a look at CPU columns as they relate to all relevant operations being executed, as well as how some of the constraints are checked.
44
41
45
42
These are the register columns, operation flags, memory columns, and general columns.
46
43
47
-
####Registers
44
+
### Registers
48
45
49
46
- $\texttt{context}$: Indicates the current context at any given time. So, $\texttt{context}\ 0$ is for the kernel, while any context specified with a positive integer indicates a user context. A user context is incremented by $1$ at every call.
50
47
- $\texttt{code_context}$: Indicates the context in which the executed code resides.
@@ -55,7 +52,7 @@ These are the register columns, operation flags, memory columns, and general col
55
52
- $\texttt{clock}$: Monotonic counter which starts at 0 and is incremented by 1 at each row. It is used to enforce correct ordering of memory accesses.
56
53
- $\texttt{opcode_bits}$ These are 8 boolean columns, indicating the bit decomposition of the opcode being read at the current PC.
57
54
58
-
####Operation flags
55
+
### Operation flags
59
56
60
57
Operation flags are boolean flags indicating whether an operation is executed or not.
61
58
@@ -85,8 +82,7 @@ $$
85
82
\texttt{eq_iszero * opcode_bits[0]}
86
83
$$
87
84
88
-
89
-
#### Memory columns
85
+
### Memory columns
90
86
91
87
The CPU interacts with the EVM memory via its memory channels.
92
88
@@ -101,7 +97,7 @@ A full memory channel is composed of the following:
101
97
102
98
The last memory channel is a partial channel. It doesn't have its own $\texttt{value}$ columns but shares them with the first full memory channel. This allows saving eight columns.
103
99
104
-
####General columns
100
+
### General columns
105
101
106
102
There are eight ($8$) shared general columns. Depending on the instruction, they are used differently:
107
103
@@ -126,5 +122,4 @@ The `popping-only` instruction uses the $\text{Stack}$ columns to check if the S
126
122
While the `pushing-only` instruction uses the $\text{Stack}$ columns to check if the Stack is empty before the instruction.
127
123
128
124
$\texttt{stack_len_bounds_aux}$ is used to check that the Stack doesn't overflow in user mode. The last four columns are used to prevent conflicts with other general columns.
129
-
See the $\text{Stack Handling}$ subsection of this [document](https://github.com/0xPolygonZero/plonky2/blob/main/evm/spec/cpulogic.tex) for more details.
130
-
125
+
See the $\text{Stack Handling}$ subsection of this [document](https://github.com/0xPolygonZero/plonky2/blob/main/evm/spec/cpulogic.tex) for more details.
Copy file name to clipboardExpand all lines: docs/cdk/architecture/type-1-prover/t1-ctl-protocol.md
+9-13Lines changed: 9 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,11 @@ For each STARK table, ordinary STARK proof and verification are used to check if
4
4
5
5
However, there are input and output values shared among the tables. These values need to be checked for possible alterations while being shared among tables. For this purpose, _cross-table lookups_ (CTLs) are used in verifying that the shared values are not tampered with.
6
6
7
-
###How CTLs work
7
+
## How CTLs work
8
8
9
-
The CLT protocol is based on the [logUP argment](https://eprint.iacr.org/2022/1530.pdf), which works similar to how range-checks work. Range-checks are discussed in a subsequent document to this one.
9
+
The CTL protocol is based on the [logUP argment](https://eprint.iacr.org/2022/1530.pdf), which works similar to how range-checks work. Range-checks are discussed in a subsequent document to this one.
10
10
11
-
####Example (CTL)
11
+
### Example (CTL)
12
12
13
13
Consider the following scenario as an example. Suppose STARK $S_2$ requires an operation -- say $Op$ -- that is carried out by another STARK $S_1$.
14
14
@@ -26,8 +26,7 @@ And thus, this check is tantamount to ensuring that the rows of the $S_1$ table
As outlined in the above example, verifying that shared values among STARK tables are not tampered with amounts to proving that rows of reduced STARK tables are permutations of each other.
33
32
@@ -40,7 +39,7 @@ The proof therefore is achieved in three steps;
40
39
- Checking correct construction and equality of 'running sums'.
41
40
42
41
43
-
####Table filtering
42
+
### Table filtering
44
43
45
44
Define filters $f^1$ and $f^2$ for STARK tables $S_1$ and $S_2$ , respectively, such that
46
45
@@ -65,8 +64,7 @@ Next create subtables $S_1'$ and $S_2'$ of STARK tables $S_1$ and $S_2$ , respec
65
64
66
65
Filters are limited to (at most) degree 2 combinations of columns.
67
66
68
-
69
-
#### Computing running sums
67
+
### Computing running sums
70
68
71
69
For each $i \in \{0,1\}$, let $\{ c^{i,j} \}$ denote the columns of $S_i'$.
72
70
@@ -86,7 +84,7 @@ for $0 < l < n-1$.
86
84
87
85
Note that $Z_l^{S_i}$ is computed backwards. i.e., It starts with $Z_{n-1}^{S_i}$ and goes down to $Z_0^{S_i}$ as the final sum.
88
86
89
-
####Checking running sums
87
+
### Checking running sums
90
88
91
89
After computing running sums, check equality of the final sums $Z_0^{S_1} =?\ Z_0^{S_2}$ and whether the running sums were correctly constructed.
92
90
@@ -97,8 +95,7 @@ The above three steps turn the CTL argument into a [LogUp lookup argument](https
97
95
98
96
which checks for equality between $S_1'$ and $S_2'$.
99
97
100
-
101
-
### CTL protocol summary
98
+
## CTL protocol summary
102
99
103
100
The cross-table protocol can be summarized as follows.
104
101
@@ -113,5 +110,4 @@ On the other side, and for the same STARK table $S$, the verifier:
113
110
114
111
- Computes the sum $Z = \sum_j Z_{j}^l$.
115
112
- Checks equality, $Z =?\ Z_0^S$.
116
-
- Checks whether each of the running sums $Z_{j}^l$ and $Z^S$ were correctly constructed.
117
-
113
+
- Checks whether each of the running sums $Z_{j}^l$ and $Z^S$ were correctly constructed.
Copy file name to clipboardExpand all lines: docs/cdk/architecture/type-1-prover/t1-design-challenge.md
+20-12Lines changed: 20 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,27 +2,35 @@ The EVM wasn't designed with zero-knowledge proving and verification in mind, an
2
2
3
3
Some of the challenges stem from the way the EVM is implemented. Here are some of the discrepancies that occur when deploying the most common zero-knowledge primitives to the EVM.
4
4
5
-
1.**Word size**: The native EVM word size is 256 bits long, whereas the chosen SNARK Plonky2, operates internally over 64-bit field elements.
5
+
## Word size
6
6
7
-
Matching these word sizes requires a work-around where word operations are performed in multiples of smaller limbs for proper handling internally.
7
+
The native EVM word size is 256 bits long, whereas the chosen SNARK Plonky2, operates internally over 64-bit field elements.
8
8
9
-
This unfortunately incurs overheads, even for simple operations like the ADD opcode.
9
+
Matching these word sizes requires a work-around where word operations are performed in multiples of smaller limbs for proper handling internally.
10
+
11
+
This unfortunately incurs overheads, even for simple operations like the ADD opcode.
10
12
11
-
2.**Supported fields:** Selecting a field for the most efficient proving scheme can become complicated.
13
+
## Supported fields
14
+
15
+
Selecting a field for the most efficient proving scheme can become complicated.
12
16
13
-
Ethereum transactions are signed over the [secp256k1 curve](https://secg.org/sec2-v2.pdf), which involves a specific prime field $\mathbb{F}_p$, where $p = 2^{256} - 2^{32} - 2^9 - 2^8 -2^7 - 2^6 - 2^4 - 1$. The EVM also supports precompiles for [BN254 curve](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-197.md) operations, where the computations are carried out in an entirely different field arithmetic.
17
+
Ethereum transactions are signed over the [secp256k1 curve](https://secg.org/sec2-v2.pdf), which involves a specific prime field $\mathbb{F}_p$, where $p = 2^{256} - 2^{32} - 2^9 - 2^8 -2^7 - 2^6 - 2^4 - 1$. The EVM also supports precompiles for [BN254 curve](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-197.md) operations, where the computations are carried out in an entirely different field arithmetic.
14
18
15
-
This adds a major overhead when it comes to proving modular arithmetic, as there is a need to deal with modular reductions in the field of the proving system.
19
+
This adds a major overhead when it comes to proving modular arithmetic, as there is a need to deal with modular reductions in the field of the proving system.
16
20
17
-
Such incongruous modular arithmetic is not uncommon. Recursive proving schemes like [Halo](https://electriccoin.co/wp-content/uploads/2019/09/Halo.pdf) resorted to utilising two pairing-friendly elliptic curves where proving and verification are instantiated in two different field arithmetics.
21
+
Such incongruous modular arithmetic is not uncommon. Recursive proving schemes like [Halo](https://electriccoin.co/wp-content/uploads/2019/09/Halo.pdf) resorted to utilising two pairing-friendly elliptic curves where proving and verification are instantiated in two different field arithmetics.
18
22
19
-
Other curves, such as the pairing-friendly [BLS12-381](https://eips.ethereum.org/EIPS/eip-2537) popularly used in recursive proving systems, are yet to be EVM-supported in the form of precompiled contracts.
23
+
Other curves, such as the pairing-friendly [BLS12-381](https://eips.ethereum.org/EIPS/eip-2537) popularly used in recursive proving systems, are yet to be EVM-supported in the form of precompiled contracts.
20
24
21
-
3.**Hash functions**: The EVM uses [Keccak](https://keccak.team/keccak_specs_summary.html) as its native hash function both for state representation and arbitrary hashing requests, through the `Keccak256` opcode.
25
+
## Hash functions
22
26
23
-
While Keccak is fairly efficient on a CPU, since Plonky2 implements polynomials of degree 3, Keccak operations would need to be expressed as constraints of degree 3. This results in an extremely heavy Algebraic Intermediate Representation (AIR) compared to some of the most recent [STARK-friendly](https://eprint.iacr.org/2020/948.pdf) hash functions, tailored specifically for zero-knowledge proving systems.
27
+
The EVM uses [Keccak](https://keccak.team/keccak_specs_summary.html) as its native hash function both for state representation and arbitrary hashing requests, through the `Keccak256` opcode.
24
28
25
-
Although the EVM supports precompiles of hash functions such as SHA2-256, RIPEMD-160, and Blake2f, they are all quite heavy for a ZK proving system.
29
+
While Keccak is fairly efficient on a CPU, since Plonky2 implements polynomials of degree 3, Keccak operations would need to be expressed as constraints of degree 3. This results in an extremely heavy Algebraic Intermediate Representation (AIR) compared to some of the most recent [STARK-friendly](https://eprint.iacr.org/2020/948.pdf) hash functions, tailored specifically for zero-knowledge proving systems.
30
+
31
+
Although the EVM supports precompiles of hash functions such as SHA2-256, RIPEMD-160, and Blake2f, they are all quite heavy for a ZK proving system.
26
32
27
-
4.**State representation**: Ethereum uses Merkle Patricia Tries with RLP encoding. Both of these are not zero-knowledge-friendly primitives, and incur huge overheads on transaction processing within a ZK-EVM context.
33
+
## State representation
34
+
35
+
Ethereum uses Merkle Patricia Tries with RLP encoding. Both of these are not zero-knowledge-friendly primitives, and incur huge overheads on transaction processing within a ZK-EVM context.
Copy file name to clipboardExpand all lines: docs/cdk/architecture/type-1-prover/testing-and-proving-costs.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
-
### Testing Polygon type-1 zkEVM
1
+
### Testing the prover
2
2
3
-
Find a parser and test runner for testing compatible and common Ethereum full node tests against Polygon type-1 zkEVM[here](https://github.com/0xPolygonZero/evm-tests).
3
+
Find a parser and test runner for testing compatible and common Ethereum full node tests against the Polygon CDK type-1 prover[here](https://github.com/0xPolygonZero/evm-tests).
4
4
5
-
Polygon type-1 zkEVM passes all relevant and official [Ethereum tests](https://github.com/ethereum/tests/).
5
+
The prover passes all relevant and official [Ethereum tests](https://github.com/ethereum/tests/).
6
6
7
7
### Proving costs
8
8
9
-
Instead of presenting gas costs, we focus on the cost of proving EVM transactions with Polygon type-1 prover.
9
+
Instead of presenting gas costs, we focus on the cost of proving EVM transactions with the Polygon CDK type-1 prover.
10
10
11
-
Since Polygon type-1 zkEVM is more like a 'CPU' for the EVM, it makes sense to look at proving costs per VM instance used, as opposed to TPS or other benchmarks.
11
+
Since the prover is more like a 'CPU' for the EVM, it makes sense to look at proving costs per VM instance used, as opposed to TPS or other benchmarks.
12
12
13
13
Consider the table below for prices of GCP's specific instances, taken from [here](https://cloud.google.com/compute/all-pricing), and webpage accessed on the 29th January, 2024.
14
14
@@ -19,8 +19,7 @@ Take the example of a t2d-standard-60 GCP instance, where each vCPU has 4GB memo
19
19
- 0.00346 USD / vCPU hour
20
20
- 0.000463 USD / GB hour
21
21
22
-
We obtain the following hourly cost, $(60 \times 0.00346) + (240 \times 0.000463) = 0.31872$ USD per hour.
23
-
The total cost per block is given by: $\texttt{(Proving time per hr)} \times 0.31872$ USD.
22
+
We obtain the following hourly cost, $(60 \times 0.00346) + (240 \times 0.000463) = 0.31872$ USD per hour. The total cost per block is given by: $\texttt{(Proving time per hr)} \times 0.31872$ USD.
24
23
25
24
The table below displays proving costs per transaction per hour.
0 commit comments