MinaFoundation / Core-Grants

25 stars 13 forks source link

RFC-0002: Introducing Side-loading Verification Keys in o1js #3

Closed teddyjfpender closed 5 months ago

teddyjfpender commented 10 months ago

πŸš€ Proposal Overview

We're excited to propose the introduction of side-loading verification keys in o1js smart contracts and provable-programs. This RFC (Request for Comments) aims to improve the developer experience by increasing flexibility and allow for the creation of new, innovative design patterns.

🎯 Why It Matters

Mina developers using o1js are limited to static verification keys compiled during their smart contract or provable-program creation, restricting dynamic interactions. By enabling side-loading of these keys, we open a world of possibilities, allowing for more complex, adaptable, and user-friendly applications within the Mina ecosystem.

πŸ” Highlights of the RFC

πŸ“£ Seeking Community Input

This proposal is a stepping stone and needs your contributions. Your input is vital to shaping a robust and effective implementation.

πŸ”— RFC Details

For a comprehensive understanding of the proposal, challenges, and anticipated impact, please refer to the full RFC document.

rpanic commented 9 months ago

I started to implement side-loaded vks a few week ago and actually got quite far already.

I thought since this RFC exists, I will show you the API design that I came up with, in case anybody wants to share his/her thoughts.

So previously, we had one Proof class that provided the linkage between verification keys of compiled circuits to the usage of them in foreign circuits. After the introductions of sideloaded vks, this can now has to be distinguished between the old, static vks and the new SL-vks. For this, I extended the old Proof class with its sideloaded pendant DynamicProof.

class DynamicProof<Input, Output> extends ProofBase<Input, Output> {
  verify(vk: VerificationKey);
  verifyIf(vk: VerificationKey, condition: Bool);
}

So as you can see, it implements the same methods as the default class does, but it requires a additional argument for the verfication key, that this proof should be verified with.

An example usage of this inside a ZkProgram could look like:

ZkProgram({
    name: "program2",
    publicInput: Field,
    methods: {
        foo: {
            privateInputs: [SampleSideloadedProof, VerificationKey],
            method(input: Field, proof: SampleSideloadedProof, vk: VerificationKey) {
                proof.verify(vk);

                proof.publicInput.assertEquals(input, "Public input not matching")
            }
        }
    }
});

Together with @mrmr1993 I am fixing some last issues, and after hearing everyone's thoughts, looking forward to merging this to o1js.