Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add env var to disable bb cleanup #7936

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions yarn-project/bb-prover/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export interface BBConfig {
bbBinaryPath: string;
bbWorkingDirectory: string;
/** Whether to skip tmp dir cleanup for debugging purposes */
bbSkipCleanup?: boolean;
}

export interface ACVMConfig {
Expand Down
13 changes: 9 additions & 4 deletions yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
constructor(
private bbBinaryPath: string,
private bbWorkingDirectory: string,
private skipCleanup: boolean,
private log = createDebugLogger('aztec:bb-native-prover'),
) {}

Expand Down Expand Up @@ -119,7 +120,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
const operation = async (directory: string) => {
return await this._createClientIvcProof(directory, acirs, witnessStack);
};
return await runInDirectory(this.bbWorkingDirectory, operation);
return await this.runInDirectory(operation);
}

public getSiloedCommitments(publicInputs: PrivateCircuitPublicInputs) {
Expand Down Expand Up @@ -189,7 +190,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
return await this.computeVerificationKey(directory, bytecode, 'App', appCircuitName);
};

return await runInDirectory(this.bbWorkingDirectory, operation);
return await this.runInDirectory(operation);
}

/**
Expand Down Expand Up @@ -229,7 +230,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
await fs.writeFile(verificationKeyPath, verificationKey);
return await verifyProof(this.bbBinaryPath, proofFileName, verificationKeyPath!, logFunction);
};
return await runInDirectory(this.bbWorkingDirectory, operation);
return await this.runInDirectory(operation);
}

/**
Expand Down Expand Up @@ -270,7 +271,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
} satisfies CircuitWitnessGenerationStats);

// TODO(#7410) we dont need to generate vk's for these circuits, they are in the vk tree
const { verificationKey } = await runInDirectory(this.bbWorkingDirectory, dir =>
const { verificationKey } = await this.runInDirectory(dir =>
this.computeVerificationKey(dir, Buffer.from(compiledCircuit.bytecode, 'base64'), circuitType),
);
const kernelOutput: PrivateKernelSimulateOutput<O> = {
Expand Down Expand Up @@ -363,4 +364,8 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver {
);
return proof;
}

private runInDirectory<T>(fn: (dir: string) => Promise<T>) {
return runInDirectory(this.bbWorkingDirectory, fn, this.skipCleanup);
}
}
20 changes: 10 additions & 10 deletions yarn-project/bb-prover/src/prover/bb_prover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {

return { circuitOutput: output, proof };
};
return await runInDirectory(this.config.bbWorkingDirectory, operation);
return await this.runInDirectory(operation);
}

private async generateAvmProofWithBB(input: AvmCircuitInputs, workingDirectory: string): Promise<BBSuccess> {
Expand Down Expand Up @@ -571,11 +571,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
}

private async createAvmProof(input: AvmCircuitInputs): Promise<ProofAndVerificationKey> {
const cleanupDir: boolean = !process.env.AVM_PROVING_PRESERVE_WORKING_DIR;
const operation = async (bbWorkingDirectory: string): Promise<ProofAndVerificationKey> => {
if (!cleanupDir) {
logger.info(`Preserving working directory ${bbWorkingDirectory}`);
}
const provingResult = await this.generateAvmProofWithBB(input, bbWorkingDirectory);

const rawProof = await fs.readFile(provingResult.proofPath!);
Expand Down Expand Up @@ -608,7 +604,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {

return { proof, verificationKey };
};
return await runInDirectory(this.config.bbWorkingDirectory, operation, cleanupDir);
return await this.runInDirectory(operation);
}

public async getTubeProof(
Expand Down Expand Up @@ -640,7 +636,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {

return { tubeVK, tubeProof };
};
return await runInDirectory(this.config.bbWorkingDirectory, operation);
return await this.runInDirectory(operation);
}

/**
Expand Down Expand Up @@ -699,7 +695,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
proof,
};
};
return await runInDirectory(this.config.bbWorkingDirectory, operation);
return await this.runInDirectory(operation);
}

/**
Expand Down Expand Up @@ -752,7 +748,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
logger.info(`Successfully verified proof from key in ${result.durationMs} ms`);
};

await runInDirectory(this.config.bbWorkingDirectory, operation);
await this.runInDirectory(operation);
}

/**
Expand Down Expand Up @@ -824,7 +820,7 @@ export class BBNativeRollupProver implements ServerCircuitProver {
true,
);
};
return await runInDirectory(this.config.bbWorkingDirectory, operation);
return await this.runInDirectory(operation);
}

/**
Expand Down Expand Up @@ -958,4 +954,8 @@ export class BBNativeRollupProver implements ServerCircuitProver {

return proof;
}

private runInDirectory<T>(fn: (dir: string) => Promise<T>) {
return runInDirectory(this.config.bbWorkingDirectory, fn, this.config.bbSkipCleanup);
}
}
4 changes: 2 additions & 2 deletions yarn-project/bb-prover/src/verifier/bb_verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
proofType: 'ultra-honk',
} satisfies CircuitVerificationStats);
};
await runInDirectory(this.config.bbWorkingDirectory, operation);
await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup);
}

public async generateSolidityContract(circuit: ProtocolArtifact, contractName: string) {
Expand Down Expand Up @@ -168,7 +168,7 @@ export class BBCircuitVerifier implements ClientProtocolCircuitVerifier {
proofType: 'client-ivc',
} satisfies CircuitVerificationStats);
};
await runInDirectory(this.config.bbWorkingDirectory, operation);
await runInDirectory(this.config.bbWorkingDirectory, operation, this.config.bbSkipCleanup);
return true;
} catch (err) {
this.logger.warn(`Failed to verify ClientIVC proof for tx ${Tx.getHash(tx)}: ${String(err)}`);
Expand Down
1 change: 1 addition & 0 deletions yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ export type EnvVar =
| 'PXE_DATA_DIRECTORY'
| 'BB_BINARY_PATH'
| 'BB_WORKING_DIRECTORY'
| 'BB_SKIP_CLEANUP'
| 'PXE_PROVER_ENABLED';
4 changes: 2 additions & 2 deletions yarn-project/foundation/src/fs/run_in_dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as path from 'path';
export async function runInDirectory<T>(
workingDirBase: string,
fn: (dir: string) => Promise<T>,
cleanup: boolean = true,
skipCleanup: boolean | undefined,
): Promise<T> {
// Create random directory to be used for temp files
const workingDirectory = await fs.mkdtemp(path.join(workingDirBase, 'tmp-'));
Expand All @@ -16,7 +16,7 @@ export async function runInDirectory<T>(
try {
return await fn(workingDirectory);
} finally {
if (cleanup) {
if (!skipCleanup) {
await fs.rm(workingDirectory, { recursive: true, force: true });
}
}
Expand Down
6 changes: 6 additions & 0 deletions yarn-project/pxe/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { fileURLToPath } from 'url';
export interface BBProverConfig {
bbWorkingDirectory?: string;
bbBinaryPath?: string;
bbSkipCleanup?: boolean;
}

/**
Expand Down Expand Up @@ -72,6 +73,11 @@ export const pxeConfigMappings: ConfigMappingsType<PXEServiceConfig> = {
env: 'BB_WORKING_DIRECTORY',
description: 'Working directory for the BB binary',
},
bbSkipCleanup: {
env: 'BB_SKIP_CLEANUP',
description: 'True to skip cleanup of temporary files for debugging purposes',
...booleanConfigHelper(),
},
proverEnabled: {
env: 'PXE_PROVER_ENABLED',
description: 'Enable real proofs',
Expand Down
1 change: 1 addition & 0 deletions yarn-project/pxe/src/pxe_service/create_pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export async function createPXEService(
: new BBNativePrivateKernelProver(
config.bbBinaryPath!,
config.bbWorkingDirectory!,
!!config.bbSkipCleanup,
createDebugLogger('aztec:pxe:bb-native-prover' + (logSuffix ? `:${logSuffix}` : '')),
);
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/providers/acvm_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,6 @@ export class NativeACVMSimulator implements SimulationProvider {
return result.witness;
};

return await runInDirectory(this.workingDirectory, operation);
return await runInDirectory(this.workingDirectory, operation, false);
}
}
Loading