Skip to content

Commit 00d464a

Browse files
committed
Update recursive verification scripts and dependencies
- Modified `.gitignore` to include `store/` directory. - Updated `package.json` to change the `recursion` script to use `tsx` and added new dependencies for `@aztec/kv-store` and `@aztec/noir-contracts.js`. - Refined `README.md` to correct command for executing the circuit. - Enhanced `generate_data.ts` by removing unused imports and simplifying proof data handling. - Revamped `run_recursion.ts` to integrate a new sandbox setup and wallet deployment process, improving contract interaction. - Introduced `sponsored_fpc.ts` for managing Sponsored FPC instances and deployment logic.
1 parent b0e55bf commit 00d464a

File tree

7 files changed

+106
-52
lines changed

7 files changed

+106
-52
lines changed

recursive_verification/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
**/target/
33
**/codegenCache.json
4-
**/artifacts/
4+
**/artifacts/
5+
store/

recursive_verification/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ cd circuit && aztec-nargo compile
7676

7777
This compiles `circuit/src/main.nr` and generates `target/hello_circuit.json` containing the circuit bytecode.
7878

79-
### 2. Execute the Circuit (Optional)
79+
### 2. Execute the Circuit
8080

8181
```bash
82-
cd circuit && nargo execute
82+
cd circuit && aztec-nargo execute
8383
```
8484

8585
Generates a witness for testing the circuit with default inputs (defined in `circuit/Prover.toml`).

recursive_verification/bun.lockb

63.5 KB
Binary file not shown.

recursive_verification/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"cli": "bun run cli.ts",
77
"ccc": "cd contract && aztec-nargo compile && aztec-postprocess-contract && aztec codegen target -o artifacts",
88
"data": "bun run scripts/generate_data.ts",
9-
"recursion": "bun run scripts/run_recursion.ts",
9+
"recursion": "tsx scripts/run_recursion.ts",
1010
"test": "bun test",
1111
"test:watch": "bun test --watch"
1212
},
@@ -20,7 +20,11 @@
2020
"@aztec/accounts": "2.0.3",
2121
"@aztec/aztec.js": "2.0.3",
2222
"@aztec/bb.js": "2.0.3",
23+
"@aztec/kv-store": "^2.0.3",
24+
"@aztec/noir-contracts.js": "^2.0.3",
2325
"@aztec/noir-noir_js": "2.0.3",
24-
"add": "^2.0.6"
26+
"@aztec/pxe": "^2.0.3",
27+
"add": "^2.0.6",
28+
"tsx": "^4.20.6"
2529
}
2630
}

recursive_verification/scripts/generate_data.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Noir } from '@aztec/noir-noir_js';
22
import circuitJson from '../circuit/target/hello_circuit.json' with { type: "json" }
3-
import { Barretenberg, deflattenFields, RawBuffer, UltraHonkBackend, type ProofData } from '@aztec/bb.js';
3+
import { Barretenberg, deflattenFields, UltraHonkBackend } from '@aztec/bb.js';
44
import fs from 'fs'
55
import { exit } from 'process';
66

@@ -9,15 +9,15 @@ const helloWorld = new Noir(circuitJson as any)
99
const { witness: mainWitness } = await helloWorld.execute({ x: 1, y: 2 })
1010

1111
const mainBackend = new UltraHonkBackend(circuitJson.bytecode, { threads: 1 })
12-
const mainProofData: ProofData = await mainBackend.generateProof(mainWitness)
12+
const mainProofData = await mainBackend.generateProof(mainWitness)
1313
const mainVerificationKey = await mainBackend.getVerificationKey()
1414

1515
const isValid = await mainBackend.verifyProof(mainProofData)
1616
console.log(`Proof verification: ${isValid ? 'SUCCESS' : 'FAILED'}`)
1717

18-
const proofAsFields = deflattenFields(new RawBuffer(mainProofData.proof))
18+
const proofAsFields = deflattenFields(mainProofData.proof)
1919
const barretenbergAPI = await Barretenberg.new({ threads: 1 });
20-
const vkAsFields = (await barretenbergAPI.acirVkAsFieldsUltraHonk(new RawBuffer(mainVerificationKey)))
20+
const vkAsFields = (await barretenbergAPI.acirVkAsFieldsUltraHonk(mainVerificationKey))
2121
.map(field => field.toString());
2222

2323
fs.writeFileSync('data.json', JSON.stringify({ proofAsFields, vkAsFields, publicInputs: mainProofData.publicInputs }, null, 2))

recursive_verification/scripts/run_recursion.ts

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,75 @@
1-
import { AccountWalletWithSecretKey, Contract, createPXEClient, waitForPXE, type FieldLike, type PXE } from "@aztec/aztec.js"
2-
1+
import { AccountWalletWithSecretKey, Contract, createAztecNodeClient, Fq, Fr, SponsoredFeePaymentMethod, waitForPXE, type FieldLike, type PXE } from "@aztec/aztec.js"
2+
import { getSponsoredFPCInstance } from "./sponsored_fpc.js";
3+
import { SponsoredFPCContract } from "@aztec/noir-contracts.js/SponsoredFPC";
34
export const PXE_URL = 'http://localhost:8080'
4-
import { getInitialTestAccountsWallets } from '@aztec/accounts/testing'
55
import { ValueNotEqualContract, ValueNotEqualContractArtifact } from '../contract/artifacts/ValueNotEqual'
66
import data from '../data.json'
7+
import { createPXEService, getPXEServiceConfig } from "@aztec/pxe/server"
8+
import { createStore } from "@aztec/kv-store/lmdb"
9+
import { getSchnorrAccount } from "@aztec/accounts/schnorr"
710

8-
export const setupSandbox = async (): Promise<PXE> => {
9-
try {
10-
console.log(`Setting up sandbox with PXE URL: ${PXE_URL}`)
11-
const pxe = await createPXEClient(PXE_URL)
12-
await waitForPXE(pxe)
13-
console.log('PXE client created and connected successfully')
14-
return pxe
15-
} catch (error) {
16-
console.error('Failed to setup sandbox:', error)
17-
throw error
18-
}
19-
}
20-
export interface TestWallets {
21-
owner: AccountWalletWithSecretKey
22-
user1: AccountWalletWithSecretKey
23-
user2: AccountWalletWithSecretKey
24-
user3: AccountWalletWithSecretKey
25-
}
11+
const sponsoredFPC = await getSponsoredFPCInstance();
12+
const sponsoredPaymentMethod = new SponsoredFeePaymentMethod(sponsoredFPC.address);
2613

27-
export const setupWallets = async (pxe: PXE): Promise<TestWallets> => {
14+
export const setupSandbox = async (): Promise<PXE> => {
2815
try {
29-
console.log('Setting up test wallets')
30-
const wallets = await getInitialTestAccountsWallets(pxe)
31-
32-
const testWallets: TestWallets = {
33-
owner: wallets[0],
34-
user1: wallets[1],
35-
user2: wallets[2],
36-
//? Here wallet[3] is always coming wallets[0], so please keep this in mind
37-
user3: wallets[3] || wallets[0], // Fallback if not enough wallets
16+
const nodeUrl = 'http://localhost:8080';
17+
const node = await createAztecNodeClient(nodeUrl);
18+
19+
try {
20+
await node.getNodeInfo();
21+
} catch (error) {
22+
throw new Error(`Cannot connect to node at ${nodeUrl}. ${nodeUrl.includes('localhost') ? 'Please run: aztec start --sandbox' : 'Check your connection.'}`);
3823
}
3924

40-
console.log('Test wallets configured')
41-
console.info('Owner address:', testWallets.owner.getAddress().toString())
42-
console.info('User1 address:', testWallets.user1.getAddress().toString())
43-
console.info('User2 address:', testWallets.user2.getAddress().toString())
25+
const l1Contracts = await node.getL1ContractAddresses();
26+
const config = getPXEServiceConfig();
27+
const fullConfig = {
28+
...config,
29+
l1Contracts,
30+
proverEnabled: true
31+
};
32+
33+
const store = await createStore('recursive_verification', {
34+
dataDirectory: 'store',
35+
dataStoreMapSizeKB: 1e6,
36+
});
4437

45-
return testWallets
38+
const pxe = await createPXEService(node, fullConfig, { store });
39+
await waitForPXE(pxe);
40+
await pxe.registerContract({ instance: sponsoredFPC, artifact: SponsoredFPCContract.artifact });
41+
42+
return pxe;
4643
} catch (error) {
47-
console.error('Failed to setup wallets:', error)
44+
console.error('Failed to setup sandbox:', error)
4845
throw error
4946
}
5047
}
5148

49+
export async function deployWallet(pxe: PXE): Promise<AccountWalletWithSecretKey> {
50+
let secretKey = Fr.random();
51+
let signingKey = Fq.random();
52+
let salt = Fr.random();
53+
let schnorrAccount = await getSchnorrAccount(pxe, secretKey, signingKey, salt);
54+
let tx = await schnorrAccount.deploy({ fee: { paymentMethod: sponsoredPaymentMethod } }).wait({ timeout: 120000 });
55+
let wallet = await schnorrAccount.getWallet();
56+
return wallet
57+
}
58+
5259
async function main() {
5360
const pxe = await setupSandbox();
54-
const wallets = await setupWallets(pxe)
61+
const wallet = await deployWallet(pxe)
5562

56-
const valueNotEqual = await Contract.deploy(wallets.owner, ValueNotEqualContractArtifact, [
57-
10, wallets.owner.getAddress()
58-
], 'initialize').send({ from: wallets.owner.getAddress() }).deployed() as ValueNotEqualContract
63+
const valueNotEqual = await Contract.deploy(wallet, ValueNotEqualContractArtifact, [
64+
10, wallet.getAddress()
65+
], 'initialize').send({ from: wallet.getAddress(), fee: { paymentMethod: sponsoredPaymentMethod } }).deployed() as ValueNotEqualContract
5966

6067
console.log("Contract Deployed at address", valueNotEqual.address.toString())
6168

62-
const tx = await valueNotEqual.methods.increment(wallets.owner.getAddress(), data.vkAsFields as unknown as FieldLike[], data.proofAsFields as unknown as FieldLike[], data.publicInputs as unknown as FieldLike[]).send({ from: wallets.owner.getAddress() }).wait()
69+
const tx = await valueNotEqual.methods.increment(wallet.getAddress(), data.vkAsFields as unknown as FieldLike[], data.proofAsFields as unknown as FieldLike[], data.publicInputs as unknown as FieldLike[]).send({ from: wallet.getAddress(), fee: { paymentMethod: sponsoredPaymentMethod } }).wait()
6370

6471
console.log(`Tx hash: ${tx.txHash.toString()}`)
65-
const counterValue = await valueNotEqual.methods.get_counter(wallets.owner.getAddress()).simulate({ from: wallets.owner.getAddress() })
72+
const counterValue = await valueNotEqual.methods.get_counter(wallet.getAddress()).simulate({ from: wallet.getAddress() })
6673
console.log(`Counter value: ${counterValue}`)
6774
}
6875

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {
2+
type ContractInstanceWithAddress,
3+
Fr,
4+
type PXE,
5+
type Wallet,
6+
getContractInstanceFromInstantiationParams,
7+
} from '@aztec/aztec.js';
8+
import type { LogFn } from '@aztec/foundation/log';
9+
import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
10+
11+
const SPONSORED_FPC_SALT = new Fr(0);
12+
13+
export async function getSponsoredFPCInstance(): Promise<ContractInstanceWithAddress> {
14+
return await getContractInstanceFromInstantiationParams(SponsoredFPCContract.artifact, {
15+
salt: SPONSORED_FPC_SALT,
16+
});
17+
}
18+
19+
export async function getSponsoredFPCAddress() {
20+
return (await getSponsoredFPCInstance()).address;
21+
}
22+
23+
export async function setupSponsoredFPC(deployer: Wallet, log: LogFn) {
24+
const deployed = await SponsoredFPCContract.deploy(deployer)
25+
.send({
26+
from: deployer.getAddress(),
27+
contractAddressSalt: SPONSORED_FPC_SALT,
28+
universalDeploy: true,
29+
})
30+
.deployed();
31+
32+
log(`SponsoredFPC: ${deployed.address}`);
33+
}
34+
35+
export async function getDeployedSponsoredFPCAddress(pxe: PXE) {
36+
const fpc = await getSponsoredFPCAddress();
37+
const contracts = await pxe.getContracts();
38+
if (!contracts.find(c => c.equals(fpc))) {
39+
throw new Error('SponsoredFPC not deployed.');
40+
}
41+
return fpc;
42+
}

0 commit comments

Comments
 (0)