In pull-request read-write lookup offline-memory-checking logUp-based implementation in (Super)Nova R1CS discussion, one of remains question is to optimise the cost of random oracle circuit in IVC. This post try to address the issue and propose a design.
One of the nice property to derive challenge via random oracle in folding IVC is we can decouple random oracle into function composition, and relax one or more of function to loose property, e.g. one of them not nessesary to satisify indifferentiable from a random oracle, while still keep overall composition result indifferentiable from random oracle. With relaxation, we implement relaxed function in IVC step circuit, while in the final SNARK pass accumuation result to another random oracle function to get the challenge which indifferentiable from random oracle.
Terminology cited from Proving the correct execution of concurrent services in zero-knowledge
Giving
,
with below
R even can be non-uniform, and not indifferentiable from a random oracle
Then is random oracle
reference proof https://hackmd.io/@2DQ_BR_sTUOyIfPms3lGVw/r1TNUj8q6
In each step circuit, we know how many read/write it will have. Per read/write we need to encoding 5 field elements and accumulated with prev acc value to obtain new acc and pass to next round.
To design a collision resistent hash, and with idea from pedersen hash, we can design as below: in setup phase we can pre-generate random ordered-set field values , for .
In zkVM setting, one step circuit in SuperNova might represent one opcode. Each opcode read/write are bounded. Giving max read/write num is , .
Question: need to be prime?
Giving , we decompose each field value into bit decomposition and concat all as
= bit() || bit() || bit() || bit() || bit()
Then we can encode batched field values into an order matter single field value, assume bit concated value lead to j
bits
where is the bit value of in index
In R1CS, This formula can be represented in just 1 R1CS constraint.
To encode batched of read/write in step circuit, it's naturally viewing it as encoding vector from its bits representation
= bit() || bit() || bit() || bit() || bit() || bit() || bit() || bit() || bit() || bit() || …
Notice with these design, it retain the order matters feature, such that if we exchange any 2 field value from vector it lead to different encoding field value.
So the length of pre-generated constant random field set need to cover max bits length in step circuit.
For encoded acc value we can passed it to next step to aggregate to next acc value. However we need to account for one order matters scenario.
Giving vector folding step m
and step n = m+1
Then
When a unhonest prover exchange 2 field value in different step yet same position, e.g. with , then the new acc value will remain unchanged, imply function R is not collision resistent with order matter.
To address this issue, we introduce step variable into accumulation formula as
where represent current folding step in Nova, and starting from 1.
Another alternative design is , to raise to power
Below we will infer the probability for such collision exist
define
To prove R is collision resistent, firstly we analyze = 2 case, and field set
Then it's equivalent to find , such that
Giving Encoding function R
And define set , subset
Let
Subset got choices, each can derived respective . So there are possible .
It implies for we have choice, after settle down, so got choice.
The probability for overlapping (collision) is
For example, giving folding steps . is 255 bit. Then the probability for collision exist
For > 2, it is equivalent to find , such that
We can rewrite as
Combination of lead to
choice.
Similarly, also got choice
And the probability for collision exist is
Speical notice above analysis just prove the probability of collision exist. We still need to search solition space and verify to find it. To verify a candidate, we need to do efficient factorial decomposition, means given , find such that
naive bruce-force search take time complexity, not sure is there any efficient other algorithm .
Giving example
Then in R1CS
name | Decomposition into Bits | collision resistent R |
---|---|---|
#R1CS constraints | 32 + 1 from address a 64 + 1 from value v 32 + 1 from ts 33 + 65 x 2 + 33 x 2 = 229. giving k reads/writes overall cost 229 x k |
1 |
#R1CS vars | 32 from address a bit 64 from value v bits 32 from ts bits 32 + 64 x 2 + 32 x 2 = 224 Giving k reads/writes, overall cost 224 x k |
1 |
So the overall challenge cost are growing linear with number of read/write in step circuit, while still remain agnostic to table size |T|
We can choose any random oracle candidate e.g. poseidon hash in final SNARK.
The final challenge (r, )
and