Try   HackMD

Introduction

In EVM circuit, ExecutionState are not well balanced, some are very complicated and require many lookups, some are not. But the cost of EVM circuit is determined by the worst case, this note shows how we strike the balance by folding the layout and improve the lookup usage efficiency.

Approach

For example, we want to perform 2 lookup (bitwise and and bitwise or) to the same table without too much overhead.

Naive Layout

a1a2a3 (a1 & a2)a4 (a1 | a2)0b01010b10100b00000b1111

The pseudo code looks like:

assert subset(
    input=rlc(Tag::BitwiseAnd, a1, a2, a3),
    table=rlc(fixed_table),
)
assert subset(
    input=rlc(Tag::BitwiseOr, a1, a2, a4),
    table=rlc(fixed_table),
)

Folded Layout

In folded layout, we try to enable the lookup by constraining the compressed input to the same column of some rotation, to reuse the same subset argument as much as possible.

This layout helps reduce the amount of lookups in EVM circuit a lot.

a1a2a3 (a1 & a2)a4 (a1 | a2)a5 (compressed input)0b01010b10100b00000b1111rlc(Tag::BitwiseAnd, a1, a2, a3)rlc(Tag::BitwiseOr, a1, a2, a4)

The pseudo code looks like:

assert a5 == rlc(Tag::BitwiseAnd, a1, a2, a3)
assert a5_w == rlc(Tag::BitwiseOr, a1, a2, a4)
assert subset(
    input=a5,
    table=rlc(fixed_table),
)

Misc

Multiple inputs to same table

To argue

n degree-1 inputs are all subset to the same table, the cost comparison:

plonkup
halo2 subset argument
Npoint
2+n
1+2n
Nevaluation
5+n
2+3n
D
2+n
1+2n

Obviously,

plonkup has more advantages in such case. With extra challenge support in halo2, we can roll our own
plonkup
.

plonkup

ProverTranscriptVerifier{[fi]1}={com(fi)}{[ti]1}={com(ti)}{[fi]1}, {[ti]1}θθ$F{[hi]1}i[n+1]={com(hi)}i[n+1]{[hi]1}i[n+1]β, γβ,γ$F[z]1=com(z)[z]1xx$F{f¯i}={eval(fi,x)}{t¯i}={eval(ti,x)}t¯ω=eval(t,ωx){h¯i}i[n+1]={eval(hi,x)}i[n+1]h¯0ω=eval(hi,ωx)z¯=eval(z,x)z¯ω=eval(z,ωx){f¯i}, {t¯i}, t¯ω, {h¯i}i[n+1], h¯0ω, z¯, z¯ω

halo2 subset argument

ProverTranscriptVerifier{[fi]1}={com(fi)}{[ti]1}={com(ti)}{[fi]1}, {[ti]1}θθ$F{[fi]1[ti]1}i[n]={com(fi)com(ti)}i[n]{[fi]1, [ti]1}i[n]β, γβ,γ$F[z]1=com(z)[z]1xx$F{f¯i}={eval(fi,x)}{t¯i}={eval(ti,x)}{f¯if¯iωt¯i}i[n]={eval(fi,x)eval(fi,ωx)eval(ti,x)}i[n]z¯=eval(z,x)z¯ω=eval(z,ωx){f¯i}, {t¯i}, {f¯i, f¯iω, t¯i}i[n], z¯, z¯ω