@aztec/aztec 0.75.0-commit.c03ba01a2a4122e43e90d5133ba017e54b90e9d2

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 (50) hide show
  1. package/README.md +57 -0
  2. package/dest/bin/index.js +46 -0
  3. package/dest/cli/aztec_start_action.js +110 -0
  4. package/dest/cli/aztec_start_options.js +341 -0
  5. package/dest/cli/cli.js +33 -0
  6. package/dest/cli/cmds/start_archiver.js +35 -0
  7. package/dest/cli/cmds/start_bot.js +31 -0
  8. package/dest/cli/cmds/start_faucet.js +20 -0
  9. package/dest/cli/cmds/start_node.js +109 -0
  10. package/dest/cli/cmds/start_p2p_bootstrap.js +20 -0
  11. package/dest/cli/cmds/start_proof_verifier.js +12 -0
  12. package/dest/cli/cmds/start_prover_agent.js +32 -0
  13. package/dest/cli/cmds/start_prover_broker.js +22 -0
  14. package/dest/cli/cmds/start_prover_node.js +81 -0
  15. package/dest/cli/cmds/start_pxe.js +90 -0
  16. package/dest/cli/cmds/start_txe.js +11 -0
  17. package/dest/cli/index.js +1 -0
  18. package/dest/cli/util.js +154 -0
  19. package/dest/cli/validation.js +25 -0
  20. package/dest/examples/token.js +53 -0
  21. package/dest/examples/util.js +31 -0
  22. package/dest/index.js +1 -0
  23. package/dest/mnemonic.js +1 -0
  24. package/dest/sandbox.js +116 -0
  25. package/dest/splash.js +2 -0
  26. package/package.json +119 -0
  27. package/src/bin/index.ts +54 -0
  28. package/src/cli/aztec_start_action.ts +115 -0
  29. package/src/cli/aztec_start_options.ts +366 -0
  30. package/src/cli/cli.ts +48 -0
  31. package/src/cli/cmds/start_archiver.ts +47 -0
  32. package/src/cli/cmds/start_bot.ts +49 -0
  33. package/src/cli/cmds/start_faucet.ts +34 -0
  34. package/src/cli/cmds/start_node.ts +123 -0
  35. package/src/cli/cmds/start_p2p_bootstrap.ts +25 -0
  36. package/src/cli/cmds/start_proof_verifier.ts +18 -0
  37. package/src/cli/cmds/start_prover_agent.ts +65 -0
  38. package/src/cli/cmds/start_prover_broker.ts +37 -0
  39. package/src/cli/cmds/start_prover_node.ts +100 -0
  40. package/src/cli/cmds/start_pxe.ts +124 -0
  41. package/src/cli/cmds/start_txe.ts +15 -0
  42. package/src/cli/index.ts +1 -0
  43. package/src/cli/util.ts +216 -0
  44. package/src/cli/validation.ts +38 -0
  45. package/src/examples/token.ts +74 -0
  46. package/src/examples/util.ts +44 -0
  47. package/src/index.ts +1 -0
  48. package/src/mnemonic.ts +1 -0
  49. package/src/sandbox.ts +165 -0
  50. package/src/splash.ts +10 -0
@@ -0,0 +1,74 @@
1
+ import { getSingleKeyAccount } from '@aztec/accounts/single_key';
2
+ import { type AccountWallet, Fr, createPXEClient } from '@aztec/aztec.js';
3
+ import { createLogger } from '@aztec/foundation/log';
4
+ import { TokenContract } from '@aztec/noir-contracts.js/Token';
5
+
6
+ const logger = createLogger('example:token');
7
+
8
+ export const alicePrivateKey = Fr.random();
9
+ export const bobPrivateKey = Fr.random();
10
+
11
+ const url = 'http://localhost:8080';
12
+
13
+ const pxe = createPXEClient(url);
14
+
15
+ let aliceWallet: AccountWallet;
16
+ let bobWallet: AccountWallet;
17
+
18
+ const ALICE_MINT_BALANCE = 333n;
19
+ const TRANSFER_AMOUNT = 33n;
20
+
21
+ /**
22
+ * Main function.
23
+ */
24
+ async function main() {
25
+ logger.info('Running token contract test on HTTP interface.');
26
+
27
+ const aliceAccount = await getSingleKeyAccount(pxe, alicePrivateKey);
28
+ aliceWallet = await aliceAccount.waitSetup();
29
+ const bobAccount = await getSingleKeyAccount(pxe, bobPrivateKey);
30
+ bobWallet = await bobAccount.waitSetup();
31
+ const alice = aliceWallet.getCompleteAddress();
32
+ const bob = bobWallet.getCompleteAddress();
33
+
34
+ logger.info(`Created Alice and Bob accounts: ${alice.address.toString()}, ${bob.address.toString()}`);
35
+
36
+ logger.info('Deploying Token...');
37
+ const token = await TokenContract.deploy(aliceWallet, alice, 'TokenName', 'TokenSymbol', 18).send().deployed();
38
+ logger.info('Token deployed');
39
+
40
+ // Create the contract abstraction and link it to Alice's and Bob's wallet for future signing
41
+ const tokenAlice = await TokenContract.at(token.address, aliceWallet);
42
+ const tokenBob = await TokenContract.at(token.address, bobWallet);
43
+
44
+ // Mint tokens to Alice
45
+ logger.info(`Minting ${ALICE_MINT_BALANCE} more coins to Alice...`);
46
+ const from = aliceWallet.getAddress(); // we are setting from to Alice here because of TODO(#9887)
47
+ await tokenAlice.methods.mint_to_private(from, aliceWallet.getAddress(), ALICE_MINT_BALANCE).send().wait();
48
+
49
+ logger.info(`${ALICE_MINT_BALANCE} tokens were successfully minted by Alice and transferred to private`);
50
+
51
+ const balanceAfterMint = await tokenAlice.methods.balance_of_private(alice).simulate();
52
+ logger.info(`Tokens successfully minted. New Alice's balance: ${balanceAfterMint}`);
53
+
54
+ // We will now transfer tokens from Alice to Bob
55
+ logger.info(`Transferring ${TRANSFER_AMOUNT} tokens from Alice to Bob...`);
56
+ await tokenAlice.methods.transfer(bob, TRANSFER_AMOUNT).send().wait();
57
+
58
+ // Check the new balances
59
+ const aliceBalance = await tokenAlice.methods.balance_of_private(alice).simulate();
60
+ logger.info(`Alice's balance ${aliceBalance}`);
61
+
62
+ const bobBalance = await tokenBob.methods.balance_of_private(bob).simulate();
63
+ logger.info(`Bob's balance ${bobBalance}`);
64
+ }
65
+
66
+ main()
67
+ .then(() => {
68
+ logger.info('Finished running successfully.');
69
+ process.exit(0);
70
+ })
71
+ .catch(err => {
72
+ logger.error('Error in main fn: ', err);
73
+ process.exit(1);
74
+ });
@@ -0,0 +1,44 @@
1
+ import { EthAddress } from '@aztec/aztec.js';
2
+ import { jsonStringify } from '@aztec/foundation/json-rpc';
3
+
4
+ import type { Abi, Narrow } from 'abitype';
5
+ import { type Account, type Chain, type Hex, type HttpTransport, type PublicClient, type WalletClient } from 'viem';
6
+
7
+ /**
8
+ * Helper function to deploy ETH contracts.
9
+ * @param walletClient - A viem WalletClient.
10
+ * @param publicClient - A viem PublicClient.
11
+ * @param abi - The ETH contract's ABI (as abitype's Abi).
12
+ * @param bytecode - The ETH contract's bytecode.
13
+ * @param args - Constructor arguments for the contract.
14
+ * @returns The ETH address the contract was deployed to.
15
+ */
16
+ export async function deployL1Contract(
17
+ walletClient: WalletClient<HttpTransport, Chain, Account>,
18
+ publicClient: PublicClient<HttpTransport, Chain>,
19
+ abi: Narrow<Abi | readonly unknown[]>,
20
+ bytecode: Hex,
21
+ args: readonly unknown[] = [],
22
+ ): Promise<EthAddress> {
23
+ const hash = await walletClient.deployContract({
24
+ abi,
25
+ bytecode,
26
+ args,
27
+ });
28
+
29
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
30
+ const contractAddress = receipt.contractAddress;
31
+ if (!contractAddress) {
32
+ throw new Error(`No contract address found in receipt: ${jsonStringify(receipt)}`);
33
+ }
34
+
35
+ return EthAddress.fromString(receipt.contractAddress!);
36
+ }
37
+
38
+ /**
39
+ * Sleep for a given number of milliseconds.
40
+ * @param ms - the number of milliseconds to sleep for
41
+ */
42
+ export function delay(ms: number): Promise<void> {
43
+ return new Promise<void>(resolve => setTimeout(resolve, ms));
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { createSandbox } from './sandbox.js';
@@ -0,0 +1 @@
1
+ export const DefaultMnemonic = 'test test test test test test test test test test test junk';
package/src/sandbox.ts ADDED
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env -S node --no-warnings
2
+ import { type AztecNodeConfig, AztecNodeService, getConfigEnvVars } from '@aztec/aztec-node';
3
+ import { AnvilTestWatcher, EthCheatCodes, SignerlessWallet } from '@aztec/aztec.js';
4
+ import { DefaultMultiCallEntrypoint } from '@aztec/aztec.js/entrypoint';
5
+ import { type BlobSinkClientInterface, createBlobSinkClient } from '@aztec/blob-sink/client';
6
+ import { type AztecNode } from '@aztec/circuit-types';
7
+ import { setupCanonicalL2FeeJuice } from '@aztec/cli/setup-contracts';
8
+ import {
9
+ NULL_KEY,
10
+ createEthereumChain,
11
+ deployL1Contracts,
12
+ getL1ContractsConfigEnvVars,
13
+ waitForPublicClient,
14
+ } from '@aztec/ethereum';
15
+ import { createLogger } from '@aztec/foundation/log';
16
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vks';
17
+ import { ProtocolContractAddress, protocolContractTreeRoot } from '@aztec/protocol-contracts';
18
+ import { type PXEServiceConfig, createPXEService, getPXEServiceConfig } from '@aztec/pxe';
19
+ import {
20
+ type TelemetryClient,
21
+ getConfigEnvVars as getTelemetryClientConfig,
22
+ initTelemetryClient,
23
+ } from '@aztec/telemetry-client';
24
+
25
+ import { type HDAccount, type PrivateKeyAccount, createPublicClient, http as httpViemTransport } from 'viem';
26
+ import { mnemonicToAccount } from 'viem/accounts';
27
+ import { foundry } from 'viem/chains';
28
+
29
+ import { DefaultMnemonic } from './mnemonic.js';
30
+
31
+ const logger = createLogger('sandbox');
32
+
33
+ const localAnvil = foundry;
34
+
35
+ /**
36
+ * Function to deploy our L1 contracts to the sandbox L1
37
+ * @param aztecNodeConfig - The Aztec Node Config
38
+ * @param hdAccount - Account for publishing L1 contracts
39
+ */
40
+ export async function deployContractsToL1(
41
+ aztecNodeConfig: AztecNodeConfig,
42
+ hdAccount: HDAccount | PrivateKeyAccount,
43
+ contractDeployLogger = logger,
44
+ opts: { assumeProvenThroughBlockNumber?: number; salt?: number } = {},
45
+ ) {
46
+ const chain = aztecNodeConfig.l1RpcUrl
47
+ ? createEthereumChain(aztecNodeConfig.l1RpcUrl, aztecNodeConfig.l1ChainId)
48
+ : { chainInfo: localAnvil };
49
+
50
+ await waitForPublicClient(aztecNodeConfig);
51
+
52
+ const l1Contracts = await deployL1Contracts(
53
+ aztecNodeConfig.l1RpcUrl,
54
+ hdAccount,
55
+ chain.chainInfo,
56
+ contractDeployLogger,
57
+ {
58
+ ...getL1ContractsConfigEnvVars(), // TODO: We should not need to be loading config from env again, caller should handle this
59
+ ...aztecNodeConfig,
60
+ l2FeeJuiceAddress: ProtocolContractAddress.FeeJuice,
61
+ vkTreeRoot: await getVKTreeRoot(),
62
+ protocolContractTreeRoot,
63
+ assumeProvenThrough: opts.assumeProvenThroughBlockNumber,
64
+ salt: opts.salt,
65
+ },
66
+ );
67
+
68
+ aztecNodeConfig.l1Contracts = l1Contracts.l1ContractAddresses;
69
+
70
+ return aztecNodeConfig.l1Contracts;
71
+ }
72
+
73
+ /** Sandbox settings. */
74
+ export type SandboxConfig = AztecNodeConfig & {
75
+ /** Mnemonic used to derive the L1 deployer private key.*/
76
+ l1Mnemonic: string;
77
+ /** Salt used to deploy L1 contracts.*/
78
+ l1Salt: string;
79
+ };
80
+
81
+ /**
82
+ * Create and start a new Aztec Node and PXE. Deploys L1 contracts.
83
+ * Does not start any HTTP services nor populate any initial accounts.
84
+ * @param config - Optional Sandbox settings.
85
+ */
86
+ export async function createSandbox(config: Partial<SandboxConfig> = {}) {
87
+ const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars(), ...config };
88
+ const hdAccount = mnemonicToAccount(config.l1Mnemonic || DefaultMnemonic);
89
+ if (!aztecNodeConfig.publisherPrivateKey || aztecNodeConfig.publisherPrivateKey === NULL_KEY) {
90
+ const privKey = hdAccount.getHdKey().privateKey;
91
+ aztecNodeConfig.publisherPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`;
92
+ }
93
+ if (!aztecNodeConfig.validatorPrivateKey || aztecNodeConfig.validatorPrivateKey === NULL_KEY) {
94
+ const privKey = hdAccount.getHdKey().privateKey;
95
+ aztecNodeConfig.validatorPrivateKey = `0x${Buffer.from(privKey!).toString('hex')}`;
96
+ }
97
+
98
+ let watcher: AnvilTestWatcher | undefined = undefined;
99
+ if (!aztecNodeConfig.p2pEnabled) {
100
+ const l1ContractAddresses = await deployContractsToL1(aztecNodeConfig, hdAccount, undefined, {
101
+ assumeProvenThroughBlockNumber: Number.MAX_SAFE_INTEGER,
102
+ salt: config.l1Salt ? parseInt(config.l1Salt) : undefined,
103
+ });
104
+
105
+ const chain = aztecNodeConfig.l1RpcUrl
106
+ ? createEthereumChain(aztecNodeConfig.l1RpcUrl, aztecNodeConfig.l1ChainId)
107
+ : { chainInfo: localAnvil };
108
+
109
+ const publicClient = createPublicClient({
110
+ chain: chain.chainInfo,
111
+ transport: httpViemTransport(aztecNodeConfig.l1RpcUrl),
112
+ });
113
+
114
+ watcher = new AnvilTestWatcher(
115
+ new EthCheatCodes(aztecNodeConfig.l1RpcUrl),
116
+ l1ContractAddresses.rollupAddress,
117
+ publicClient,
118
+ );
119
+ watcher.setIsSandbox(true);
120
+ await watcher.start();
121
+ }
122
+
123
+ const telemetry = initTelemetryClient(getTelemetryClientConfig());
124
+ // Create a local blob sink client inside the sandbox, no http connectivity
125
+ const blobSinkClient = createBlobSinkClient();
126
+ const node = await createAztecNode(aztecNodeConfig, { telemetry, blobSinkClient });
127
+ const pxe = await createAztecPXE(node);
128
+
129
+ await setupCanonicalL2FeeJuice(
130
+ new SignerlessWallet(pxe, new DefaultMultiCallEntrypoint(aztecNodeConfig.l1ChainId, aztecNodeConfig.version)),
131
+ aztecNodeConfig.l1Contracts.feeJuicePortalAddress,
132
+ undefined,
133
+ logger.info,
134
+ );
135
+
136
+ const stop = async () => {
137
+ await node.stop();
138
+ await watcher?.stop();
139
+ };
140
+
141
+ return { node, pxe, aztecNodeConfig, stop };
142
+ }
143
+
144
+ /**
145
+ * Create and start a new Aztec RPC HTTP Server
146
+ * @param config - Optional Aztec node settings.
147
+ */
148
+ export async function createAztecNode(
149
+ config: Partial<AztecNodeConfig> = {},
150
+ deps: { telemetry?: TelemetryClient; blobSinkClient?: BlobSinkClientInterface } = {},
151
+ ) {
152
+ const aztecNodeConfig: AztecNodeConfig = { ...getConfigEnvVars(), ...config };
153
+ const node = await AztecNodeService.createAndSync(aztecNodeConfig, deps);
154
+ return node;
155
+ }
156
+
157
+ /**
158
+ * Create and start a new Aztec PXE HTTP Server
159
+ * @param config - Optional PXE settings.
160
+ */
161
+ export async function createAztecPXE(node: AztecNode, config: Partial<PXEServiceConfig> = {}) {
162
+ const pxeServiceConfig: PXEServiceConfig = { ...getPXEServiceConfig(), ...config };
163
+ const pxe = await createPXEService(node, pxeServiceConfig);
164
+ return pxe;
165
+ }
package/src/splash.ts ADDED
@@ -0,0 +1,10 @@
1
+ export const splash: string =
2
+ '\n' +
3
+ ' _\n' +
4
+ ' /\\ | |\n' +
5
+ ' / \\ ___| |_ ___ ___ \n' +
6
+ ' / /\\ \\ |_ / __/ _ \\/ __|\n' +
7
+ ' / ____ \\ / /| || __/ (__ \n' +
8
+ '/_/___ \\_\\/___|\\__\\___|\\___|\n';
9
+
10
+ export const github = 'https://github.com/AztecProtocol';