appliedzkp zkevm(10)中的Transactions Proof

1. 引言

transactions proof会:

  • 验证每笔交易的签名;
  • 验证transactionsRoot对应的merkle patricia trie中刚好包含了所有的交易(不多不少);
  • 使得EVM proof可通过transaction table访问transactions data。

2. Transcation encoding

存在不同的交易编码方式。在第一版本的zkEVM将仅支持兼容EIP-155的Legacy transaction。未来将支持Non-Legacy (EIP-2718)transactions。

2.1 Legacy Transaction encoding

Legacy type为:

rlp([nonce, gasPrice, gas, to, value, data, sig_v, r, s])
  • 在BIP-155之前,待签名的hashed data为:(nonce, gasprice, gas, to, value, data) with sig_v = {0,1} + 27
  • 在EIP-155之后,待签名的hashed data为:(nonce, gasprice, gas, to, value, data, chain_id, 0, 0) with sig_v = {0,1} + CHAIN_ID * 2 + 35

其中的{0,1}表示的curve point y y y坐标的极性,该curve point对应为secp256k1签名过程中的公钥。

2.2 Non-Legacy (EIP-2719) Transaction encoding

根据:

Non-Legacy类型为:

0x02 || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas, destination, amount, data, access_list, signature_y_parity, signature_r, signature_s])

待签名的hashed data为:待定。

3. Circuit behaviour

Transactions proof证明电路中对应的public inputs有:

  • chain_id
  • transactionsRoot

每笔交易由以下参数定义:

  • (nonce, gas_price, gas, to, value, data, sig_v, sig_r, sig_s)

其中可用作public inputs的参数有:

  • (nonce, gas_price, gas, to, value, data, from)

Transactions proof证明电路的验证逻辑为:

  • 1)txSignData: bytes = rlp([nonce, gas_price, gas, to, value, data, chain_id, 0, 0])
  • 2)txSignHash: word = keccak(txSignData)
  • 3)sig_parity: {0, 1} = sig_v - 35 - chain_id / 2
  • 4)ecdsa_recover(txSignHash, sig_parity, sig_r, sig_s) = pubKey 或等价为 verify(txSignHash, sig_r, sig_s, pubKey) = true
  • 5)fromAddress = keccak(pubKey)[-20:]

其中:

  • 第1)步中对交易参数的rlp编码将采用定制的rlp encoding gadget来实现,以区分(不同于)MPT circuit中使用的rlp encoding。
  • 第2)步中的待签名消息keccak hash验证将采用keccak circuit。该tx circuit将实现一个单独的对应keccak 的lookup table(使用RLC将rlp encoded transaction类加紧一个single value内)。
  • 第3)步中根据待签名消息和签名恢复公钥将采用ECDSA circuit。该tx circuit将实现一个对应ECDSA的lookup table。
  • 第5)步中的公钥keccak hash验证将采用keccak circuit。该tx circuit将实现一个对应keccak的lookup table。

根据以上信息,构建了TxTable:

0 TxID 1 Tag 2 Index 3 value
TxContextFieldTag
$TxID Nonce 0 $value: raw
$TxID Gas 0 $value: raw
$TxID GasPrice 0 $value: rlc
$TxID GasTipCap 0 $value: 0
$TxID GasFeeCap 0 $value: 0
$TxID CallerAddress 0 $value: raw
$TxID CalleeAddress 0 $value: raw
$TxID IsCreate 0 $value: raw
$TxID Value 0 $value: rlc
$TxID CallDataLength 0 $value: raw
$TxID CallData $ByteIndex $value: raw

其中:

  • Gas = gas
  • GasTipCap = 0
  • GasFeeCap = 0
  • CallerAddress = fromAddress
  • CalleeAddress = to
  • IsCreate = 1 if to is None else 0
  • CallDataLength = len(data)
  • CallData[KaTeX parse error: Can't use function '\]' in math mode at position 10: ByteIndex\̲]̲ = data\[ByteIndex]

参考资料

[1] zkEVM-specs Transactions proof

猜你喜欢

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