fluidex / circuits

GNU Affero General Public License v3.0
10 stars 5 forks source link

feat: add data availability #181

Closed noel2004 closed 3 years ago

noel2004 commented 3 years ago

BREAKING: the new feature require more input field in witness so the prover-cluster would be broken for this new circuit. Merging should be suspended until rollup manager has supported data availability (https://github.com/fluidex/rollup-state-manager/issues/178)

This work is mainly for issue #144, include following parts:

(All of works above should include test cases)

For first phase we just put transfer on chain, and data encoded as follows:

[ NAccountLevels bits ] fromAccountID [ NAccountLevels bits ] toAccountID [ 16 bits ] tokenID [ 40 bits ] amount

We have no token records on L2 so just purpose the maximum count is 2^16 (2 bytes, according to the discussion in issue)

noel2004 commented 3 years ago

Should also evaluate the cost that DA has induced. Current circuit for block_2_2_2_2 (no DA) is:

[INFO] snarkJS: Curve: bn-128 [INFO] snarkJS: # of Wires: 52473 [INFO] snarkJS: # of Constraints: 52639 [INFO] snarkJS: # of Private Inputs: 164 [INFO] snarkJS: # of Public Inputs: 2 [INFO] snarkJS: # of Labels: 242393 [INFO] snarkJS: # of Outputs: 0

noel2004 commented 3 years ago

When data avaliability has been induced, about 30k constraints has been added into the circuit for block 2_2_2_2

should notice that the size should increase linearly with nTxs

[INFO] snarkJS: Curve: bn-128 [INFO] snarkJS: # of Wires: 81318 [INFO] snarkJS: # of Constraints: 81804 [INFO] snarkJS: # of Private Inputs: 164 [INFO] snarkJS: # of Public Inputs: 2 [INFO] snarkJS: # of Labels: 447045 [INFO] snarkJS: # of Outputs: 2

noel2004 commented 3 years ago

Has made fixing according to the comments

The missed decode circuit for float40 is completed now, but many templatize works on circuits still being left (now they are mostly hard-coded) ...