@aztec/end-to-end 0.0.0-test.1 → 0.0.1-fake-c83136db25

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.
Files changed (166) hide show
  1. package/dest/bench/client_flows/benchmark.d.ts +61 -0
  2. package/dest/bench/client_flows/benchmark.d.ts.map +1 -0
  3. package/dest/bench/client_flows/benchmark.js +261 -0
  4. package/dest/bench/client_flows/client_flows_benchmark.d.ts +73 -0
  5. package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -0
  6. package/dest/bench/client_flows/client_flows_benchmark.js +311 -0
  7. package/dest/bench/client_flows/config.d.ts +14 -0
  8. package/dest/bench/client_flows/config.d.ts.map +1 -0
  9. package/dest/bench/client_flows/config.js +106 -0
  10. package/dest/bench/client_flows/data_extractor.d.ts +2 -0
  11. package/dest/bench/client_flows/data_extractor.d.ts.map +1 -0
  12. package/dest/bench/client_flows/data_extractor.js +99 -0
  13. package/dest/bench/utils.d.ts +10 -36
  14. package/dest/bench/utils.d.ts.map +1 -1
  15. package/dest/bench/utils.js +26 -66
  16. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +20 -12
  17. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
  18. package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +85 -57
  19. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +18 -24
  20. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
  21. package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +48 -69
  22. package/dest/e2e_deploy_contract/deploy_test.d.ts +14 -6
  23. package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
  24. package/dest/e2e_deploy_contract/deploy_test.js +13 -19
  25. package/dest/e2e_epochs/epochs_test.d.ts +58 -17
  26. package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
  27. package/dest/e2e_epochs/epochs_test.js +224 -43
  28. package/dest/e2e_fees/bridging_race.notest.d.ts +2 -0
  29. package/dest/e2e_fees/bridging_race.notest.d.ts.map +1 -0
  30. package/dest/e2e_fees/bridging_race.notest.js +63 -0
  31. package/dest/e2e_fees/fees_test.d.ts +20 -9
  32. package/dest/e2e_fees/fees_test.d.ts.map +1 -1
  33. package/dest/e2e_fees/fees_test.js +98 -107
  34. package/dest/e2e_l1_publisher/write_json.d.ts +10 -0
  35. package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -0
  36. package/dest/e2e_l1_publisher/write_json.js +57 -0
  37. package/dest/e2e_multi_validator/utils.d.ts +12 -0
  38. package/dest/e2e_multi_validator/utils.d.ts.map +1 -0
  39. package/dest/e2e_multi_validator/utils.js +214 -0
  40. package/dest/e2e_nested_contract/nested_contract_test.d.ts +9 -6
  41. package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
  42. package/dest/e2e_nested_contract/nested_contract_test.js +22 -19
  43. package/dest/e2e_p2p/inactivity_slash_test.d.ts +31 -0
  44. package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -0
  45. package/dest/e2e_p2p/inactivity_slash_test.js +135 -0
  46. package/dest/e2e_p2p/p2p_network.d.ts +69 -22
  47. package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
  48. package/dest/e2e_p2p/p2p_network.js +180 -129
  49. package/dest/e2e_p2p/shared.d.ts +41 -5
  50. package/dest/e2e_p2p/shared.d.ts.map +1 -1
  51. package/dest/e2e_p2p/shared.js +163 -19
  52. package/dest/e2e_token_contract/token_contract_test.d.ts +11 -5
  53. package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
  54. package/dest/e2e_token_contract/token_contract_test.js +50 -26
  55. package/dest/{e2e_prover → fixtures}/e2e_prover_test.d.ts +14 -9
  56. package/dest/fixtures/e2e_prover_test.d.ts.map +1 -0
  57. package/dest/{e2e_prover → fixtures}/e2e_prover_test.js +95 -100
  58. package/dest/fixtures/fixtures.d.ts +5 -6
  59. package/dest/fixtures/fixtures.d.ts.map +1 -1
  60. package/dest/fixtures/fixtures.js +4 -3
  61. package/dest/fixtures/get_acvm_config.d.ts +1 -1
  62. package/dest/fixtures/get_acvm_config.d.ts.map +1 -1
  63. package/dest/fixtures/get_acvm_config.js +2 -14
  64. package/dest/fixtures/get_bb_config.d.ts +1 -1
  65. package/dest/fixtures/get_bb_config.d.ts.map +1 -1
  66. package/dest/fixtures/get_bb_config.js +10 -17
  67. package/dest/fixtures/l1_to_l2_messaging.d.ts +8 -5
  68. package/dest/fixtures/l1_to_l2_messaging.d.ts.map +1 -1
  69. package/dest/fixtures/l1_to_l2_messaging.js +44 -18
  70. package/dest/fixtures/setup_l1_contracts.d.ts +3 -3
  71. package/dest/fixtures/setup_l1_contracts.d.ts.map +1 -1
  72. package/dest/fixtures/setup_l1_contracts.js +4 -4
  73. package/dest/fixtures/setup_p2p_test.d.ts +14 -13
  74. package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
  75. package/dest/fixtures/setup_p2p_test.js +73 -21
  76. package/dest/fixtures/snapshot_manager.d.ts +15 -7
  77. package/dest/fixtures/snapshot_manager.d.ts.map +1 -1
  78. package/dest/fixtures/snapshot_manager.js +147 -121
  79. package/dest/fixtures/token_utils.d.ts +6 -3
  80. package/dest/fixtures/token_utils.d.ts.map +1 -1
  81. package/dest/fixtures/token_utils.js +23 -10
  82. package/dest/fixtures/utils.d.ts +76 -37
  83. package/dest/fixtures/utils.d.ts.map +1 -1
  84. package/dest/fixtures/utils.js +464 -368
  85. package/dest/fixtures/web3signer.d.ts +5 -0
  86. package/dest/fixtures/web3signer.d.ts.map +1 -0
  87. package/dest/fixtures/web3signer.js +53 -0
  88. package/dest/quality_of_service/alert_checker.d.ts +1 -1
  89. package/dest/quality_of_service/alert_checker.d.ts.map +1 -1
  90. package/dest/shared/cross_chain_test_harness.d.ts +41 -25
  91. package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
  92. package/dest/shared/cross_chain_test_harness.js +104 -50
  93. package/dest/shared/gas_portal_test_harness.d.ts +32 -24
  94. package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
  95. package/dest/shared/gas_portal_test_harness.js +50 -29
  96. package/dest/shared/jest_setup.js +1 -1
  97. package/dest/shared/submit-transactions.d.ts +5 -3
  98. package/dest/shared/submit-transactions.d.ts.map +1 -1
  99. package/dest/shared/submit-transactions.js +8 -7
  100. package/dest/shared/uniswap_l1_l2.d.ts +13 -11
  101. package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
  102. package/dest/shared/uniswap_l1_l2.js +138 -108
  103. package/dest/simulators/lending_simulator.d.ts +6 -6
  104. package/dest/simulators/lending_simulator.d.ts.map +1 -1
  105. package/dest/simulators/lending_simulator.js +13 -16
  106. package/dest/simulators/token_simulator.d.ts +5 -2
  107. package/dest/simulators/token_simulator.d.ts.map +1 -1
  108. package/dest/simulators/token_simulator.js +16 -13
  109. package/dest/spartan/setup_test_wallets.d.ts +23 -10
  110. package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
  111. package/dest/spartan/setup_test_wallets.js +167 -58
  112. package/dest/spartan/utils.d.ts +100 -303
  113. package/dest/spartan/utils.d.ts.map +1 -1
  114. package/dest/spartan/utils.js +407 -130
  115. package/package.json +61 -56
  116. package/src/bench/client_flows/benchmark.ts +341 -0
  117. package/src/bench/client_flows/client_flows_benchmark.ts +402 -0
  118. package/src/bench/client_flows/config.ts +61 -0
  119. package/src/bench/client_flows/data_extractor.ts +111 -0
  120. package/src/bench/utils.ts +22 -76
  121. package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +80 -77
  122. package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +63 -105
  123. package/src/e2e_deploy_contract/deploy_test.ts +23 -38
  124. package/src/e2e_epochs/epochs_test.ts +274 -54
  125. package/src/e2e_fees/bridging_race.notest.ts +80 -0
  126. package/src/e2e_fees/fees_test.ts +137 -136
  127. package/src/e2e_l1_publisher/write_json.ts +76 -0
  128. package/src/e2e_multi_validator/utils.ts +258 -0
  129. package/src/e2e_nested_contract/nested_contract_test.ts +27 -18
  130. package/src/e2e_p2p/inactivity_slash_test.ts +178 -0
  131. package/src/e2e_p2p/p2p_network.ts +272 -166
  132. package/src/e2e_p2p/shared.ts +244 -29
  133. package/src/e2e_token_contract/token_contract_test.ts +43 -39
  134. package/src/fixtures/dumps/epoch_proof_result.json +1 -1
  135. package/src/{e2e_prover → fixtures}/e2e_prover_test.ts +101 -145
  136. package/src/fixtures/fixtures.ts +4 -3
  137. package/src/fixtures/get_acvm_config.ts +3 -11
  138. package/src/fixtures/get_bb_config.ts +18 -13
  139. package/src/fixtures/l1_to_l2_messaging.ts +53 -23
  140. package/src/fixtures/setup_l1_contracts.ts +6 -7
  141. package/src/fixtures/setup_p2p_test.ts +112 -38
  142. package/src/fixtures/snapshot_manager.ts +187 -139
  143. package/src/fixtures/token_utils.ts +29 -12
  144. package/src/fixtures/utils.ts +552 -425
  145. package/src/fixtures/web3signer.ts +63 -0
  146. package/src/guides/up_quick_start.sh +6 -14
  147. package/src/quality_of_service/alert_checker.ts +1 -1
  148. package/src/shared/cross_chain_test_harness.ts +108 -79
  149. package/src/shared/gas_portal_test_harness.ts +58 -49
  150. package/src/shared/jest_setup.ts +1 -1
  151. package/src/shared/submit-transactions.ts +12 -8
  152. package/src/shared/uniswap_l1_l2.ts +173 -176
  153. package/src/simulators/lending_simulator.ts +12 -15
  154. package/src/simulators/token_simulator.ts +21 -13
  155. package/src/spartan/DEVELOP.md +121 -0
  156. package/src/spartan/setup_test_wallets.ts +215 -93
  157. package/src/spartan/utils.ts +458 -130
  158. package/dest/e2e_prover/e2e_prover_test.d.ts.map +0 -1
  159. package/dest/sample-dapp/connect.js +0 -12
  160. package/dest/sample-dapp/contracts.js +0 -10
  161. package/dest/sample-dapp/deploy.js +0 -35
  162. package/dest/sample-dapp/index.js +0 -98
  163. package/src/sample-dapp/connect.mjs +0 -16
  164. package/src/sample-dapp/contracts.mjs +0 -14
  165. package/src/sample-dapp/deploy.mjs +0 -40
  166. package/src/sample-dapp/index.mjs +0 -128
@@ -0,0 +1,402 @@
1
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
+ import { FeeJuicePaymentMethodWithClaim } from '@aztec/aztec.js/fee';
3
+ import { type FeePaymentMethod, PrivateFeePaymentMethod, SponsoredFeePaymentMethod } from '@aztec/aztec.js/fee';
4
+ import { type Logger, createLogger } from '@aztec/aztec.js/log';
5
+ import type { AztecNode } from '@aztec/aztec.js/node';
6
+ import type { Wallet } from '@aztec/aztec.js/wallet';
7
+ import { CheatCodes } from '@aztec/aztec/testing';
8
+ import { type DeployL1ContractsArgs, RollupContract, createExtendedL1Client, deployL1Contract } from '@aztec/ethereum';
9
+ import { ChainMonitor } from '@aztec/ethereum/test';
10
+ import { randomBytes } from '@aztec/foundation/crypto';
11
+ import { EthAddress } from '@aztec/foundation/eth-address';
12
+ import { Fr } from '@aztec/foundation/fields';
13
+ import { TestERC20Abi } from '@aztec/l1-artifacts/TestERC20Abi';
14
+ import { TestERC20Bytecode } from '@aztec/l1-artifacts/TestERC20Bytecode';
15
+ import { AMMContract } from '@aztec/noir-contracts.js/AMM';
16
+ import { FPCContract } from '@aztec/noir-contracts.js/FPC';
17
+ import { FeeJuiceContract } from '@aztec/noir-contracts.js/FeeJuice';
18
+ import { SponsoredFPCContract } from '@aztec/noir-contracts.js/SponsoredFPC';
19
+ import { TokenContract as BananaCoin, TokenContract } from '@aztec/noir-contracts.js/Token';
20
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
21
+ import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';
22
+ import { type PXEConfig, getPXEConfig } from '@aztec/pxe/server';
23
+ import { GasSettings } from '@aztec/stdlib/gas';
24
+ import { deriveSigningKey } from '@aztec/stdlib/keys';
25
+ import { TestWallet } from '@aztec/test-wallet/server';
26
+
27
+ import { MNEMONIC } from '../../fixtures/fixtures.js';
28
+ import {
29
+ type ISnapshotManager,
30
+ type SubsystemsContext,
31
+ createSnapshotManager,
32
+ deployAccounts,
33
+ } from '../../fixtures/snapshot_manager.js';
34
+ import { mintTokensToPrivate } from '../../fixtures/token_utils.js';
35
+ import { type SetupOptions, setupSponsoredFPC } from '../../fixtures/utils.js';
36
+ import { CrossChainTestHarness } from '../../shared/cross_chain_test_harness.js';
37
+ import {
38
+ FeeJuicePortalTestingHarnessFactory,
39
+ type GasBridgingTestHarness,
40
+ } from '../../shared/gas_portal_test_harness.js';
41
+ import { ProxyLogger } from './benchmark.js';
42
+ import { type ClientFlowsConfig, FULL_FLOWS_CONFIG, KEY_FLOWS_CONFIG } from './config.js';
43
+
44
+ const { E2E_DATA_PATH: dataPath, BENCHMARK_CONFIG } = process.env;
45
+
46
+ export type AccountType = 'ecdsar1' | 'schnorr';
47
+ export type FeePaymentMethodGetter = (wallet: Wallet, sender: AztecAddress) => Promise<FeePaymentMethod | undefined>;
48
+ export type BenchmarkingFeePaymentMethod = 'bridged_fee_juice' | 'private_fpc' | 'sponsored_fpc' | 'fee_juice';
49
+
50
+ export class ClientFlowsBenchmark {
51
+ private snapshotManager: ISnapshotManager;
52
+
53
+ public logger: Logger;
54
+ public aztecNode!: AztecNode;
55
+ public cheatCodes!: CheatCodes;
56
+ public context!: SubsystemsContext;
57
+ public chainMonitor!: ChainMonitor;
58
+ public feeJuiceBridgeTestHarness!: GasBridgingTestHarness;
59
+ public adminWallet!: TestWallet;
60
+
61
+ // The admin that aids in the setup of the test
62
+ public adminAddress!: AztecAddress;
63
+
64
+ // Aztec Node config
65
+ public sequencerAddress!: AztecAddress;
66
+ public coinbase!: EthAddress;
67
+
68
+ // Contracts
69
+ public feeJuiceContract!: FeeJuiceContract;
70
+ // Asset in which fees are paid via FPC
71
+ public bananaCoin!: BananaCoin;
72
+ public bananaFPC!: FPCContract;
73
+ // Random asset we want to trade
74
+ public candyBarCoin!: TokenContract;
75
+ // AMM contract
76
+ public amm!: AMMContract;
77
+ // Liquidity token for AMM
78
+ public liquidityToken!: TokenContract;
79
+ // Sponsored FPC contract
80
+ public sponsoredFPC!: SponsoredFPCContract;
81
+
82
+ // PXE and Wallet used by the benchmarking user. It can be set up with client-side proving enabled
83
+ public userWallet!: TestWallet;
84
+
85
+ public realProofs = ['true', '1'].includes(process.env.REAL_PROOFS ?? '');
86
+
87
+ public paymentMethods: Record<BenchmarkingFeePaymentMethod, { forWallet: FeePaymentMethodGetter; circuits: number }> =
88
+ {
89
+ // eslint-disable-next-line camelcase
90
+ bridged_fee_juice: {
91
+ forWallet: this.getBridgedFeeJuicePaymentMethodForWallet.bind(this),
92
+ circuits: 2, // FeeJuice claim + kernel inner
93
+ },
94
+ // eslint-disable-next-line camelcase
95
+ private_fpc: {
96
+ forWallet: this.getPrivateFPCPaymentMethodForWallet.bind(this),
97
+ circuits:
98
+ 2 + // FPC entrypoint + kernel inner
99
+ 2 + // BananaCoin transfer_to_public + kernel inner
100
+ 2 + // Account verify_private_authwit + kernel inner
101
+ 2, // BananaCoin prepare_private_balance_increase + kernel inner
102
+ },
103
+ // eslint-disable-next-line camelcase
104
+ sponsored_fpc: {
105
+ forWallet: this.getSponsoredFPCPaymentMethodForWallet.bind(this),
106
+ circuits: 2, // Sponsored FPC sponsor_unconditionally + kernel inner
107
+ },
108
+ // eslint-disable-next-line camelcase
109
+ fee_juice: {
110
+ forWallet: () => Promise.resolve(undefined),
111
+ circuits: 0,
112
+ },
113
+ };
114
+
115
+ public config: ClientFlowsConfig;
116
+
117
+ private proxyLogger: ProxyLogger;
118
+
119
+ constructor(testName?: string, setupOptions: Partial<SetupOptions & DeployL1ContractsArgs> = {}) {
120
+ this.logger = createLogger(`bench:client_flows${testName ? `:${testName}` : ''}`);
121
+ this.snapshotManager = createSnapshotManager(
122
+ `bench_client_flows${testName ? `/${testName}` : ''}`,
123
+ dataPath,
124
+ { startProverNode: true, ...setupOptions },
125
+ { ...setupOptions },
126
+ );
127
+ this.config = BENCHMARK_CONFIG === 'key_flows' ? KEY_FLOWS_CONFIG : FULL_FLOWS_CONFIG;
128
+ ProxyLogger.create();
129
+ this.proxyLogger = ProxyLogger.getInstance();
130
+ }
131
+
132
+ async setup() {
133
+ const context = await this.snapshotManager.setup();
134
+ await context.aztecNode.setConfig({ feeRecipient: this.sequencerAddress, coinbase: this.coinbase });
135
+
136
+ const rollupContract = RollupContract.getFromConfig(context.aztecNodeConfig);
137
+ this.chainMonitor = new ChainMonitor(rollupContract, context.dateProvider, this.logger, 200).start();
138
+
139
+ return this;
140
+ }
141
+
142
+ async teardown() {
143
+ await this.chainMonitor.stop();
144
+ await this.snapshotManager.teardown();
145
+ }
146
+
147
+ async mintAndBridgeFeeJuice(address: AztecAddress) {
148
+ const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(address);
149
+ const { claimSecret: secret, messageLeafIndex: index } = claim;
150
+ await this.feeJuiceContract.methods
151
+ .claim(address, claim.claimAmount, secret, index)
152
+ .send({ from: this.adminAddress })
153
+ .wait();
154
+ }
155
+
156
+ /** Admin mints bananaCoin tokens privately to the target address and redeems them. */
157
+ async mintPrivateBananas(amount: bigint, address: AztecAddress) {
158
+ const balanceBefore = await this.bananaCoin.methods
159
+ .balance_of_private(address)
160
+ .simulate({ from: this.adminAddress });
161
+
162
+ await mintTokensToPrivate(this.bananaCoin, this.adminAddress, address, amount);
163
+
164
+ const balanceAfter = await this.bananaCoin.methods
165
+ .balance_of_private(address)
166
+ .simulate({ from: this.adminAddress });
167
+ expect(balanceAfter).toEqual(balanceBefore + amount);
168
+ }
169
+
170
+ createBenchmarkingAccountManager(wallet: TestWallet, type: 'ecdsar1' | 'schnorr') {
171
+ const benchysSecret = Fr.random();
172
+ const salt = Fr.random();
173
+
174
+ let benchysPrivateSigningKey;
175
+ if (type === 'schnorr') {
176
+ benchysPrivateSigningKey = deriveSigningKey(benchysSecret);
177
+ return wallet.createSchnorrAccount(benchysSecret, salt, benchysPrivateSigningKey);
178
+ } else if (type === 'ecdsar1') {
179
+ benchysPrivateSigningKey = randomBytes(32);
180
+ return wallet.createECDSARAccount(benchysSecret, salt, benchysPrivateSigningKey);
181
+ } else {
182
+ throw new Error(`Unknown account type: ${type}`);
183
+ }
184
+ }
185
+
186
+ public async applyBaseSnapshots() {
187
+ await this.applyInitialAccountsSnapshot();
188
+ await this.applySetupFeeJuiceSnapshot();
189
+ }
190
+
191
+ async applyInitialAccountsSnapshot() {
192
+ await this.snapshotManager.snapshot(
193
+ 'initial_accounts',
194
+ deployAccounts(2, this.logger),
195
+ async (
196
+ { deployedAccounts: [{ address: adminAddress }, { address: sequencerAddress }] },
197
+ { wallet, aztecNode, cheatCodes },
198
+ ) => {
199
+ this.adminWallet = wallet;
200
+ this.aztecNode = aztecNode;
201
+ this.cheatCodes = cheatCodes;
202
+
203
+ this.adminAddress = adminAddress;
204
+ this.sequencerAddress = sequencerAddress;
205
+
206
+ const canonicalFeeJuice = await getCanonicalFeeJuice();
207
+ this.feeJuiceContract = await FeeJuiceContract.at(canonicalFeeJuice.address, this.adminWallet);
208
+ this.coinbase = EthAddress.random();
209
+
210
+ const userPXEConfig = getPXEConfig();
211
+ const userPXEConfigWithContracts = {
212
+ ...userPXEConfig,
213
+ proverEnabled: this.realProofs,
214
+ } as PXEConfig;
215
+
216
+ this.userWallet = await TestWallet.create(this.aztecNode, userPXEConfigWithContracts, {
217
+ loggers: {
218
+ prover: this.proxyLogger.createLogger('pxe:bb:wasm:bundle:proxied'),
219
+ },
220
+ });
221
+ },
222
+ );
223
+ }
224
+
225
+ async applySetupFeeJuiceSnapshot() {
226
+ await this.snapshotManager.snapshot(
227
+ 'setup_fee_juice',
228
+ async () => {},
229
+ async (_data, context) => {
230
+ this.context = context;
231
+
232
+ this.feeJuiceContract = await FeeJuiceContract.at(ProtocolContractAddress.FeeJuice, this.adminWallet);
233
+
234
+ this.feeJuiceBridgeTestHarness = await FeeJuicePortalTestingHarnessFactory.create({
235
+ aztecNode: context.aztecNode,
236
+ aztecNodeAdmin: context.aztecNode,
237
+ l1Client: context.deployL1ContractsValues.l1Client,
238
+ wallet: this.adminWallet,
239
+ logger: this.logger,
240
+ });
241
+ },
242
+ );
243
+ }
244
+
245
+ async applyDeployBananaTokenSnapshot() {
246
+ await this.snapshotManager.snapshot(
247
+ 'deploy_banana_token',
248
+ async () => {
249
+ const bananaCoin = await BananaCoin.deploy(this.adminWallet, this.adminAddress, 'BC', 'BC', 18n)
250
+ .send({ from: this.adminAddress })
251
+ .deployed();
252
+ this.logger.info(`BananaCoin deployed at ${bananaCoin.address}`);
253
+ return { bananaCoinAddress: bananaCoin.address };
254
+ },
255
+ async ({ bananaCoinAddress }) => {
256
+ this.bananaCoin = await BananaCoin.at(bananaCoinAddress, this.adminWallet);
257
+ },
258
+ );
259
+ }
260
+
261
+ async applyDeployCandyBarTokenSnapshot() {
262
+ await this.snapshotManager.snapshot(
263
+ 'deploy_candy_bar_token',
264
+ async () => {
265
+ const candyBarCoin = await TokenContract.deploy(this.adminWallet, this.adminAddress, 'CBC', 'CBC', 18n)
266
+ .send({ from: this.adminAddress })
267
+ .deployed();
268
+ this.logger.info(`CandyBarCoin deployed at ${candyBarCoin.address}`);
269
+ return { candyBarCoinAddress: candyBarCoin.address };
270
+ },
271
+ async ({ candyBarCoinAddress }) => {
272
+ this.candyBarCoin = await TokenContract.at(candyBarCoinAddress, this.adminWallet);
273
+ },
274
+ );
275
+ }
276
+
277
+ public async applyFPCSetupSnapshot() {
278
+ await this.snapshotManager.snapshot(
279
+ 'fpc_setup',
280
+ async context => {
281
+ const feeJuiceContract = this.feeJuiceBridgeTestHarness.feeJuice;
282
+ expect((await context.wallet.getContractMetadata(feeJuiceContract.address)).isContractPublished).toBe(true);
283
+
284
+ const bananaCoin = this.bananaCoin;
285
+ const bananaFPC = await FPCContract.deploy(this.adminWallet, bananaCoin.address, this.adminAddress)
286
+ .send({ from: this.adminAddress })
287
+ .deployed();
288
+
289
+ this.logger.info(`BananaPay deployed at ${bananaFPC.address}`);
290
+
291
+ await this.feeJuiceBridgeTestHarness.bridgeFromL1ToL2(bananaFPC.address, this.adminAddress);
292
+
293
+ return { bananaFPCAddress: bananaFPC.address };
294
+ },
295
+ async data => {
296
+ this.bananaFPC = await FPCContract.at(data.bananaFPCAddress, this.adminWallet);
297
+ },
298
+ );
299
+ }
300
+
301
+ async applyDeploySponsoredFPCSnapshot() {
302
+ await this.snapshotManager.snapshot(
303
+ 'deploy_sponsored_fpc',
304
+ async () => {
305
+ const sponsoredFPC = await setupSponsoredFPC(this.adminWallet);
306
+ this.logger.info(`SponsoredFPC at ${sponsoredFPC.address}`);
307
+ return { sponsoredFPCAddress: sponsoredFPC.address };
308
+ },
309
+ async ({ sponsoredFPCAddress }) => {
310
+ this.sponsoredFPC = await SponsoredFPCContract.at(sponsoredFPCAddress, this.adminWallet);
311
+ },
312
+ );
313
+ }
314
+
315
+ public async createCrossChainTestHarness(owner: AztecAddress) {
316
+ const l1Client = createExtendedL1Client(this.context.aztecNodeConfig.l1RpcUrls, MNEMONIC);
317
+
318
+ const underlyingERC20Address = await deployL1Contract(l1Client, TestERC20Abi, TestERC20Bytecode, [
319
+ 'Underlying',
320
+ 'UND',
321
+ l1Client.account.address,
322
+ ]).then(({ address }) => address);
323
+
324
+ this.logger.verbose(`Setting up cross chain harness...`);
325
+ const crossChainTestHarness = await CrossChainTestHarness.new(
326
+ this.aztecNode,
327
+ l1Client,
328
+ this.adminWallet,
329
+ owner,
330
+ this.logger,
331
+ underlyingERC20Address,
332
+ );
333
+
334
+ this.logger.verbose(`L2 token deployed to: ${crossChainTestHarness.l2Token.address}`);
335
+
336
+ return crossChainTestHarness;
337
+ }
338
+
339
+ public async createAndFundBenchmarkingAccountOnUserWallet(accountType: AccountType) {
340
+ const benchysAccountManager = await this.createBenchmarkingAccountManager(this.adminWallet, accountType);
341
+ const benchysAccount = await benchysAccountManager.getAccount();
342
+ const benchysAddress = benchysAccountManager.address;
343
+ const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(benchysAddress);
344
+ const behchysDeployMethod = await benchysAccountManager.getDeployMethod();
345
+ await behchysDeployMethod
346
+ .send({
347
+ from: AztecAddress.ZERO,
348
+ fee: { paymentMethod: new FeeJuicePaymentMethodWithClaim(benchysAddress, claim) },
349
+ })
350
+ .wait();
351
+ // Register benchy on the user's Wallet, where we're going to be interacting from
352
+ const accountManager = await this.userWallet.createAccount({
353
+ secret: benchysAccount.getSecretKey(),
354
+ salt: new Fr(benchysAccount.salt),
355
+ contract: benchysAccountManager.getAccountContract(),
356
+ });
357
+ return accountManager.address;
358
+ }
359
+
360
+ public async applyDeployAmmSnapshot() {
361
+ await this.snapshotManager.snapshot(
362
+ 'deploy_amm',
363
+ async () => {
364
+ const liquidityToken = await TokenContract.deploy(this.adminWallet, this.adminAddress, 'LPT', 'LPT', 18n)
365
+ .send({ from: this.adminAddress })
366
+ .deployed();
367
+ const amm = await AMMContract.deploy(
368
+ this.adminWallet,
369
+ this.bananaCoin.address,
370
+ this.candyBarCoin.address,
371
+ liquidityToken.address,
372
+ )
373
+ .send({ from: this.adminAddress })
374
+ .deployed();
375
+ this.logger.info(`AMM deployed at ${amm.address}`);
376
+ await liquidityToken.methods.set_minter(amm.address, true).send({ from: this.adminAddress }).wait();
377
+ return { ammAddress: amm.address, liquidityTokenAddress: liquidityToken.address };
378
+ },
379
+ async ({ ammAddress, liquidityTokenAddress }) => {
380
+ this.liquidityToken = await TokenContract.at(liquidityTokenAddress, this.adminWallet);
381
+ this.amm = await AMMContract.at(ammAddress, this.adminWallet);
382
+ },
383
+ );
384
+ }
385
+
386
+ public async getBridgedFeeJuicePaymentMethodForWallet(_wallet: Wallet, sender: AztecAddress) {
387
+ const claim = await this.feeJuiceBridgeTestHarness.prepareTokensOnL1(sender);
388
+ return new FeeJuicePaymentMethodWithClaim(sender, claim);
389
+ }
390
+
391
+ public async getPrivateFPCPaymentMethodForWallet(wallet: Wallet, sender: AztecAddress) {
392
+ // The private fee paying method assembled on the app side requires knowledge of the maximum
393
+ // fee the user is willing to pay
394
+ const maxFeesPerGas = (await this.aztecNode.getCurrentBaseFees()).mul(1.5);
395
+ const gasSettings = GasSettings.default({ maxFeesPerGas });
396
+ return new PrivateFeePaymentMethod(this.bananaFPC.address, sender, wallet, gasSettings);
397
+ }
398
+
399
+ public getSponsoredFPCPaymentMethodForWallet(_wallet: Wallet, _sender: AztecAddress) {
400
+ return Promise.resolve(new SponsoredFeePaymentMethod(this.sponsoredFPC.address));
401
+ }
402
+ }
@@ -0,0 +1,61 @@
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 = 'accountDeployments' | 'deployments' | 'transfers' | 'bridging' | 'amm';
10
+
11
+ export type ClientFlowsConfig = {
12
+ [key in ClientFlows]: ClientFlowConfig;
13
+ };
14
+
15
+ export const KEY_FLOWS_CONFIG: ClientFlowsConfig = {
16
+ accountDeployments: {
17
+ accounts: ['ecdsar1', 'schnorr'],
18
+ feePaymentMethods: ['sponsored_fpc'],
19
+ },
20
+ deployments: {
21
+ accounts: ['ecdsar1', 'schnorr'],
22
+ feePaymentMethods: ['sponsored_fpc'],
23
+ },
24
+ amm: {
25
+ accounts: ['ecdsar1'],
26
+ feePaymentMethods: ['sponsored_fpc'],
27
+ },
28
+ bridging: {
29
+ accounts: ['ecdsar1'],
30
+ feePaymentMethods: ['sponsored_fpc'],
31
+ },
32
+ transfers: {
33
+ accounts: ['ecdsar1'],
34
+ feePaymentMethods: ['sponsored_fpc', 'private_fpc'],
35
+ recursions: [0, 1],
36
+ },
37
+ };
38
+
39
+ export const FULL_FLOWS_CONFIG: ClientFlowsConfig = {
40
+ accountDeployments: {
41
+ accounts: ['ecdsar1', 'schnorr'],
42
+ feePaymentMethods: ['bridged_fee_juice', 'sponsored_fpc'],
43
+ },
44
+ deployments: {
45
+ accounts: ['ecdsar1', 'schnorr'],
46
+ feePaymentMethods: ['bridged_fee_juice', 'sponsored_fpc'],
47
+ },
48
+ amm: {
49
+ accounts: ['ecdsar1', 'schnorr'],
50
+ feePaymentMethods: ['sponsored_fpc', 'private_fpc'],
51
+ },
52
+ bridging: {
53
+ accounts: ['ecdsar1', 'schnorr'],
54
+ feePaymentMethods: ['sponsored_fpc', 'private_fpc'],
55
+ },
56
+ transfers: {
57
+ accounts: ['ecdsar1', 'schnorr'],
58
+ feePaymentMethods: ['sponsored_fpc', 'private_fpc'],
59
+ recursions: [0, 1, 2],
60
+ },
61
+ };
@@ -0,0 +1,111 @@
1
+ import type { Logger } from '@aztec/aztec.js/log';
2
+ import { BBNativePrivateKernelProver } from '@aztec/bb-prover/client/native';
3
+ import { BBWASMBundlePrivateKernelProver } from '@aztec/bb-prover/client/wasm/bundle';
4
+ import { createLogger, logger } from '@aztec/foundation/log';
5
+ import { Timer } from '@aztec/foundation/timer';
6
+ import { WASMSimulator } from '@aztec/simulator/client';
7
+ import type { PrivateExecutionStep } from '@aztec/stdlib/kernel';
8
+ import type { ProvingStats, ProvingTimings, SimulationStats } from '@aztec/stdlib/tx';
9
+
10
+ import { Decoder } from 'msgpackr';
11
+ import { readFile, readdir, writeFile } from 'node:fs/promises';
12
+ import { join } from 'node:path';
13
+
14
+ import { type Log, type ProverType, ProxyLogger, generateBenchmark } from './benchmark.js';
15
+
16
+ type NativeProverConfig = { bbBinaryPath?: string; bbWorkingDirectory?: string };
17
+
18
+ async function createProver(config: NativeProverConfig = {}, log: Logger) {
19
+ const simulator = new WASMSimulator();
20
+ if (!config.bbBinaryPath || !config.bbWorkingDirectory) {
21
+ return { prover: new BBWASMBundlePrivateKernelProver(simulator, 16, log), type: 'wasm' as ProverType };
22
+ } else {
23
+ const bbConfig = config as Required<NativeProverConfig>;
24
+ return {
25
+ prover: await BBNativePrivateKernelProver.new(
26
+ { bbSkipCleanup: false, numConcurrentIVCVerifiers: 1, bbIVCConcurrency: 1, ...bbConfig },
27
+ simulator,
28
+ log,
29
+ ),
30
+ type: 'native' as ProverType,
31
+ };
32
+ }
33
+ }
34
+
35
+ async function main() {
36
+ ProxyLogger.create();
37
+ const proxyLogger = ProxyLogger.getInstance();
38
+ const ivcFolder = process.env.CAPTURE_IVC_FOLDER;
39
+ if (!ivcFolder) {
40
+ throw new Error('CAPTURE_IVC_FOLDER is not set');
41
+ }
42
+ const flows = await readdir(ivcFolder);
43
+ logger.info(`Flows in ${ivcFolder}: \n${flows.map(flowName => `\t- ${flowName}`).join('\n')}`);
44
+ const { prover, type: proverType } = await createProver(
45
+ { bbBinaryPath: process.env.BB_BINARY_PATH, bbWorkingDirectory: process.env.BB_WORKING_DIRECTORY },
46
+ proxyLogger.createLogger('bb:prover'),
47
+ );
48
+
49
+ const userLog = createLogger('chonk_flows:data_processor');
50
+
51
+ for (const flow of flows) {
52
+ userLog.info(`Processing flow ${flow}`);
53
+ const ivcInputs = await readFile(join(ivcFolder, flow, 'ivc-inputs.msgpack'));
54
+ const stepsFromFile: PrivateExecutionStep[] = new Decoder({ useRecords: false }).unpack(ivcInputs);
55
+ const witnesses = await readFile(join(ivcFolder, flow, 'witnesses.json'));
56
+
57
+ const witnessStack = JSON.parse(witnesses.toString()).map((witnessMap: Record<string, string>) => {
58
+ return new Map<number, string>(Object.entries(witnessMap).map(([k, v]) => [Number(k), v]));
59
+ });
60
+ const profileFile = await readFile(join(ivcFolder, flow, 'profile.json'));
61
+ const profile = JSON.parse(profileFile.toString()) as {
62
+ stats: ProvingStats | SimulationStats;
63
+ steps: {
64
+ functionName: string;
65
+ gateCount: number;
66
+ timings: { witgen: number; gateCount: number };
67
+ }[];
68
+ };
69
+ const privateExecutionSteps: PrivateExecutionStep[] = profile.steps.map((step, i) => ({
70
+ functionName: step.functionName,
71
+ gateCount: step.gateCount,
72
+ bytecode: stepsFromFile[i].bytecode,
73
+ // TODO(AD) do we still want to take this from witness.json?
74
+ witness: witnessStack[i],
75
+ vk: stepsFromFile[i].vk,
76
+ timings: {
77
+ witgen: step.timings.witgen,
78
+ gateCount: step.timings.gateCount,
79
+ },
80
+ }));
81
+
82
+ let error: any;
83
+ let currentLogs: Log[] = [];
84
+ let provingTime;
85
+ try {
86
+ const provingTimer = new Timer();
87
+ await prover.createChonkProof(privateExecutionSteps);
88
+ provingTime = provingTimer.ms();
89
+ } catch (e) {
90
+ userLog.error(`Failed to generate chonk proof for ${flow}`, e);
91
+ error = (e as Error).message;
92
+ }
93
+ // Extract logs from this run from the proxy and write them to disk unconditionally
94
+ currentLogs = proxyLogger.getLogs();
95
+ await writeFile(join(ivcFolder, flow, 'logs.json'), JSON.stringify(currentLogs, null, 2));
96
+ if (!(profile.stats.timings as ProvingTimings).proving) {
97
+ (profile.stats.timings as ProvingTimings).proving = provingTime;
98
+ }
99
+ const benchmark = generateBenchmark(flow, currentLogs, profile.stats, privateExecutionSteps, proverType, error);
100
+ await writeFile(join(ivcFolder, flow, 'benchmark.json'), JSON.stringify(benchmark, null, 2));
101
+ proxyLogger.flushLogs();
102
+ }
103
+ }
104
+
105
+ try {
106
+ await main();
107
+ } catch (e) {
108
+ // eslint-disable-next-line no-console
109
+ console.error(e);
110
+ process.exit(1);
111
+ }