1
+ import { BB_RESULT , verifyClientIvcProof , writeClientIVCProofToOutputDirectory } from '@aztec/bb-prover' ;
1
2
import { AztecClientBackend } from '@aztec/bb.js' ;
3
+ import { createLogger } from '@aztec/foundation/log' ;
2
4
3
5
import { jest } from '@jest/globals' ;
4
6
5
7
/* eslint-disable camelcase */
6
8
import createDebug from 'debug' ;
7
9
import { ungzip } from 'pako' ;
10
+ import path from 'path' ;
11
+ import { fileURLToPath } from 'url' ;
8
12
13
+ import { getWorkingDirectory } from './bb_working_directory.js' ;
9
14
import {
10
15
MOCK_MAX_COMMITMENTS_PER_TX ,
11
16
MockAppCreatorCircuit ,
@@ -19,6 +24,7 @@ import {
19
24
MockPrivateKernelResetCircuit ,
20
25
MockPrivateKernelResetVk ,
21
26
MockPrivateKernelTailCircuit ,
27
+ generate3FunctionTestingIVCStack ,
22
28
getVkAsFields ,
23
29
witnessGenCreatorAppMockCircuit ,
24
30
witnessGenMockPrivateKernelInitCircuit ,
@@ -27,9 +33,11 @@ import {
27
33
witnessGenMockPrivateKernelTailCircuit ,
28
34
witnessGenReaderAppMockCircuit ,
29
35
} from './index.js' ;
30
- import { proveThenVerifyAztecClient } from './prove_wasm.js' ;
36
+ import { proveClientIVC as proveClientIVCNative } from './prove_native.js' ;
37
+ import { proveClientIVC as proveClientIVCWasm , proveThenVerifyAztecClient } from './prove_wasm.js' ;
38
+
39
+ const logger = createLogger ( 'ivc-integration:test:wasm' ) ;
31
40
32
- const logger = createDebug ( 'ivc-integration:test:wasm' ) ;
33
41
createDebug . enable ( '*' ) ;
34
42
35
43
jest . setTimeout ( 120_000 ) ;
@@ -41,42 +49,31 @@ describe('Client IVC Integration', () => {
41
49
// 1. Run a mock app that creates two commitments
42
50
// 2. Run the init kernel to process the app run
43
51
// 3. Run the tail kernel to finish the client IVC chain.
44
- it ( 'Should generate a verifiable client IVC proof from a simple mock tx via bb.js' , async ( ) => {
45
- const tx = {
46
- number_of_calls : '0x1' ,
47
- } ;
48
- // Witness gen app and kernels
49
- const appWitnessGenResult = await witnessGenCreatorAppMockCircuit ( { commitments_to_create : [ '0x1' , '0x2' ] } ) ;
50
- logger ( 'generated app mock circuit witness' ) ;
51
-
52
- const initWitnessGenResult = await witnessGenMockPrivateKernelInitCircuit ( {
53
- app_inputs : appWitnessGenResult . publicInputs ,
54
- tx,
55
- app_vk : getVkAsFields ( MockAppCreatorVk ) ,
56
- } ) ;
57
- logger ( 'generated mock private kernel init witness' ) ;
58
-
59
- const tailWitnessGenResult = await witnessGenMockPrivateKernelTailCircuit ( {
60
- prev_kernel_public_inputs : initWitnessGenResult . publicInputs ,
61
- kernel_vk : getVkAsFields ( MockPrivateKernelInitVk ) ,
62
- } ) ;
63
- logger ( 'generated mock private kernel tail witness' ) ;
64
-
65
- // Create client IVC proof
66
- const bytecodes = [
67
- MockAppCreatorCircuit . bytecode ,
68
- MockPrivateKernelInitCircuit . bytecode ,
69
- MockPrivateKernelTailCircuit . bytecode ,
52
+ it ( 'Should generate a verifiable client IVC proof from a simple mock tx via bb.js, verified by bb' , async ( ) => {
53
+ const [ bytecodes , witnessStack ] = await generate3FunctionTestingIVCStack ( ) ;
54
+
55
+ // We use the bb binary for verification / writing out the VK
56
+ const bbBinaryPath = path . join (
57
+ path . dirname ( fileURLToPath ( import . meta. url ) ) ,
58
+ '../../../barretenberg/cpp/build/bin' ,
59
+ 'bb' ,
60
+ ) ;
61
+ const clientIVCWorkingDirectory = await getWorkingDirectory ( 'bb-client-ivc-integration-' ) ;
62
+ const tasks = [
63
+ proveClientIVCNative ( bbBinaryPath , clientIVCWorkingDirectory , witnessStack , bytecodes , logger ) ,
64
+ proveClientIVCWasm ( bytecodes , witnessStack ) ,
70
65
] ;
71
-
72
- logger ( 'built bytecode array' ) ;
73
- const witnessStack = [ appWitnessGenResult . witness , initWitnessGenResult . witness , tailWitnessGenResult . witness ] ;
74
- logger ( 'built witness stack' ) ;
75
-
76
- const verifyResult = await proveThenVerifyAztecClient ( bytecodes , witnessStack ) ;
77
- logger ( `generated then verified proof. result: ${ verifyResult } ` ) ;
78
-
79
- expect ( verifyResult ) . toEqual ( true ) ;
66
+ const [ _ , wasmProof ] = await Promise . all ( tasks ) ;
67
+
68
+ // Write the WASM proof over the output directory (the bb cli will have output to this folder, we need the vk to be in place).
69
+ await writeClientIVCProofToOutputDirectory ( wasmProof , clientIVCWorkingDirectory ) ;
70
+ const verifyWasmResultInNative = await verifyClientIvcProof (
71
+ bbBinaryPath ,
72
+ clientIVCWorkingDirectory . concat ( '/proof' ) ,
73
+ clientIVCWorkingDirectory . concat ( '/vk' ) ,
74
+ logger . info ,
75
+ ) ;
76
+ expect ( verifyWasmResultInNative . status ) . toEqual ( BB_RESULT . SUCCESS ) ;
80
77
} ) ;
81
78
82
79
it ( 'Should generate an array of gate numbers for the stack of programs being proved by ClientIVC' , async ( ) => {
@@ -93,7 +90,7 @@ describe('Client IVC Integration', () => {
93
90
// Compute the numbers of gates in each circuit
94
91
const gateNumbers = await backend . gates ( ) ;
95
92
await backend . destroy ( ) ;
96
- logger ( 'Gate numbers for each circuit:' , gateNumbers ) ;
93
+ logger . info ( 'Gate numbers for each circuit:' , gateNumbers ) ;
97
94
// STARTER: add a test here instantiate an AztecClientBackend with the above bytecodes, call gates, and check they're correct (maybe just
98
95
// eyeball against logs to start... better is to make another test that actually pins the sizes since the mock protocol circuits are
99
96
// intended not to change, though for sure there will be some friction, and such test should actually just be located in barretenberg/ts)
@@ -160,7 +157,7 @@ describe('Client IVC Integration', () => {
160
157
] ;
161
158
162
159
const verifyResult = await proveThenVerifyAztecClient ( bytecodes , witnessStack ) ;
163
- logger ( `generated then verified proof. result: ${ verifyResult } ` ) ;
160
+ logger . info ( `generated then verified proof. result: ${ verifyResult } ` ) ;
164
161
165
162
expect ( verifyResult ) . toEqual ( true ) ;
166
163
} ) ;
0 commit comments