-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add VerifierData & return it alongside the proof (#310)
- Loading branch information
Showing
9 changed files
with
69 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Abi } from '@noir-lang/noirc_abi'; | ||
|
||
export function publicInputs(abi: Abi): Abi { | ||
const parameters = abi.parameters.filter((param) => param.visibility === 'public'); | ||
return { | ||
...abi, | ||
parameters | ||
}; | ||
} | ||
|
||
export function returnValues(abi: Abi): Abi { | ||
return { | ||
parameters: [], | ||
param_witnesses: {}, | ||
error_types: {}, | ||
return_type: abi.return_type, | ||
return_witnesses: abi.return_witnesses | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
import { randomUUID } from 'crypto'; | ||
import { MonorepoCircuit } from './circuit.js'; | ||
import { NargoProver } from './nargoProver.js'; | ||
import { encodeProofAsFields, encodePublicInputs } from './utils.js'; | ||
import { encodeProofAsFields } from './utils.js'; | ||
import { InputMap } from '@noir-lang/noirc_abi'; | ||
import { Hex } from 'viem'; | ||
import path from 'path'; | ||
import { VerifierData } from './verifierData.js'; | ||
|
||
export interface VerifiableComputation { | ||
proofAsFields: Hex[]; | ||
verifierData: VerifierData; | ||
} | ||
|
||
export class BaseProver { | ||
constructor(public circuit: MonorepoCircuit) {} | ||
public async proveBase(inputs: InputMap): Promise<Hex[]> { | ||
public async proveBase(inputs: InputMap): Promise<VerifiableComputation> { | ||
const proofId = randomUUID(); | ||
const prover = new NargoProver(this.circuit, proofId); | ||
|
||
const { proof, verifierData } = await prover.prove(inputs); | ||
const proof = await prover.prove(inputs); | ||
|
||
const proofAsFieldsPath = path.join(this.circuit.root, 'proofs', `${this.circuit.name}.proof.json`); | ||
return await encodeProofAsFields( | ||
const verifierData = await VerifierData.create(prover.verifierTomlPath, this.circuit.artefact.abi); | ||
const proofAsFields = await encodeProofAsFields( | ||
proof, | ||
encodePublicInputs(this.circuit.artefact.abi, verifierData), | ||
verifierData.publicInputs(), | ||
this.circuit.vkPath(), | ||
proofAsFieldsPath | ||
); | ||
return { proofAsFields, verifierData }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Abi, InputMap, abiEncode } from '@noir-lang/noirc_abi'; | ||
import { readTomlObject } from '../../util/file.js'; | ||
import { Hex } from 'viem'; | ||
import { publicInputs, returnValues } from './abi.js'; | ||
|
||
export class VerifierData { | ||
public static async create(verifierTomlPath: string, abi: Abi) { | ||
const verifierData = await readTomlObject<InputMap>(verifierTomlPath); | ||
return new VerifierData(abi, verifierData); | ||
} | ||
|
||
public publicInputs(): Hex[] { | ||
return this.encodeSubset(publicInputs(this.abi)); | ||
} | ||
|
||
public returnValues(): Hex[] { | ||
return this.encodeSubset(returnValues(this.abi)); | ||
} | ||
|
||
public encodeSubset(subset: Abi): Hex[] { | ||
const subsetEncodedMap = abiEncode(subset, this.verifierData, this.verifierData.return); | ||
return Array.from(subsetEncodedMap.values()) as Hex[]; | ||
} | ||
|
||
private constructor( | ||
private abi: Abi, | ||
private verifierData: InputMap | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.