@aztec/end-to-end 0.0.0-test.1 → 0.0.1-commit.03f7ef2

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