appliedzkp zkevm(9)中的Bytecode Proof

1. 引言

bytecode proof可帮助EVM proof,使得bytecode更易于访问(bytecode以其code hash来标识)。bytecode中的每个byte可通过其在该bytecode中的位置来访问。同时标注了一个flag来标识该byte 是一个opcode 还是 给前一PUSH指令的data。

2. Bytecode Circuit Layout

Column Description
q_first 1 on the first row, else 0
q_last 1 on the last row, else 0
hash The keccak hash of the bytecode
tag Tag indicates whether value is a byte or length of the bytecode
index The position of the byte in the bytecode
value The byte data for the current position, or length of the bytecode
is_code 1 if the byte is code, 0 if the byte is PUSH data
push_data_left The number of PUSH data bytes that still follow the current row
hash_rlc The accumulator containing the current and previous bytes
hash_length The bytecode length
byte_push_size The number of bytes pushed for the current byte
is_final 1 if the current byte is the last byte of the bytecode, else 0
padding 1 if the current row is padding, else 0
push_data_left_inv The inverse of push_data_left (IsZeroChip helper)
push_table.byte Push Table: A byte value
push_table.push_size Push Table: The number of bytes pushed for this byte as opcode

3. Push lookup table

push lookup table用于find how many bytes an opcode pushes,用于探测哪个byte是code,哪个byte不是code。

由于会对每个byte进行lookup,该table也可间接用于range check the byte inputs。

Byte Num bytes pushed
[0, OpcodeId::PUSH1] 0
[OpcodeId::PUSH1, OpcodeId::PUSH32] [1..32]
[OpcodeId::PUSH32, 256] 0

3.1 Circuit behavior

该circuit 以通过设置tag = Length添加bytecode length的行 开始,然后自位置0开始,遍历该bytecode的所有bytes。

参考资料

[1] zkevm-specs Bytecode Proof

猜你喜欢

转载自blog.csdn.net/mutourend/article/details/125473793