1. 引言
enum RomError {
ROM_ERROR_UNSPECIFIED = 0;
// ROM_ERROR_NO_ERROR indicates the execution ended successfully
ROM_ERROR_NO_ERROR = 1;
// ROM_ERROR_OUT_OF_GAS indicates there is not enough balance to continue the execution
ROM_ERROR_OUT_OF_GAS = 2;
// ROM_ERROR_STACK_OVERFLOW indicates a stack overflow has happened
ROM_ERROR_STACK_OVERFLOW = 3;
// ROM_ERROR_STACK_UNDERFLOW indicates a stack overflow has happened
ROM_ERROR_STACK_UNDERFLOW = 4;
// ROM_ERROR_MAX_CODE_SIZE_EXCEEDED indicates the code size is beyond the maximum
ROM_ERROR_MAX_CODE_SIZE_EXCEEDED = 5;
// ROM_ERROR_CONTRACT_ADDRESS_COLLISION there is a collision regarding contract addresses
ROM_ERROR_CONTRACT_ADDRESS_COLLISION = 6;
// ROM_ERROR_EXECUTION_REVERTED indicates the execution has been reverted
ROM_ERROR_EXECUTION_REVERTED = 7;
// ROM_ERROR_OUT_OF_COUNTERS_STEP indicates there is not enough step counters to continue the execution
ROM_ERROR_OUT_OF_COUNTERS_STEP = 8;
// ROM_ERROR_OUT_OF_COUNTERS_KECCAK indicates there is not enough keccak counters to continue the execution
ROM_ERROR_OUT_OF_COUNTERS_KECCAK = 9;
// ROM_ERROR_OUT_OF_COUNTERS_BINARY indicates there is not enough binary counters to continue the execution
ROM_ERROR_OUT_OF_COUNTERS_BINARY = 10;
// ROM_ERROR_OUT_OF_COUNTERS_MEM indicates there is not enough memory aligncounters to continue the execution
ROM_ERROR_OUT_OF_COUNTERS_MEM = 11;
// ROM_ERROR_OUT_OF_COUNTERS_ARITH indicates there is not enough arith counters to continue the execution
ROM_ERROR_OUT_OF_COUNTERS_ARITH = 12;
// ROM_ERROR_OUT_OF_COUNTERS_PADDING indicates there is not enough padding counters to continue the execution
ROM_ERROR_OUT_OF_COUNTERS_PADDING = 13;
// ROM_ERROR_OUT_OF_COUNTERS_POSEIDON indicates there is not enough poseidon counters to continue the execution
ROM_ERROR_OUT_OF_COUNTERS_POSEIDON = 14;
// ROM_ERROR_INVALID_JUMP indicates there is an invalid jump opcode
ROM_ERROR_INVALID_JUMP = 15;
// ROM_ERROR_INVALID_OPCODE indicates there is an invalid opcode
ROM_ERROR_INVALID_OPCODE = 16;
// ROM_ERROR_INVALID_STATIC indicates there is an invalid static call
ROM_ERROR_INVALID_STATIC = 17;
// ROM_ERROR_INVALID_BYTECODE_STARTS_EF indicates there is a bytecode starting with 0xEF
ROM_ERROR_INVALID_BYTECODE_STARTS_EF = 18;
// ROM_ERROR_INTRINSIC_INVALID_SIGNATURE indicates the transaction is failing at the signature intrinsic check
ROM_ERROR_INTRINSIC_INVALID_SIGNATURE = 19;
// ROM_ERROR_INTRINSIC_INVALID_CHAIN_ID indicates the transaction is failing at the chain id intrinsic check
ROM_ERROR_INTRINSIC_INVALID_CHAIN_ID = 20;
// ROM_ERROR_INTRINSIC_INVALID_NONCE indicates the transaction is failing at the nonce intrinsic check
ROM_ERROR_INTRINSIC_INVALID_NONCE = 21;
// ROM_ERROR_INTRINSIC_INVALID_GAS indicates the transaction is failing at the gas limit intrinsic check
ROM_ERROR_INTRINSIC_INVALID_GAS_LIMIT = 22;
// ROM_ERROR_INTRINSIC_INVALID_BALANCE indicates the transaction is failing at balance intrinsic check
ROM_ERROR_INTRINSIC_INVALID_BALANCE = 23;
// ROM_ERROR_INTRINSIC_INVALID_BATCH_GAS_LIMIT indicates the batch is exceeding the batch gas limit
ROM_ERROR_INTRINSIC_INVALID_BATCH_GAS_LIMIT = 24;
// ROM_ERROR_INTRINSIC_INVALID_SENDER_CODE indicates the transaction sender is invalid
ROM_ERROR_INTRINSIC_INVALID_SENDER_CODE = 25;
// ROM_ERROR_INTRINSIC_TX_GAS_OVERFLOW indicates the transaction gasLimit*gasPrice > MAX_UINT_256 - 1
ROM_ERROR_INTRINSIC_TX_GAS_OVERFLOW = 26;
// ROM_ERROR_BATCH_DATA_TOO_BIG indicates the batch_l2_data is too big to be processed
ROM_ERROR_BATCH_DATA_TOO_BIG = 27;
// ROM_ERROR_UNSUPPORTED_FORK_ID indicates that the fork id is not supported
ROM_ERROR_UNSUPPORTED_FORK_ID = 28;
}
enum ExecutorError {
EXECUTOR_ERROR_UNSPECIFIED = 0;
// EXECUTOR_ERROR_NO_ERROR indicates there was no error
EXECUTOR_ERROR_NO_ERROR = 1;
// EXECUTOR_ERROR_COUNTERS_OVERFLOW_KECCAK indicates that the keccak counter exceeded the maximum
EXECUTOR_ERROR_COUNTERS_OVERFLOW_KECCAK = 2;
// EXECUTOR_ERROR_COUNTERS_OVERFLOW_BINARY indicates that the binary counter exceeded the maximum
EXECUTOR_ERROR_COUNTERS_OVERFLOW_BINARY = 3;
// EXECUTOR_ERROR_COUNTERS_OVERFLOW_MEM indicates that the memory align counter exceeded the maximum
EXECUTOR_ERROR_COUNTERS_OVERFLOW_MEM = 4;
// EXECUTOR_ERROR_COUNTERS_OVERFLOW_ARITH indicates that the arith counter exceeded the maximum
EXECUTOR_ERROR_COUNTERS_OVERFLOW_ARITH = 5;
// EXECUTOR_ERROR_COUNTERS_OVERFLOW_PADDING indicates that the padding counter exceeded the maximum
EXECUTOR_ERROR_COUNTERS_OVERFLOW_PADDING = 6;
// EXECUTOR_ERROR_COUNTERS_OVERFLOW_POSEIDON indicates that the poseidon counter exceeded the maximum
EXECUTOR_ERROR_COUNTERS_OVERFLOW_POSEIDON = 7;
// EXECUTOR_ERROR_UNSUPPORTED_FORK_ID indicates that the fork id is not supported
EXECUTOR_ERROR_UNSUPPORTED_FORK_ID = 8;
// EXECUTOR_ERROR_BALANCE_MISMATCH indicates that there is a balance mismatch error in the ROM
EXECUTOR_ERROR_BALANCE_MISMATCH = 9;
// EXECUTOR_ERROR_FEA2SCALAR indicates that there is a fea2scalar error in the execution
EXECUTOR_ERROR_FEA2SCALAR = 10;
// EXECUTOR_ERROR_TOS32 indicates that there is a TOS32 error in the execution
EXECUTOR_ERROR_TOS32 = 11;
}
- state_db中,l2block表中每条记录对应transaction表中一笔交易。即每个L2Block中仅包含1笔L2交易。
- 代码中的GER简称对应:GlobalExitRoot
ProcessBatchResponse
为调用executor.ProcessBatch()
所返回的对某batch的处理结果。ProcessTransactionResponse
为Executor返回的对batch内每笔交易的执行结果。
// 为Executor对batch的处理结果
type ProcessBatchResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
NewStateRoot []byte `protobuf:"bytes,1,opt,name=new_state_root,json=newStateRoot,proto3" json:"new_state_root,omitempty"`
NewAccInputHash []byte `protobuf:"bytes,2,opt,name=new_acc_input_hash,json=newAccInputHash,proto3" json:"new_acc_input_hash,omitempty"`
NewLocalExitRoot []byte `protobuf:"bytes,3,opt,name=new_local_exit_root,json=newLocalExitRoot,proto3" json:"new_local_exit_root,omitempty"`
NewBatchNum uint64 `protobuf:"varint,4,opt,name=new_batch_num,json=newBatchNum,proto3" json:"new_batch_num,omitempty"`
CntKeccakHashes uint32 `protobuf:"varint,5,opt,name=cnt_keccak_hashes,json=cntKeccakHashes,proto3" json:"cnt_keccak_hashes,omitempty"`
CntPoseidonHashes uint32 `protobuf:"varint,6,opt,name=cnt_poseidon_hashes,json=cntPoseidonHashes,proto3" json:"cnt_poseidon_hashes,omitempty"`
CntPoseidonPaddings uint32 `protobuf:"varint,7,opt,name=cnt_poseidon_paddings,json=cntPoseidonPaddings,proto3" json:"cnt_poseidon_paddings,omitempty"`
CntMemAligns uint32 `protobuf:"varint,8,opt,name=cnt_mem_aligns,json=cntMemAligns,proto3" json:"cnt_mem_aligns,omitempty"`
CntArithmetics uint32 `protobuf:"varint,9,opt,name=cnt_arithmetics,json=cntArithmetics,proto3" json:"cnt_arithmetics,omitempty"`
CntBinaries uint32 `protobuf:"varint,10,opt,name=cnt_binaries,json=cntBinaries,proto3" json:"cnt_binaries,omitempty"`
CntSteps uint32 `protobuf:"varint,11,opt,name=cnt_steps,json=cntSteps,proto3" json:"cnt_steps,omitempty"`
CumulativeGasUsed uint64 `protobuf:"varint,12,opt,name=cumulative_gas_used,json=cumulativeGasUsed,proto3" json:"cumulative_gas_used,omitempty"`
Responses []*ProcessTransactionResponse `protobuf:"bytes,13,rep,name=responses,proto3" json:"responses,omitempty"`
Error ExecutorError `protobuf:"varint,14,opt,name=error,proto3,enum=executor.v1.ExecutorError" json:"error,omitempty"`
ReadWriteAddresses map[string]*InfoReadWrite `protobuf:"bytes,15,rep,name=read_write_addresses,json=readWriteAddresses,proto3" json:"read_write_addresses,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
}
// ProcessBatchResponse represents the response of a batch process.
type ProcessBatchResponse struct {
NewStateRoot common.Hash
NewAccInputHash common.Hash
NewLocalExitRoot common.Hash
NewBatchNumber uint64
UsedZkCounters ZKCounters
Responses []*ProcessTransactionResponse //对batch内每笔交易的执行结果
ExecutorError error
IsBatchProcessed bool
ReadWriteAddresses map[common.Address]*InfoReadWrite
}
// 为Executor对batch内每笔交易的执行结果
type ProcessTransactionResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// Hash of the transaction
TxHash []byte `protobuf:"bytes,1,opt,name=tx_hash,json=txHash,proto3" json:"tx_hash,omitempty"`
// RLP encoded transaction
// [nonce, gasPrice, gasLimit, to, value, data, v, r, s]
RlpTx []byte `protobuf:"bytes,2,opt,name=rlp_tx,json=rlpTx,proto3" json:"rlp_tx,omitempty"`
// Type indicates legacy transaction
// It will be always 0 (legacy) in the executor
Type uint32 `protobuf:"varint,3,opt,name=type,proto3" json:"type,omitempty"`
// Returned data from the runtime (function result or data supplied with revert opcode)
ReturnValue []byte `protobuf:"bytes,4,opt,name=return_value,json=returnValue,proto3" json:"return_value,omitempty"`
// Total gas left as result of execution
GasLeft uint64 `protobuf:"varint,5,opt,name=gas_left,json=gasLeft,proto3" json:"gas_left,omitempty"`
// Total gas used as result of execution or gas estimation
GasUsed uint64 `protobuf:"varint,6,opt,name=gas_used,json=gasUsed,proto3" json:"gas_used,omitempty"`
// Total gas refunded as result of execution
GasRefunded uint64 `protobuf:"varint,7,opt,name=gas_refunded,json=gasRefunded,proto3" json:"gas_refunded,omitempty"`
// Any error encountered during the execution
Error RomError `protobuf:"varint,8,opt,name=error,proto3,enum=executor.v1.RomError" json:"error,omitempty"`
// New SC Address in case of SC creation
CreateAddress string `protobuf:"bytes,9,opt,name=create_address,json=createAddress,proto3" json:"create_address,omitempty"`
// State Root
StateRoot []byte `protobuf:"bytes,10,opt,name=state_root,json=stateRoot,proto3" json:"state_root,omitempty"`
// Logs emited by LOG opcode
Logs []*Log `protobuf:"bytes,11,rep,name=logs,proto3" json:"logs,omitempty"`
// Trace
ExecutionTrace []*ExecutionTraceStep `protobuf:"bytes,13,rep,name=execution_trace,json=executionTrace,proto3" json:"execution_trace,omitempty"`
CallTrace *CallTrace `protobuf:"bytes,14,opt,name=call_trace,json=callTrace,proto3" json:"call_trace,omitempty"`
}
// ProcessTransactionResponse represents the response of a tx process.
type ProcessTransactionResponse struct {
// TxHash is the hash of the transaction
TxHash common.Hash
// Type indicates legacy transaction
// It will be always 0 (legacy) in the executor
Type uint32
// ReturnValue is the returned data from the runtime (function result or data supplied with revert opcode)
ReturnValue []byte
// GasLeft is the total gas left as result of execution
GasLeft uint64
// GasUsed is the total gas used as result of execution or gas estimation
GasUsed uint64
// GasRefunded is the total gas refunded as result of execution
GasRefunded uint64
// RomError represents any error encountered during the execution
RomError error
// CreateAddress is the new SC Address in case of SC creation
CreateAddress common.Address
// StateRoot is the State Root
StateRoot common.Hash
// Logs emitted by LOG opcode
Logs []*types.Log
// IsProcessed indicates if this tx didn't fit into the batch
IsProcessed bool
// Tx is the whole transaction object
Tx types.Transaction
// ExecutionTrace contains the traces produced in the execution
ExecutionTrace []instrumentation.StructLog
// CallTrace contains the call trace.
CallTrace instrumentation.ExecutorTrace
}
// InfoReadWrite has information about modified addresses during the execution
type InfoReadWrite struct {
Address common.Address
Nonce *uint64
Balance *big.Int
}
附录:Polygon Hermez 2.0 zkEVM系列博客
- ZK-Rollups工作原理
- Polygon zkEVM——Hermez 2.0简介
- Polygon zkEVM网络节点
- Polygon zkEVM 基本概念
- Polygon zkEVM Prover
- Polygon zkEVM工具——PIL和CIRCOM
- Polygon zkEVM节点代码解析
- Polygon zkEVM的pil-stark Fibonacci状态机初体验
- Polygon zkEVM的pil-stark Fibonacci状态机代码解析
- Polygon zkEVM PIL编译器——pilcom 代码解析
- Polygon zkEVM Arithmetic状态机
- Polygon zkEVM中的常量多项式
- Polygon zkEVM Binary状态机
- Polygon zkEVM Memory状态机
- Polygon zkEVM Memory Align状态机
- Polygon zkEVM zkASM编译器——zkasmcom
- Polygon zkEVM哈希状态机——Keccak-256和Poseidon
- Polygon zkEVM zkASM语法
- Polygon zkEVM可验证计算简单状态机示例
- Polygon zkEVM zkASM 与 以太坊虚拟机opcode 对应集合
- Polygon zkEVM zkROM代码解析(1)
- Polygon zkEVM zkASM中的函数集合
- Polygon zkEVM zkROM代码解析(2)
- Polygon zkEVM zkROM代码解析(3)
- Polygon zkEVM公式梳理
- Polygon zkEVM中的Merkle tree
- Polygon zkEVM中Goldilocks域元素circom约束
- Polygon zkEVM Merkle tree的circom约束
- Polygon zkEVM FFT和多项式evaluate计算的circom约束
- Polygon zkEVM R1CS与Plonk电路转换
- Polygon zkEVM中的子约束系统
- Polygon zkEVM交易解析
- Polygon zkEVM 审计及递归证明
- Polygon zkEVM发布公开测试网2.0
- Polygon zkEVM测试集——创建合约交易
- Polygon zkEVM中的Recursive STARKs
- Polygon zkEVM的gas定价
- Polygon zkEVM zkProver基本设计原则 以及 Storage状态机
- Polygon zkEVM bridge技术文档
- Polygon zkEVM Trustless L2 State Management 技术文档