proto-kit / framework

Apache License 2.0
26 stars 8 forks source link

Use Sideloading for runtime methods #190

Open rpanic opened 3 weeks ago

rpanic commented 3 weeks ago

Is your feature request related to a problem? Please describe. Currently, wrap circuits in pickles have a maximum number of circuit methods that can be used. This limit is quite low and users are expected to run into this limitation eventually. Additionally, compilation of any circuit currently requires all circuits it consumes to be compiled as well which leads to bad memory performance.

Describe the solution you'd like o1js now exposes sideloading, which can be used to split up zkprograms into multiple pieces and then stitch them together afterwards. The propsed solution is the following: Create a sepearte ZkProgram for each runtime method. In parallel, hash the verification keys of all methods and put them into a merkle tree, whose root will then be baked into the BlockProver circuit via a Field constant. For workers, proving becomes really easy, compile (or load) the circuit for the specific method they have to prove, and return the proof to the sequencer. During proveTransaction, the BlockProver will then prove the membership of this proof's verification key in the global runtime-method merkle tree by providing a tree witness to that and computing the root using the verification key's hash (which is a builtin primitive in sideloaded keys). The resulting root can then be asserted to equal the previously baked in root in the BlockProver. This procedure ensures that only valid runtime methods can be proven since otherwise the verification key would change (since the methodId is also baked into the runtime method's circuit)