@aztec/end-to-end 0.82.2 → 0.82.3-nightly.20250403
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +66 -0
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
- package/dest/bench/client_flows/client_flows_benchmark.js +281 -0
- package/dest/bench/client_flows/config.d.ts +14 -0
- package/dest/bench/client_flows/config.d.ts.map +1 -0
- package/dest/bench/client_flows/config.js +85 -0
- package/dest/bench/client_flows/data_extractor.d.ts +23 -0
- package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
- package/dest/bench/client_flows/data_extractor.js +198 -0
- package/dest/bench/utils.d.ts +0 -12
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +2 -28
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +0 -12
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +1 -13
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +3 -14
- package/dest/e2e_p2p/p2p_network.d.ts +5 -0
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +13 -4
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +1 -0
- package/dest/fixtures/l1_to_l2_messaging.d.ts +2 -2
- package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
- package/dest/fixtures/l1_to_l2_messaging.js +2 -1
- package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
- package/dest/fixtures/setup_l1_contracts.js +1 -2
- package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
- package/dest/fixtures/snapshot_manager.js +7 -2
- package/dest/fixtures/token_utils.d.ts +2 -1
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +14 -1
- package/dest/fixtures/utils.d.ts +0 -4
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +216 -238
- package/dest/sample-dapp/contracts.js +4 -4
- package/dest/shared/capture_private_execution_steps.d.ts +2 -2
- package/dest/shared/capture_private_execution_steps.d.ts.map +1 -1
- package/dest/shared/capture_private_execution_steps.js +24 -6
- package/dest/shared/cross_chain_test_harness.d.ts +12 -1
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +14 -3
- package/dest/shared/uniswap_l1_l2.js +8 -6
- package/package.json +32 -32
- package/src/bench/client_flows/client_flows_benchmark.ts +395 -0
- package/src/bench/client_flows/config.ts +53 -0
- package/src/bench/client_flows/data_extractor.ts +217 -0
- package/src/bench/utils.ts +2 -30
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +1 -25
- package/src/e2e_fees/fees_test.ts +2 -15
- package/src/e2e_p2p/p2p_network.ts +10 -6
- package/src/e2e_p2p/shared.ts +1 -0
- package/src/fixtures/l1_to_l2_messaging.ts +12 -3
- package/src/fixtures/setup_l1_contracts.ts +1 -2
- package/src/fixtures/snapshot_manager.ts +7 -2
- package/src/fixtures/token_utils.ts +22 -2
- package/src/fixtures/utils.ts +235 -261
- package/src/sample-dapp/contracts.mjs +4 -4
- package/src/shared/capture_private_execution_steps.ts +43 -6
- package/src/shared/cross_chain_test_harness.ts +26 -2
- package/src/shared/uniswap_l1_l2.ts +8 -8
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { EcdsaRAccountContractArtifact, getEcdsaRAccount } from '@aztec/accounts/ecdsa';
|
|
2
|
+
import { SchnorrAccountContractArtifact, getSchnorrAccount, getSchnorrWallet } from '@aztec/accounts/schnorr';
|
|
3
|
+
import {
|
|
4
|
+
type AccountWallet,
|
|
5
|
+
AztecAddress,
|
|
6
|
+
type AztecNode,
|
|
7
|
+
FeeJuicePaymentMethodWithClaim,
|
|
8
|
+
type FeePaymentMethod,
|
|
9
|
+
type Logger,
|
|
10
|
+
type PXE,
|
|
11
|
+
PrivateFeePaymentMethod,
|
|
12
|
+
SponsoredFeePaymentMethod,
|
|
13
|
+
type Wallet,
|
|
14
|
+
createLogger,
|
|
15
|
+
} from '@aztec/aztec.js';
|
|
16
|
+
import { CheatCodes } from '@aztec/aztec.js/testing';
|
|
17
|
+
import { FEE_FUNDING_FOR_TESTER_ACCOUNT } from '@aztec/constants';
|
|
18
|
+
import { type DeployL1ContractsArgs, RollupContract, createL1Clients, deployL1Contract } from '@aztec/ethereum';
|
|
19
|
+
import { ChainMonitor } from '@aztec/ethereum/test';
|
|
20
|
+
import { randomBytes } from '@aztec/foundation/crypto';
|
|
21
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
22
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
23
|
+
import { TestERC20Abi } from '@aztec/l1-artifacts/TestERC20Abi';
|
|
24
|
+
import { TestERC20Bytecode } from '@aztec/l1-artifacts/TestERC20Bytecode';
|
|
25
|
+
import { AMMContract } from '@aztec/noir-contracts.js/AMM';
|
|
26
|
+
import { FPCContract } from '@aztec/noir-contracts.js/FPC';
|
|
27
|
+
import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice';
|
|
28
|
+
import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
|
|
29
|
+
import { TokenContract as BananaCoin, TokenContract } from '@aztec/noir-contracts.js/Token';
|
|
30
|
+
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
31
|
+
import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';
|
|
32
|
+
import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe/server';
|
|
33
|
+
import { deriveSigningKey } from '@aztec/stdlib/keys';
|
|
34
|
+
|
|
35
|
+
import { MNEMONIC } from '../../fixtures/fixtures.js';
|
|
36
|
+
import {
|
|
37
|
+
type ISnapshotManager,
|
|
38
|
+
type SubsystemsContext,
|
|
39
|
+
createSnapshotManager,
|
|
40
|
+
deployAccounts,
|
|
41
|
+
} from '../../fixtures/snapshot_manager.js';
|
|
42
|
+
import { mintTokensToPrivate } from '../../fixtures/token_utils.js';
|
|
43
|
+
import { type SetupOptions, setupSponsoredFPC } from '../../fixtures/utils.js';
|
|
44
|
+
import { CrossChainTestHarness } from '../../shared/cross_chain_test_harness.js';
|
|
45
|
+
import {
|
|
46
|
+
FeeJuicePortalTestingHarnessFactory,
|
|
47
|
+
type GasBridgingTestHarness,
|
|
48
|
+
} from '../../shared/gas_portal_test_harness.js';
|
|
49
|
+
import { type ClientFlowsConfig, FULL_FLOWS_CONFIG, KEY_FLOWS_CONFIG } from './config.js';
|
|
50
|
+
|
|
51
|
+
const { E2E_DATA_PATH: dataPath, BENCHMARK_CONFIG } = process.env;
|
|
52
|
+
|
|
53
|
+
export type AccountType = 'ecdsar1' | 'schnorr';
|
|
54
|
+
export type FeePaymentMethodGetter = (wallet: Wallet) => Promise<FeePaymentMethod>;
|
|
55
|
+
export type BenchmarkingFeePaymentMethod = 'bridged_fee_juice' | 'private_fpc' | 'sponsored_fpc';
|
|
56
|
+
|
|
57
|
+
export class ClientFlowsBenchmark {
|
|
58
|
+
private snapshotManager: ISnapshotManager;
|
|
59
|
+
|
|
60
|
+
public logger: Logger;
|
|
61
|
+
public pxe!: PXE;
|
|
62
|
+
public aztecNode!: AztecNode;
|
|
63
|
+
public cheatCodes!: CheatCodes;
|
|
64
|
+
public context!: SubsystemsContext;
|
|
65
|
+
public chainMonitor!: ChainMonitor;
|
|
66
|
+
public feeJuiceBridgeTestHarness!: GasBridgingTestHarness;
|
|
67
|
+
|
|
68
|
+
// The admin that aids in the setup of the test
|
|
69
|
+
public adminWallet!: AccountWallet;
|
|
70
|
+
public adminAddress!: AztecAddress;
|
|
71
|
+
|
|
72
|
+
// Aztec Node config
|
|
73
|
+
public sequencerAddress!: AztecAddress;
|
|
74
|
+
public coinbase!: EthAddress;
|
|
75
|
+
|
|
76
|
+
// Contracts
|
|
77
|
+
public feeJuiceContract!: FeeJuiceContract;
|
|
78
|
+
// Asset in which fees are paid via FPC
|
|
79
|
+
public bananaCoin!: BananaCoin;
|
|
80
|
+
public bananaFPC!: FPCContract;
|
|
81
|
+
// Random asset we want to trade
|
|
82
|
+
public candyBarCoin!: TokenContract;
|
|
83
|
+
// AMM contract
|
|
84
|
+
public amm!: AMMContract;
|
|
85
|
+
// Liquidity token for AMM
|
|
86
|
+
public liquidityToken!: TokenContract;
|
|
87
|
+
// Sponsored FPC contract
|
|
88
|
+
public sponsoredFPC!: SponsoredFPCContract;
|
|
89
|
+
|
|
90
|
+
// PXE used by the benchmarking user. It can be set up with client-side proving enabled
|
|
91
|
+
public userPXE!: PXE;
|
|
92
|
+
|
|
93
|
+
public paymentMethods: Record<BenchmarkingFeePaymentMethod, { forWallet: FeePaymentMethodGetter; circuits: number }> =
|
|
94
|
+
{
|
|
95
|
+
// eslint-disable-next-line camelcase
|
|
96
|
+
bridged_fee_juice: {
|
|
97
|
+
forWallet: this.getBridgedFeeJuicePaymentMethodForWallet.bind(this),
|
|
98
|
+
circuits: 2, // FeeJuice claim + kernel inner
|
|
99
|
+
},
|
|
100
|
+
// eslint-disable-next-line camelcase
|
|
101
|
+
private_fpc: {
|
|
102
|
+
forWallet: this.getPrivateFPCPaymentMethodForWallet.bind(this),
|
|
103
|
+
circuits:
|
|
104
|
+
2 + // FPC entrypoint + kernel inner
|
|
105
|
+
2 + // BananaCoin transfer_to_public + kernel inner
|
|
106
|
+
2 + // Account verify_private_authwit + kernel inner
|
|
107
|
+
2, // BananaCoin prepare_private_balance_increase + kernel inner
|
|
108
|
+
},
|
|
109
|
+
// eslint-disable-next-line camelcase
|
|
110
|
+
sponsored_fpc: {
|
|
111
|
+
forWallet: this.getSponsoredFPCPaymentMethodForWallet.bind(this),
|
|
112
|
+
circuits: 2, // Sponsored FPC sponsor_unconditionally + kernel inner
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
public config: ClientFlowsConfig;
|
|
117
|
+
|
|
118
|
+
constructor(testName?: string, setupOptions: Partial<SetupOptions & DeployL1ContractsArgs> = {}) {
|
|
119
|
+
this.logger = createLogger(`bench:client_flows${testName ? `:${testName}` : ''}`);
|
|
120
|
+
this.snapshotManager = createSnapshotManager(
|
|
121
|
+
`bench_client_flows${testName ? `/${testName}` : ''}`,
|
|
122
|
+
dataPath,
|
|
123
|
+
{ startProverNode: true, ...setupOptions },
|
|
124
|
+
{ ...setupOptions },
|
|
125
|
+
);
|
|
126
|
+
this.config = BENCHMARK_CONFIG === 'key_flows' ? KEY_FLOWS_CONFIG : FULL_FLOWS_CONFIG;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async setup() {
|
|
130
|
+
const context = await this.snapshotManager.setup();
|
|
131
|
+
await context.aztecNode.setConfig({ feeRecipient: this.sequencerAddress, coinbase: this.coinbase });
|
|
132
|
+
|
|
133
|
+
const rollupContract = RollupContract.getFromConfig(context.aztecNodeConfig);
|
|
134
|
+
this.chainMonitor = new ChainMonitor(rollupContract, this.logger, 200).start();
|
|
135
|
+
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async teardown() {
|
|
140
|
+
this.chainMonitor.stop();
|
|
141
|
+
await this.snapshotManager.teardown();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async mintAndBridgeFeeJuice(address: AztecAddress, amount: bigint) {
|
|
145
|
+
const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(amount, address);
|
|
146
|
+
const { claimSecret: secret, messageLeafIndex: index } = claim;
|
|
147
|
+
await this.feeJuiceContract.methods.claim(address, amount, secret, index).send().wait();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Admin mints bananaCoin tokens privately to the target address and redeems them. */
|
|
151
|
+
async mintPrivateBananas(amount: bigint, address: AztecAddress) {
|
|
152
|
+
const balanceBefore = await this.bananaCoin.methods.balance_of_private(address).simulate();
|
|
153
|
+
|
|
154
|
+
await mintTokensToPrivate(this.bananaCoin, this.adminWallet, address, amount);
|
|
155
|
+
|
|
156
|
+
const balanceAfter = await this.bananaCoin.methods.balance_of_private(address).simulate();
|
|
157
|
+
expect(balanceAfter).toEqual(balanceBefore + amount);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async createBenchmarkingAccountManager(type: 'ecdsar1' | 'schnorr') {
|
|
161
|
+
const benchysSecretKey = Fr.random();
|
|
162
|
+
const salt = Fr.random();
|
|
163
|
+
|
|
164
|
+
let benchysPrivateSigningKey;
|
|
165
|
+
let benchysAccountManager;
|
|
166
|
+
if (type === 'schnorr') {
|
|
167
|
+
benchysPrivateSigningKey = deriveSigningKey(benchysSecretKey);
|
|
168
|
+
benchysAccountManager = await getSchnorrAccount(this.userPXE, benchysSecretKey, benchysPrivateSigningKey, salt);
|
|
169
|
+
} else if (type === 'ecdsar1') {
|
|
170
|
+
benchysPrivateSigningKey = randomBytes(32);
|
|
171
|
+
benchysAccountManager = await getEcdsaRAccount(this.userPXE, benchysSecretKey, benchysPrivateSigningKey, salt);
|
|
172
|
+
} else {
|
|
173
|
+
throw new Error(`Unknown account type: ${type}`);
|
|
174
|
+
}
|
|
175
|
+
await benchysAccountManager.register();
|
|
176
|
+
return benchysAccountManager;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
public async applyBaseSnapshots() {
|
|
180
|
+
await this.applyInitialAccountsSnapshot();
|
|
181
|
+
await this.applySetupFeeJuiceSnapshot();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async applyInitialAccountsSnapshot() {
|
|
185
|
+
await this.snapshotManager.snapshot(
|
|
186
|
+
'initial_accounts',
|
|
187
|
+
deployAccounts(2, this.logger),
|
|
188
|
+
async ({ deployedAccounts }, { pxe, aztecNode, aztecNodeConfig }) => {
|
|
189
|
+
this.pxe = pxe;
|
|
190
|
+
|
|
191
|
+
this.aztecNode = aztecNode;
|
|
192
|
+
this.cheatCodes = await CheatCodes.create(aztecNodeConfig.l1RpcUrls, pxe);
|
|
193
|
+
|
|
194
|
+
const deployedWallets = await Promise.all(
|
|
195
|
+
deployedAccounts.map(a => getSchnorrWallet(pxe, a.address, a.signingKey)),
|
|
196
|
+
);
|
|
197
|
+
[this.adminWallet] = deployedWallets;
|
|
198
|
+
this.adminAddress = this.adminWallet.getAddress();
|
|
199
|
+
this.sequencerAddress = deployedWallets[1].getAddress();
|
|
200
|
+
|
|
201
|
+
const canonicalFeeJuice = await getCanonicalFeeJuice();
|
|
202
|
+
this.feeJuiceContract = await FeeJuiceContract.at(canonicalFeeJuice.address, this.adminWallet);
|
|
203
|
+
this.coinbase = EthAddress.random();
|
|
204
|
+
|
|
205
|
+
const userPXEConfig = getPXEServiceConfig();
|
|
206
|
+
const l1Contracts = await aztecNode.getL1ContractAddresses();
|
|
207
|
+
const userPXEConfigWithContracts = {
|
|
208
|
+
...userPXEConfig,
|
|
209
|
+
proverEnabled: ['true', '1'].includes(process.env.REAL_PROOFS ?? ''),
|
|
210
|
+
l1Contracts,
|
|
211
|
+
} as PXEServiceConfig;
|
|
212
|
+
|
|
213
|
+
this.userPXE = await createPXEService(this.aztecNode, userPXEConfigWithContracts, 'pxe-user');
|
|
214
|
+
},
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async applySetupFeeJuiceSnapshot() {
|
|
219
|
+
await this.snapshotManager.snapshot(
|
|
220
|
+
'setup_fee_juice',
|
|
221
|
+
async () => {},
|
|
222
|
+
async (_data, context) => {
|
|
223
|
+
this.context = context;
|
|
224
|
+
|
|
225
|
+
this.feeJuiceContract = await FeeJuiceContract.at(ProtocolContractAddress.FeeJuice, this.adminWallet);
|
|
226
|
+
|
|
227
|
+
this.feeJuiceBridgeTestHarness = await FeeJuicePortalTestingHarnessFactory.create({
|
|
228
|
+
aztecNode: context.aztecNode,
|
|
229
|
+
aztecNodeAdmin: context.aztecNode,
|
|
230
|
+
pxeService: context.pxe,
|
|
231
|
+
publicClient: context.deployL1ContractsValues.publicClient,
|
|
232
|
+
walletClient: context.deployL1ContractsValues.walletClient,
|
|
233
|
+
wallet: this.adminWallet,
|
|
234
|
+
logger: this.logger,
|
|
235
|
+
});
|
|
236
|
+
},
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async applyDeployBananaTokenSnapshot() {
|
|
241
|
+
await this.snapshotManager.snapshot(
|
|
242
|
+
'deploy_banana_token',
|
|
243
|
+
async () => {
|
|
244
|
+
const bananaCoin = await BananaCoin.deploy(this.adminWallet, this.adminAddress, 'BC', 'BC', 18n)
|
|
245
|
+
.send()
|
|
246
|
+
.deployed();
|
|
247
|
+
this.logger.info(`BananaCoin deployed at ${bananaCoin.address}`);
|
|
248
|
+
return { bananaCoinAddress: bananaCoin.address };
|
|
249
|
+
},
|
|
250
|
+
async ({ bananaCoinAddress }) => {
|
|
251
|
+
this.bananaCoin = await BananaCoin.at(bananaCoinAddress, this.adminWallet);
|
|
252
|
+
},
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async applyDeployCandyBarTokenSnapshot() {
|
|
257
|
+
await this.snapshotManager.snapshot(
|
|
258
|
+
'deploy_candy_bar_token',
|
|
259
|
+
async () => {
|
|
260
|
+
const candyBarCoin = await TokenContract.deploy(this.adminWallet, this.adminAddress, 'CBC', 'CBC', 18n)
|
|
261
|
+
.send()
|
|
262
|
+
.deployed();
|
|
263
|
+
this.logger.info(`CandyBarCoin deployed at ${candyBarCoin.address}`);
|
|
264
|
+
return { candyBarCoinAddress: candyBarCoin.address };
|
|
265
|
+
},
|
|
266
|
+
async ({ candyBarCoinAddress }) => {
|
|
267
|
+
this.candyBarCoin = await TokenContract.at(candyBarCoinAddress, this.adminWallet);
|
|
268
|
+
},
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
public async applyFPCSetupSnapshot() {
|
|
273
|
+
await this.snapshotManager.snapshot(
|
|
274
|
+
'fpc_setup',
|
|
275
|
+
async context => {
|
|
276
|
+
const feeJuiceContract = this.feeJuiceBridgeTestHarness.feeJuice;
|
|
277
|
+
expect((await context.pxe.getContractMetadata(feeJuiceContract.address)).isContractPubliclyDeployed).toBe(true);
|
|
278
|
+
|
|
279
|
+
const bananaCoin = this.bananaCoin;
|
|
280
|
+
const bananaFPC = await FPCContract.deploy(this.adminWallet, bananaCoin.address, this.adminAddress)
|
|
281
|
+
.send()
|
|
282
|
+
.deployed();
|
|
283
|
+
|
|
284
|
+
this.logger.info(`BananaPay deployed at ${bananaFPC.address}`);
|
|
285
|
+
|
|
286
|
+
await this.feeJuiceBridgeTestHarness.bridgeFromL1ToL2(FEE_FUNDING_FOR_TESTER_ACCOUNT, bananaFPC.address);
|
|
287
|
+
|
|
288
|
+
return { bananaFPCAddress: bananaFPC.address };
|
|
289
|
+
},
|
|
290
|
+
async data => {
|
|
291
|
+
this.bananaFPC = await FPCContract.at(data.bananaFPCAddress, this.adminWallet);
|
|
292
|
+
},
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async applyDeploySponsoredFPCSnapshot() {
|
|
297
|
+
await this.snapshotManager.snapshot(
|
|
298
|
+
'deploy_sponsored_fpc',
|
|
299
|
+
async () => {
|
|
300
|
+
const sponsoredFPC = await setupSponsoredFPC(this.pxe);
|
|
301
|
+
this.logger.info(`SponsoredFPC deployed at ${sponsoredFPC.address}`);
|
|
302
|
+
return { sponsoredFPCAddress: sponsoredFPC.address };
|
|
303
|
+
},
|
|
304
|
+
async ({ sponsoredFPCAddress }) => {
|
|
305
|
+
this.sponsoredFPC = await SponsoredFPCContract.at(sponsoredFPCAddress, this.adminWallet);
|
|
306
|
+
},
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
public async createCrossChainTestHarness(owner: AccountWallet) {
|
|
311
|
+
const { publicClient, walletClient } = createL1Clients(this.context.aztecNodeConfig.l1RpcUrls, MNEMONIC);
|
|
312
|
+
|
|
313
|
+
const underlyingERC20Address = await deployL1Contract(walletClient, publicClient, TestERC20Abi, TestERC20Bytecode, [
|
|
314
|
+
'Underlying',
|
|
315
|
+
'UND',
|
|
316
|
+
walletClient.account.address,
|
|
317
|
+
]).then(({ address }) => address);
|
|
318
|
+
|
|
319
|
+
this.logger.verbose(`Setting up cross chain harness...`);
|
|
320
|
+
const crossChainTestHarness = await CrossChainTestHarness.new(
|
|
321
|
+
this.aztecNode,
|
|
322
|
+
this.pxe,
|
|
323
|
+
publicClient,
|
|
324
|
+
walletClient,
|
|
325
|
+
owner,
|
|
326
|
+
this.logger,
|
|
327
|
+
underlyingERC20Address,
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
this.logger.verbose(`L2 token deployed to: ${crossChainTestHarness.l2Token.address}`);
|
|
331
|
+
|
|
332
|
+
return crossChainTestHarness;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
public async createAndFundBenchmarkingWallet(accountType: AccountType) {
|
|
336
|
+
const benchysAccountManager = await this.createBenchmarkingAccountManager(accountType);
|
|
337
|
+
const benchysWallet = await benchysAccountManager.getWallet();
|
|
338
|
+
const benchysAddress = benchysAccountManager.getAddress();
|
|
339
|
+
const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(
|
|
340
|
+
FEE_FUNDING_FOR_TESTER_ACCOUNT,
|
|
341
|
+
benchysAddress,
|
|
342
|
+
);
|
|
343
|
+
const paymentMethod = new FeeJuicePaymentMethodWithClaim(benchysWallet, claim);
|
|
344
|
+
await benchysAccountManager.deploy({ fee: { paymentMethod } }).wait();
|
|
345
|
+
// Register benchy on admin's PXE so we can check its balances
|
|
346
|
+
await this.pxe.registerContract({
|
|
347
|
+
instance: benchysAccountManager.getInstance(),
|
|
348
|
+
artifact: accountType === 'ecdsar1' ? EcdsaRAccountContractArtifact : SchnorrAccountContractArtifact,
|
|
349
|
+
});
|
|
350
|
+
await this.pxe.registerAccount(benchysWallet.getSecretKey(), benchysWallet.getCompleteAddress().partialAddress);
|
|
351
|
+
return benchysWallet;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
public async applyDeployAmmSnapshot() {
|
|
355
|
+
await this.snapshotManager.snapshot(
|
|
356
|
+
'deploy_amm',
|
|
357
|
+
async () => {
|
|
358
|
+
const liquidityToken = await TokenContract.deploy(this.adminWallet, this.adminAddress, 'LPT', 'LPT', 18n)
|
|
359
|
+
.send()
|
|
360
|
+
.deployed();
|
|
361
|
+
const amm = await AMMContract.deploy(
|
|
362
|
+
this.adminWallet,
|
|
363
|
+
this.bananaCoin.address,
|
|
364
|
+
this.candyBarCoin.address,
|
|
365
|
+
liquidityToken.address,
|
|
366
|
+
)
|
|
367
|
+
.send()
|
|
368
|
+
.deployed();
|
|
369
|
+
this.logger.info(`AMM deployed at ${amm.address}`);
|
|
370
|
+
await liquidityToken.methods.set_minter(amm.address, true).send().wait();
|
|
371
|
+
return { ammAddress: amm.address, liquidityTokenAddress: liquidityToken.address };
|
|
372
|
+
},
|
|
373
|
+
async ({ ammAddress, liquidityTokenAddress }) => {
|
|
374
|
+
this.liquidityToken = await TokenContract.at(liquidityTokenAddress, this.adminWallet);
|
|
375
|
+
this.amm = await AMMContract.at(ammAddress, this.adminWallet);
|
|
376
|
+
},
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
public async getBridgedFeeJuicePaymentMethodForWallet(wallet: Wallet) {
|
|
381
|
+
const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(
|
|
382
|
+
FEE_FUNDING_FOR_TESTER_ACCOUNT,
|
|
383
|
+
wallet.getAddress(),
|
|
384
|
+
);
|
|
385
|
+
return new FeeJuicePaymentMethodWithClaim(wallet, claim);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
public getPrivateFPCPaymentMethodForWallet(wallet: Wallet) {
|
|
389
|
+
return Promise.resolve(new PrivateFeePaymentMethod(this.bananaFPC.address, wallet));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
public getSponsoredFPCPaymentMethodForWallet(_wallet: Wallet) {
|
|
393
|
+
return Promise.resolve(new SponsoredFeePaymentMethod(this.sponsoredFPC.address));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AccountType, BenchmarkingFeePaymentMethod } from './client_flows_benchmark.js';
|
|
2
|
+
|
|
3
|
+
export type ClientFlowConfig = {
|
|
4
|
+
accounts: AccountType[];
|
|
5
|
+
feePaymentMethods: BenchmarkingFeePaymentMethod[];
|
|
6
|
+
recursions?: number[];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
type ClientFlows = 'deployments' | 'transfers' | 'bridging' | 'amm';
|
|
10
|
+
|
|
11
|
+
export type ClientFlowsConfig = {
|
|
12
|
+
[key in ClientFlows]: ClientFlowConfig;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const KEY_FLOWS_CONFIG: ClientFlowsConfig = {
|
|
16
|
+
deployments: {
|
|
17
|
+
accounts: ['ecdsar1', 'schnorr'],
|
|
18
|
+
feePaymentMethods: ['sponsored_fpc'],
|
|
19
|
+
},
|
|
20
|
+
amm: {
|
|
21
|
+
accounts: ['ecdsar1'],
|
|
22
|
+
feePaymentMethods: ['sponsored_fpc'],
|
|
23
|
+
},
|
|
24
|
+
bridging: {
|
|
25
|
+
accounts: ['ecdsar1'],
|
|
26
|
+
feePaymentMethods: ['sponsored_fpc'],
|
|
27
|
+
},
|
|
28
|
+
transfers: {
|
|
29
|
+
accounts: ['ecdsar1'],
|
|
30
|
+
feePaymentMethods: ['sponsored_fpc'],
|
|
31
|
+
recursions: [1],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const FULL_FLOWS_CONFIG: ClientFlowsConfig = {
|
|
36
|
+
deployments: {
|
|
37
|
+
accounts: ['ecdsar1', 'schnorr'],
|
|
38
|
+
feePaymentMethods: ['bridged_fee_juice', 'sponsored_fpc'],
|
|
39
|
+
},
|
|
40
|
+
amm: {
|
|
41
|
+
accounts: ['ecdsar1', 'schnorr'],
|
|
42
|
+
feePaymentMethods: ['sponsored_fpc', 'private_fpc'],
|
|
43
|
+
},
|
|
44
|
+
bridging: {
|
|
45
|
+
accounts: ['ecdsar1', 'schnorr'],
|
|
46
|
+
feePaymentMethods: ['sponsored_fpc', 'private_fpc'],
|
|
47
|
+
},
|
|
48
|
+
transfers: {
|
|
49
|
+
accounts: ['ecdsar1', 'schnorr'],
|
|
50
|
+
feePaymentMethods: ['sponsored_fpc', 'private_fpc'],
|
|
51
|
+
recursions: [0, 1, 2],
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import type { Logger } from '@aztec/aztec.js';
|
|
2
|
+
import { BBNativePrivateKernelProver } from '@aztec/bb-prover';
|
|
3
|
+
import { BBWASMBundlePrivateKernelProver } from '@aztec/bb-prover/wasm/bundle';
|
|
4
|
+
import { createLogger, logger } from '@aztec/foundation/log';
|
|
5
|
+
import { WASMSimulator } from '@aztec/simulator/client';
|
|
6
|
+
import type { PrivateExecutionStep } from '@aztec/stdlib/kernel';
|
|
7
|
+
|
|
8
|
+
import { decode } from '@msgpack/msgpack';
|
|
9
|
+
import assert from 'node:assert';
|
|
10
|
+
import { readFile, readdir, writeFile } from 'node:fs/promises';
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
|
|
13
|
+
const logLevel = ['silent', 'fatal', 'error', 'warn', 'info', 'verbose', 'debug', 'trace'] as const;
|
|
14
|
+
type LogLevel = (typeof logLevel)[number];
|
|
15
|
+
|
|
16
|
+
type Log = {
|
|
17
|
+
type: LogLevel;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
prefix: string;
|
|
20
|
+
message: string;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
data: any;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const GATE_TYPES = [
|
|
26
|
+
'ecc_op',
|
|
27
|
+
'busread',
|
|
28
|
+
'lookup',
|
|
29
|
+
'pub_inputs',
|
|
30
|
+
'arithmetic',
|
|
31
|
+
'delta_range',
|
|
32
|
+
'elliptic',
|
|
33
|
+
'aux',
|
|
34
|
+
'poseidon2_external',
|
|
35
|
+
'poseidon2_internal',
|
|
36
|
+
'overflow',
|
|
37
|
+
] as const;
|
|
38
|
+
|
|
39
|
+
type GateType = (typeof GATE_TYPES)[number];
|
|
40
|
+
|
|
41
|
+
type StructuredTrace = {
|
|
42
|
+
[k in GateType]: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export class ProxyLogger {
|
|
46
|
+
private static instance: ProxyLogger;
|
|
47
|
+
private logs: Log[] = [];
|
|
48
|
+
|
|
49
|
+
private constructor() {}
|
|
50
|
+
|
|
51
|
+
static create() {
|
|
52
|
+
ProxyLogger.instance = new ProxyLogger();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static getInstance() {
|
|
56
|
+
return ProxyLogger.instance;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
createLogger(prefix: string): Logger {
|
|
60
|
+
return new Proxy(createLogger(prefix), {
|
|
61
|
+
get: (target: Logger, prop: keyof Logger) => {
|
|
62
|
+
if (logLevel.includes(prop as (typeof logLevel)[number])) {
|
|
63
|
+
return function (this: Logger, ...data: Parameters<Logger[LogLevel]>) {
|
|
64
|
+
const loggingFn = prop as LogLevel;
|
|
65
|
+
const args = [loggingFn, prefix, ...data] as Parameters<ProxyLogger['handleLog']>;
|
|
66
|
+
ProxyLogger.getInstance().handleLog(...args);
|
|
67
|
+
target[loggingFn].call(this, ...[data[0], data[1]]);
|
|
68
|
+
};
|
|
69
|
+
} else {
|
|
70
|
+
return target[prop];
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private handleLog(type: (typeof logLevel)[number], prefix: string, message: string, data: any) {
|
|
77
|
+
this.logs.unshift({ type, prefix, message, data, timestamp: Date.now() });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public flushLogs() {
|
|
81
|
+
this.logs = [];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public getLogs() {
|
|
85
|
+
return this.logs;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type NativeProverConfig = { bbBinaryPath?: string; bbWorkingDirectory?: string };
|
|
90
|
+
|
|
91
|
+
type ProverType = 'wasm' | 'native';
|
|
92
|
+
|
|
93
|
+
type Step = { fnName: string; gateCount: number; accGateCount?: number };
|
|
94
|
+
|
|
95
|
+
async function createProver(config: NativeProverConfig = {}, log: Logger) {
|
|
96
|
+
const simulationProvider = new WASMSimulator();
|
|
97
|
+
if (!config.bbBinaryPath || !config.bbWorkingDirectory) {
|
|
98
|
+
return { prover: new BBWASMBundlePrivateKernelProver(simulationProvider, 16, log), type: 'wasm' as ProverType };
|
|
99
|
+
} else {
|
|
100
|
+
const bbConfig = config as Required<NativeProverConfig>;
|
|
101
|
+
return {
|
|
102
|
+
prover: await BBNativePrivateKernelProver.new({ bbSkipCleanup: false, ...bbConfig }, simulationProvider, log),
|
|
103
|
+
type: 'native' as ProverType,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getMinimumTrace(logs: Log[], proverType: ProverType): StructuredTrace {
|
|
109
|
+
const minimumMessage = 'Minimum required block sizes for structured trace:';
|
|
110
|
+
const minimumMessageIndex = logs.findIndex(log => log.message.includes(minimumMessage));
|
|
111
|
+
const candidateLogs = logs.slice(minimumMessageIndex - GATE_TYPES.length, minimumMessageIndex);
|
|
112
|
+
const traceLogs =
|
|
113
|
+
proverType === 'wasm'
|
|
114
|
+
? candidateLogs.map(log => log.message)
|
|
115
|
+
: logs
|
|
116
|
+
.slice(minimumMessageIndex - GATE_TYPES.length, minimumMessageIndex)
|
|
117
|
+
.filter(log => GATE_TYPES.some(type => log.message.includes(`bb - ${type}`)))
|
|
118
|
+
.map(log => log.message.split('\n'))
|
|
119
|
+
.flat();
|
|
120
|
+
const traceSizes = traceLogs.map(log => {
|
|
121
|
+
const [gateType, gateSizeStr] = log
|
|
122
|
+
.replace(/\n.*\)$/, '')
|
|
123
|
+
.replace(/bb - /, '')
|
|
124
|
+
.split(':')
|
|
125
|
+
.map(s => s.trim());
|
|
126
|
+
const gateSize = parseInt(gateSizeStr);
|
|
127
|
+
assert(GATE_TYPES.includes(gateType as GateType), `Gate type ${gateType} is not recognized`);
|
|
128
|
+
return { [gateType]: gateSize };
|
|
129
|
+
});
|
|
130
|
+
assert(traceSizes.length === GATE_TYPES.length, 'Decoded trace sizes do not match expected amount of gate types');
|
|
131
|
+
return traceSizes.reduce((acc, curr) => ({ ...acc, ...curr }), {}) as StructuredTrace;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function main() {
|
|
135
|
+
ProxyLogger.create();
|
|
136
|
+
const proxyLogger = ProxyLogger.getInstance();
|
|
137
|
+
const ivcFolder = process.env.CAPTURE_IVC_FOLDER;
|
|
138
|
+
if (!ivcFolder) {
|
|
139
|
+
throw new Error('CAPTURE_IVC_FOLDER is not set');
|
|
140
|
+
}
|
|
141
|
+
const flows = await readdir(ivcFolder);
|
|
142
|
+
logger.info(`Flows in ${ivcFolder}: \n${flows.map(flowName => `\t- ${flowName}`).join('\n')}`);
|
|
143
|
+
const { prover, type: proverType } = await createProver(
|
|
144
|
+
{ bbBinaryPath: process.env.BB_BINARY_PATH, bbWorkingDirectory: process.env.BB_WORKING_DIRECTORY },
|
|
145
|
+
proxyLogger.createLogger('bb:prover'),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const userLog = createLogger('client_ivc_flows:data_processor');
|
|
149
|
+
|
|
150
|
+
for (const flow of flows) {
|
|
151
|
+
userLog.info(`Processing flow ${flow}`);
|
|
152
|
+
const bytecode = await readFile(join(ivcFolder, flow, 'acir.msgpack'));
|
|
153
|
+
const acirStack = decode(bytecode) as Buffer[];
|
|
154
|
+
const witnesses = await readFile(join(ivcFolder, flow, 'witnesses.json'));
|
|
155
|
+
const witnessStack = JSON.parse(witnesses.toString()).map((witnessMap: Record<string, string>) => {
|
|
156
|
+
return new Map<number, string>(Object.entries(witnessMap).map(([k, v]) => [Number(k), v]));
|
|
157
|
+
});
|
|
158
|
+
const stepsFile = await readFile(join(ivcFolder, flow, 'steps.json'));
|
|
159
|
+
const executionSteps = JSON.parse(stepsFile.toString()) as { fnName: string; gateCount: number }[];
|
|
160
|
+
const privateExecutionSteps: PrivateExecutionStep[] = executionSteps.map((step, i) => ({
|
|
161
|
+
functionName: step.fnName,
|
|
162
|
+
gateCount: step.gateCount,
|
|
163
|
+
bytecode: acirStack[i],
|
|
164
|
+
witness: witnessStack[i],
|
|
165
|
+
}));
|
|
166
|
+
let stats: { duration: number; eventName: string; proofSize: number } | undefined;
|
|
167
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
|
+
let error: any | undefined;
|
|
169
|
+
let currentLogs: Log[] = [];
|
|
170
|
+
try {
|
|
171
|
+
await prover.createClientIvcProof(privateExecutionSteps);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
userLog.error(`Failed to generate client ivc proof for ${flow}`, e);
|
|
174
|
+
error = (e as Error).message;
|
|
175
|
+
}
|
|
176
|
+
// Extract logs from this run from the proxy and write them to disk unconditionally
|
|
177
|
+
currentLogs = proxyLogger.getLogs();
|
|
178
|
+
await writeFile(join(ivcFolder, flow, 'logs.json'), JSON.stringify(currentLogs, null, 2));
|
|
179
|
+
|
|
180
|
+
if (!error) {
|
|
181
|
+
stats = currentLogs[0].data as { duration: number; eventName: string; proofSize: number };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const minimumTrace = getMinimumTrace(currentLogs, proverType);
|
|
185
|
+
|
|
186
|
+
const steps = executionSteps.reduce<Step[]>((acc, step, i) => {
|
|
187
|
+
const previousAccGateCount = i === 0 ? 0 : acc[i - 1].accGateCount!;
|
|
188
|
+
return [
|
|
189
|
+
...acc,
|
|
190
|
+
{
|
|
191
|
+
fnName: step.fnName,
|
|
192
|
+
gateCount: step.gateCount,
|
|
193
|
+
accGateCount: previousAccGateCount + step.gateCount,
|
|
194
|
+
},
|
|
195
|
+
];
|
|
196
|
+
}, []);
|
|
197
|
+
const totalGateCount = steps[steps.length - 1].accGateCount;
|
|
198
|
+
const benchmark = {
|
|
199
|
+
proverType,
|
|
200
|
+
minimumTrace: minimumTrace,
|
|
201
|
+
totalGateCount,
|
|
202
|
+
stats,
|
|
203
|
+
steps,
|
|
204
|
+
error,
|
|
205
|
+
};
|
|
206
|
+
await writeFile(join(ivcFolder, flow, 'benchmark.json'), JSON.stringify(benchmark, null, 2));
|
|
207
|
+
proxyLogger.flushLogs();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
try {
|
|
212
|
+
await main();
|
|
213
|
+
} catch (e) {
|
|
214
|
+
// eslint-disable-next-line no-console
|
|
215
|
+
console.error(e);
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|