diff --git a/src/lib/proof_system.ts b/src/lib/proof_system.ts index 0cea67e2f..8378abd19 100644 --- a/src/lib/proof_system.ts +++ b/src/lib/proof_system.ts @@ -22,3 +22,57 @@ class Proof { } } type RawProof = unknown; +type CompiledTag = unknown; + +type Circuit = { + privateInput: { + [K in keyof Args]: AsFieldElements; + }; + circuit(publicInput: PublicInput, ...args: Args): void; +}; + +type Prover = ( + publicInput: PublicInput, + ...args: Args +) => Promise>; + +// TODO: this only works for Field / Bool / UInt32 / UInt64 / Int64 because they have a custom `check` method +// doesn't work for general CircuitValue +// we need a robust method for infering the type from a CircuitValue subclass! +type InferAsFields> = T['check'] extends ( + x: infer U +) => void + ? U + : never; + +function MultiCircuit< + PublicInput extends AsFieldElements, + Types extends { + [I in string]: readonly [any, ...any[]]; + } +>(c: { + publicInput: PublicInput; + circuits: { + [I in keyof Types]: Circuit, Types[I]>; + }; +}): { + [I in keyof Types]: Prover, Types[I]>; +} { + return c as never; +} + +/* let myCircuit = MultiCircuit({ + publicInput: UInt32, + circuits: { + someCircuit: { + privateInput: [Bool], + circuit(publicInput: UInt32, b: Bool) { + publicInput.add(9).equals(UInt32.from(10)).and(b).assertTrue(); + }, + }, + }, +}); + +let p: Proof = await myCircuit.someCircuit(UInt32.one, Bool.true); +p.verify(); +p.publicInput; */