@@ -5,8 +5,7 @@ import { omit } from "lodash";
55import fs from "node:fs" ;
66import os from "node:os" ;
77import path from "node:path" ;
8- import { z } from "zod" ;
9- import { promiseWithResolvers } from "../utils.js" ;
8+ import { decodeNativeHonkProof , promiseWithResolvers } from "../utils.js" ;
109import { inWorkingDir , makeRunCommand , splitInput } from "./utils.js" ;
1110
1211export class MpcProverService {
@@ -143,27 +142,11 @@ async function proveAsParty(params: {
143142 `./run-party.sh ${ workingDir } ${ circuitPath } ${ params . partyIndex } ` ,
144143 ) ;
145144
146- const publicInputs = z
147- . string ( )
148- . array ( )
149- . parse (
150- JSON . parse (
151- fs . readFileSync ( path . join ( workingDir , "public_input.json" ) , "utf-8" ) ,
152- ) ,
153- ) ;
154- const proofData = Uint8Array . from (
145+ const { proof, publicInputs } = decodeNativeHonkProof (
155146 fs . readFileSync (
156147 path . join ( workingDir , `proof.${ params . partyIndex } .proof` ) ,
157148 ) ,
158149 ) ;
159- // arcane magic
160- const proof = ethers . getBytes (
161- ethers . concat ( [
162- proofData . slice ( 0 , 2 ) ,
163- proofData . slice ( 6 , 100 ) ,
164- proofData . slice ( 100 + publicInputs . length * 32 ) ,
165- ] ) ,
166- ) ;
167150
168151 // pre-verify proof
169152 const backend = new UltraHonkBackend ( params . circuit . bytecode , {
@@ -172,16 +155,7 @@ async function proveAsParty(params: {
172155 let verified : boolean ;
173156 try {
174157 verified = await backend . verifyProof (
175- {
176- // prepend length as 4 bytes
177- proof : ethers . getBytes (
178- ethers . concat ( [
179- ethers . zeroPadValue ( ethers . toBeArray ( proof . length ) , 4 ) ,
180- proof ,
181- ] ) ,
182- ) ,
183- publicInputs,
184- } ,
158+ { proof, publicInputs } ,
185159 { keccak : true } ,
186160 ) ;
187161 } catch ( e : any ) {
@@ -196,8 +170,10 @@ async function proveAsParty(params: {
196170 throw new Error ( "mpc generated invalid proof: returned false" ) ;
197171 }
198172
199- // console.log("proof native\n", JSON.stringify(Array.from(proof)));
200- return { proof, publicInputs } ;
173+ return {
174+ proof : proof . slice ( 4 ) , // remove length
175+ publicInputs,
176+ } ;
201177 } ) ;
202178}
203179
0 commit comments