@@ -5,11 +5,10 @@ import { tmpdir } from "os";
55import { join } from "path" ;
66import { promisify } from "util" ;
77
8- import type { VerificationResult , RunGDVInput } from "../types/verification.js" ;
8+ import { getVerificationResultId , type VerificationResult , type RunGDVInput } from "../types/verification.js" ;
99
1010const execFileAsync = promisify ( execFile ) ;
1111
12-
1312function extractSZSStatus ( output : string ) : string | null {
1413 const match = output . match ( / S Z S s t a t u s \s + ( [ A - Z a - z _ ] + ) / i) ;
1514
@@ -32,11 +31,25 @@ function normalizeTPTPIncludes(problemContent: string): string {
3231 ) ;
3332}
3433
35- export async function runGDV ( input : RunGDVInput ) : Promise < VerificationResult > {
36- const { proofId, verifierNodeId, problemContent, proofContent, tptpRoot, dockerImage } =
37- input ;
34+ export async function runGDV (
35+ input : RunGDVInput
36+ ) : Promise < VerificationResult > {
37+ const {
38+ proofId,
39+ verifierNodeId,
40+ problemContent,
41+ proofContent,
42+ tptpRoot,
43+ dockerImage,
44+ } = input ;
45+
46+ const verificationResultId = getVerificationResultId ( proofId , verifierNodeId ) ;
47+
48+ const workDir = join (
49+ tmpdir ( ) ,
50+ `gdv-${ proofId } -${ randomUUID ( ) } `
51+ ) ;
3852
39- const workDir = join ( tmpdir ( ) , `gdv-${ proofId } -${ randomUUID ( ) } ` ) ;
4053 const problemFile = join ( workDir , "problem.p" ) ;
4154 const proofFile = join ( workDir , "proof.s" ) ;
4255
@@ -56,10 +69,21 @@ export async function runGDV(input: RunGDVInput): Promise<VerificationResult> {
5669 await mkdir ( workDir , { recursive : true } ) ;
5770
5871 try {
59- const normalizedProblemContent = normalizeTPTPIncludes ( problemContent ) ;
72+ const normalizedProblemContent =
73+ normalizeTPTPIncludes ( problemContent ) ;
74+
75+ await writeFile (
76+ problemFile ,
77+ normalizedProblemContent ,
78+ "utf8"
79+ ) ;
80+
81+ await writeFile (
82+ proofFile ,
83+ cleanedProofContent ,
84+ "utf8"
85+ ) ;
6086
61- await writeFile ( problemFile , normalizedProblemContent , "utf8" ) ;
62- await writeFile ( proofFile , cleanedProofContent , "utf8" ) ;
6387 const { stdout, stderr } = await execFileAsync ( "docker" , [
6488 "run" ,
6589 "--rm" ,
@@ -83,22 +107,30 @@ export async function runGDV(input: RunGDVInput): Promise<VerificationResult> {
83107 const verified = gdvOutput . includes ( "SUCCESS" ) || szsStatus === "Verified" ;
84108
85109 return {
110+ verificationResultId,
86111 proofId,
87112 verifierNodeId,
88113 verified,
89114 szsStatus,
90- gdvOutputHash : createHash ( "sha256" ) . update ( gdvOutput ) . digest ( "hex" ) ,
115+ gdvOutputHash : createHash ( "sha256" )
116+ . update ( gdvOutput )
117+ . digest ( "hex" ) ,
91118 gdvRawOutput : gdvOutput ,
92119 verifiedAt : Date . now ( ) ,
93120 } ;
94121 } catch ( error ) {
95- const err = error as { stdout ?: string ; stderr ?: string ; message ?: string } ;
122+ const err = error as {
123+ stdout ?: string ;
124+ stderr ?: string ;
125+ message ?: string ;
126+ } ;
96127
97- const gdvOutput = `${ err . stdout ?? "" } \n${ err . stderr ?? "" } \n ${
98- err . message ?? ""
99- } `;
128+ const gdvOutput = `${ err . stdout ?? "" } \n${
129+ err . stderr ?? ""
130+ } \n ${ err . message ?? "" } `;
100131
101132 return {
133+ verificationResultId,
102134 proofId,
103135 verifierNodeId,
104136 verified : false ,
@@ -108,6 +140,9 @@ export async function runGDV(input: RunGDVInput): Promise<VerificationResult> {
108140 verifiedAt : Date . now ( ) ,
109141 } ;
110142 } finally {
111- await rm ( workDir , { recursive : true , force : true } ) ;
143+ await rm ( workDir , {
144+ recursive : true ,
145+ force : true ,
146+ } ) ;
112147 }
113148}
0 commit comments