... | @@ -7,8 +7,12 @@ |
... | @@ -7,8 +7,12 @@ |
|
```rust
|
|
```rust
|
|
pub struct CoreCircuitConfig<F: Field, const NUM_STATE_HI_COL: usize, const NUM_STATE_LO_COL: usize>
|
|
pub struct CoreCircuitConfig<F: Field, const NUM_STATE_HI_COL: usize, const NUM_STATE_LO_COL: usize>
|
|
{
|
|
{
|
|
|
|
/// block index, the index of the block in the chunk, repeated for rows in one block
|
|
|
|
pub block_idx: Column<Advice>,
|
|
/// Transaction index, the index inside the block, repeated for rows in one transaction
|
|
/// Transaction index, the index inside the block, repeated for rows in one transaction
|
|
pub tx_idx: Column<Advice>,
|
|
pub tx_idx: Column<Advice>,
|
|
|
|
/// whether the current transaction is a transaction to create a contract
|
|
|
|
pub tx_is_create: Column<Advice>,
|
|
/// Call id, unique for each call, repeated for rows in one execution state
|
|
/// Call id, unique for each call, repeated for rows in one execution state
|
|
pub call_id: Column<Advice>,
|
|
pub call_id: Column<Advice>,
|
|
/// Contract code address, repeated for rows in one execution state
|
|
/// Contract code address, repeated for rows in one execution state
|
... | @@ -22,8 +26,9 @@ pub struct CoreCircuitConfig<F: Field, const NUM_STATE_HI_COL: usize, const NUM_ |
... | @@ -22,8 +26,9 @@ pub struct CoreCircuitConfig<F: Field, const NUM_STATE_HI_COL: usize, const NUM_ |
|
...
|
|
...
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
- block_idx:表示当前交易所在的区块是chunk的第几个
|
|
- tx_idx: 表示交易是区块的第几笔
|
|
- tx_idx: 表示交易是区块的第几笔
|
|
|
|
- tx_is_create:表示当前交易用于创建合约
|
|
- call_id:在处理执行轨迹的时候,遇到新的call,就给其分配一个唯一的id (不是每次增加1)
|
|
- call_id:在处理执行轨迹的时候,遇到新的call,就给其分配一个唯一的id (不是每次增加1)
|
|
- code_addr:当前运行的合约代码的地址
|
|
- code_addr:当前运行的合约代码的地址
|
|
- pc:当前程序计数器的位置
|
|
- pc:当前程序计数器的位置
|
... | @@ -62,11 +67,8 @@ pub struct CoreCircuitConfig<F: Field, const NUM_STATE_HI_COL: usize, const NUM_ |
... | @@ -62,11 +67,8 @@ pub struct CoreCircuitConfig<F: Field, const NUM_STATE_HI_COL: usize, const NUM_ |
|
pub enum ExecutionState {
|
|
pub enum ExecutionState {
|
|
......
|
|
......
|
|
STOP,
|
|
STOP,
|
|
ADD,
|
|
ADD_SUB_MUL_DIV_MOD,
|
|
MUL,
|
|
|
|
SUB,
|
|
|
|
EXP,
|
|
EXP,
|
|
DIV_MOD,
|
|
|
|
ADDMOD,
|
|
ADDMOD,
|
|
MULMOD,
|
|
MULMOD,
|
|
POP,
|
|
POP,
|
... | @@ -76,19 +78,20 @@ pub enum ExecutionState { |
... | @@ -76,19 +78,20 @@ pub enum ExecutionState { |
|
......
|
|
......
|
|
}
|
|
}
|
|
```
|
|
```
|
|
我们可以注意到,这两个名称“DIV_MOD”,“AND_OR_XOR”由下划线分隔了,意味着他们可以处理多个功能、逻辑相近的指令(DIV和MOD,AND、OR和XOR)。以逻辑运算指令AND、OR和XOR为例,尽管它们运算不同,但是操作模式相似。因此为了减少重复代码,可以使用一个执行状态处理这三种指令。
|
|
我们可以注意到,这两个名称“ADD_SUB_MUL_DIV_MOD”,“AND_OR_XOR”由下划线分隔了,意味着他们可以处理多个功能、逻辑相近的指令(ADD、SUB、DIV和MOD,AND、OR和XOR)。以逻辑运算指令AND、OR和XOR为例,尽管它们运算不同,但是操作模式相似。因此为了减少重复代码,可以使用一个执行状态处理这三种指令。
|
|
|
|
|
|
#### 3.1.2 zkEVM电路内部的状态
|
|
#### 3.1.2 zkEVM电路内部的状态
|
|
在zkEVM电路中为了处理一些非EVM指令的流程,需要使用一些内部状态。EVM中不存在此概念。包括但不限于:
|
|
在zkEVM电路中为了处理一些非EVM指令的流程,需要使用一些内部状态。EVM中不存在此概念。包括但不限于:
|
|
```rust
|
|
```rust
|
|
pub enum ExecutionState {
|
|
pub enum ExecutionState {
|
|
......
|
|
......
|
|
END_PADDING, // it has to be the first state as it is the padding state
|
|
|
|
BEGIN_TX_1, // start a tx, part one
|
|
BEGIN_TX_1, // start a tx, part one
|
|
BEGIN_TX_2, // start a tx, part two
|
|
BEGIN_TX_2, // start a tx, part two
|
|
END_BLOCK,
|
|
BEGIN_TX_3, // start a tx, part three
|
|
END_TX,
|
|
|
|
BEGIN_BLOCK,
|
|
BEGIN_BLOCK,
|
|
|
|
BEGIN_CHUNK,
|
|
|
|
END_BLOCK,
|
|
|
|
END_CHUNK,
|
|
......
|
|
......
|
|
}
|
|
}
|
|
```
|
|
```
|
... | | ... | |