@aztec/aztec 0.0.1-commit.343b43af6 → 0.0.1-commit.350e0a4d

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 (125) hide show
  1. package/dest/bin/index.js +3 -1
  2. package/dest/cli/aztec_start_action.d.ts +1 -1
  3. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  4. package/dest/cli/aztec_start_action.js +22 -23
  5. package/dest/cli/aztec_start_options.d.ts +2 -2
  6. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  7. package/dest/cli/aztec_start_options.js +15 -15
  8. package/dest/cli/cmds/compile.d.ts +1 -1
  9. package/dest/cli/cmds/compile.d.ts.map +1 -1
  10. package/dest/cli/cmds/compile.js +34 -25
  11. package/dest/cli/cmds/profile.d.ts +1 -1
  12. package/dest/cli/cmds/profile.d.ts.map +1 -1
  13. package/dest/cli/cmds/profile.js +1 -1
  14. package/dest/cli/cmds/profile_flamegraph.d.ts +1 -1
  15. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -1
  16. package/dest/cli/cmds/profile_flamegraph.js +2 -1
  17. package/dest/cli/cmds/profile_gates.d.ts +2 -2
  18. package/dest/cli/cmds/profile_gates.d.ts.map +1 -1
  19. package/dest/cli/cmds/profile_gates.js +23 -4
  20. package/dest/cli/cmds/prover.d.ts +4 -0
  21. package/dest/cli/cmds/prover.d.ts.map +1 -0
  22. package/dest/cli/cmds/prover.js +24 -0
  23. package/dest/cli/cmds/standby.d.ts +39 -10
  24. package/dest/cli/cmds/standby.d.ts.map +1 -1
  25. package/dest/cli/cmds/standby.js +80 -18
  26. package/dest/cli/cmds/start_bot.d.ts +1 -1
  27. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  28. package/dest/cli/cmds/start_bot.js +8 -4
  29. package/dest/cli/cmds/start_node.d.ts +1 -1
  30. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  31. package/dest/cli/cmds/start_node.js +29 -48
  32. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  33. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  34. package/dest/cli/cmds/start_prover_agent.js +5 -17
  35. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  36. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  37. package/dest/cli/cmds/start_prover_broker.js +17 -8
  38. package/dest/cli/cmds/start_txe.d.ts +2 -2
  39. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  40. package/dest/cli/cmds/start_txe.js +6 -5
  41. package/dest/cli/cmds/utils/artifacts.d.ts +6 -1
  42. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -1
  43. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
  44. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
  45. package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
  46. package/dest/cli/cmds/utils/needs_recompile.d.ts +1 -1
  47. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -1
  48. package/dest/cli/cmds/utils/needs_recompile.js +9 -43
  49. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
  50. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
  51. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
  52. package/dest/cli/util.d.ts +10 -5
  53. package/dest/cli/util.d.ts.map +1 -1
  54. package/dest/cli/util.js +26 -53
  55. package/dest/examples/token.js +3 -3
  56. package/dest/local-network/auth_registry.d.ts +5 -0
  57. package/dest/local-network/auth_registry.d.ts.map +1 -0
  58. package/dest/local-network/auth_registry.js +17 -0
  59. package/dest/local-network/banana_fpc.d.ts +3 -2
  60. package/dest/local-network/banana_fpc.d.ts.map +1 -1
  61. package/dest/local-network/banana_fpc.js +11 -7
  62. package/dest/local-network/local-network.d.ts +8 -32
  63. package/dest/local-network/local-network.d.ts.map +1 -1
  64. package/dest/local-network/local-network.js +52 -73
  65. package/dest/testing/cheat_codes.d.ts +17 -23
  66. package/dest/testing/cheat_codes.d.ts.map +1 -1
  67. package/dest/testing/cheat_codes.js +17 -43
  68. package/dest/testing/epoch_test_settler.d.ts +2 -2
  69. package/dest/testing/epoch_test_settler.d.ts.map +1 -1
  70. package/dest/testing/epoch_test_settler.js +6 -26
  71. package/dest/testing/index.d.ts +1 -2
  72. package/dest/testing/index.d.ts.map +1 -1
  73. package/dest/testing/index.js +0 -1
  74. package/dest/testing/token_allowed_setup.d.ts +9 -4
  75. package/dest/testing/token_allowed_setup.d.ts.map +1 -1
  76. package/dest/testing/token_allowed_setup.js +12 -8
  77. package/package.json +34 -34
  78. package/scripts/add_crate.sh +11 -60
  79. package/scripts/aztec.sh +6 -2
  80. package/scripts/init.sh +5 -5
  81. package/scripts/new.sh +2 -2
  82. package/scripts/setup_workspace.sh +3 -2
  83. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  84. package/scripts/templates/blank/contract/src/main.nr +10 -0
  85. package/scripts/templates/blank/test/Nargo.toml +7 -0
  86. package/scripts/templates/blank/test/src/lib.nr +11 -0
  87. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  88. package/scripts/templates/counter/contract/src/main.nr +48 -0
  89. package/scripts/templates/counter/test/Nargo.toml +7 -0
  90. package/scripts/templates/counter/test/src/lib.nr +32 -0
  91. package/src/bin/index.ts +3 -1
  92. package/src/cli/aztec_start_action.ts +18 -19
  93. package/src/cli/aztec_start_options.ts +22 -23
  94. package/src/cli/cmds/compile.ts +39 -24
  95. package/src/cli/cmds/profile.ts +2 -1
  96. package/src/cli/cmds/profile_flamegraph.ts +2 -1
  97. package/src/cli/cmds/profile_gates.ts +22 -5
  98. package/src/cli/cmds/prover.ts +42 -0
  99. package/src/cli/cmds/standby.ts +95 -22
  100. package/src/cli/cmds/start_bot.ts +9 -6
  101. package/src/cli/cmds/start_node.ts +37 -40
  102. package/src/cli/cmds/start_prover_agent.ts +5 -8
  103. package/src/cli/cmds/start_prover_broker.ts +17 -11
  104. package/src/cli/cmds/start_txe.ts +7 -5
  105. package/src/cli/cmds/utils/artifacts.ts +5 -0
  106. package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
  107. package/src/cli/cmds/utils/needs_recompile.ts +8 -49
  108. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
  109. package/src/cli/util.ts +27 -68
  110. package/src/examples/token.ts +3 -3
  111. package/src/local-network/auth_registry.ts +19 -0
  112. package/src/local-network/banana_fpc.ts +12 -8
  113. package/src/local-network/local-network.ts +56 -83
  114. package/src/testing/cheat_codes.ts +18 -49
  115. package/src/testing/epoch_test_settler.ts +8 -32
  116. package/src/testing/index.ts +0 -1
  117. package/src/testing/token_allowed_setup.ts +15 -8
  118. package/dest/cli/cmds/start_archiver.d.ts +0 -9
  119. package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
  120. package/dest/cli/cmds/start_archiver.js +0 -48
  121. package/dest/testing/anvil_test_watcher.d.ts +0 -42
  122. package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
  123. package/dest/testing/anvil_test_watcher.js +0 -181
  124. package/src/cli/cmds/start_archiver.ts +0 -50
  125. package/src/testing/anvil_test_watcher.ts +0 -210
@@ -2,10 +2,11 @@
2
2
  set -euo pipefail
3
3
 
4
4
  # Creates a contract+test crate pair and adds them to an existing workspace.
5
- # Usage: add_crate.sh <crate_name>
5
+ # Usage: add_crate.sh <crate_name> <template>
6
6
  # Must be called from a workspace root that already has Nargo.toml with [workspace].
7
7
 
8
8
  crate_name=$1
9
+ template=$2
9
10
 
10
11
  if [ -z "$crate_name" ]; then
11
12
  echo "Error: crate name is required"
@@ -31,72 +32,22 @@ fi
31
32
 
32
33
  # Get the actual aztec version for the git tag.
33
34
  AZTEC_VERSION=$(jq -r '.version' $(dirname $0)/../package.json)
35
+ TEMPLATE_DIR="$(dirname $0)/templates/$template"
34
36
 
35
- # Create contract crate
36
- mkdir -p "$contract_dir/src"
37
- cat > "$contract_dir/Nargo.toml" << CEOF
38
- [package]
39
- name = "${crate_name}_contract"
40
- type = "contract"
41
-
42
- [dependencies]
43
- aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" }
44
- CEOF
45
-
46
- cat > "$contract_dir/src/main.nr" << 'EOF'
47
- use aztec::macros::aztec;
48
-
49
- #[aztec]
50
- pub contract Main {
51
- use aztec::macros::functions::{external, initializer};
52
-
53
- #[initializer]
54
- #[external("private")]
55
- fn constructor() {}
56
- }
57
- EOF
58
-
59
- # Create test crate
60
- mkdir -p "$test_dir/src"
61
- cat > "$test_dir/Nargo.toml" << TEOF
62
- [package]
63
- name = "${crate_name}_test"
64
- type = "lib"
65
-
66
- [dependencies]
67
- aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" }
68
- ${crate_name}_contract = { path = "../${contract_dir}" }
69
- TEOF
70
-
71
- cat > "$test_dir/src/lib.nr" << 'NOIR'
72
- use aztec::test::helpers::test_environment::TestEnvironment;
73
- use __CRATE_NAME___contract::Main;
74
-
75
- #[test]
76
- unconstrained fn test_constructor() {
77
- let mut env = TestEnvironment::new();
78
- let deployer = env.create_light_account();
79
-
80
- // Deploy the contract with the default constructor:
81
- let contract_address = env.deploy("@__CRATE_NAME___contract/Main").with_private_initializer(
82
- deployer,
83
- Main::interface().constructor(),
84
- );
85
-
86
- // Deploy without an initializer:
87
- let contract_address = env.deploy("@__CRATE_NAME___contract/Main").without_initializer();
88
- }
89
- NOIR
90
-
91
- sed -i "s/__CRATE_NAME__/${crate_name}/g" "$test_dir/src/lib.nr"
37
+ # Copy template crates and substitute placeholders
38
+ cp -r "$TEMPLATE_DIR/contract" "$contract_dir"
39
+ cp -r "$TEMPLATE_DIR/test" "$test_dir"
40
+ # Use perl -i for portability across os.
41
+ find "$contract_dir" "$test_dir" -type f -exec \
42
+ perl -i -pe "s/__CRATE_NAME__/${crate_name}/g; s/__AZTEC_VERSION__/${AZTEC_VERSION}/g" {} +
92
43
 
93
44
  # Add members to workspace Nargo.toml
94
45
  if grep -q 'members\s*=\s*\[\s*\]' Nargo.toml; then
95
46
  # Empty array: members = []
96
- sed -i "s|members\s*=\s*\[\s*\]|members = [\"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
47
+ perl -i -pe "s|members\s*=\s*\[\s*\]|members = [\"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
97
48
  else
98
49
  # Non-empty array: add before closing ]
99
- sed -i "s|\(members\s*=\s*\[.*\)\]|\1, \"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
50
+ perl -i -pe "s|(members\s*=\s*\[.*)\]|\1, \"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
100
51
  fi
101
52
 
102
53
  echo "Created crates '${contract_dir}' and '${test_dir}'"
package/scripts/aztec.sh CHANGED
@@ -23,13 +23,17 @@ case $cmd in
23
23
  # Attempt to compile, no-op if there are no changes
24
24
  node --no-warnings "$script_dir/../dest/bin/index.js" compile
25
25
 
26
- export LOG_LEVEL="${LOG_LEVEL:-"error;trace:contract_log"}"
26
+ export LOG_LEVEL="${LOG_LEVEL:-"error;trace:^contract:"}"
27
27
  aztec start --txe --port 8081 &
28
28
  server_pid=$!
29
29
  trap 'kill $server_pid &>/dev/null || true' EXIT
30
+ if ! command -v nc &>/dev/null; then
31
+ echo "Error: 'nc' (netcat) is required but not installed." >&2
32
+ exit 1
33
+ fi
30
34
  while ! nc -z 127.0.0.1 8081 &>/dev/null; do sleep 0.2; done
31
35
  export NARGO_FOREIGN_CALL_TIMEOUT=300000
32
- nargo test --silence-warnings --oracle-resolver http://127.0.0.1:8081 --test-threads 16 "$@"
36
+ nargo test --silence-warnings --oracle-resolver http://127.0.0.1:8081 "$@"
33
37
  ;;
34
38
  start)
35
39
  if [ "${1:-}" == "--local-network" ]; then
package/scripts/init.sh CHANGED
@@ -16,11 +16,11 @@ Options:
16
16
  -h, --help Print help
17
17
 
18
18
  This command creates a new Aztec Noir project in the current directory with
19
- a workspace containing a contract crate and a test crate, and automatically
20
- adds the Aztec.nr dependency to both.
19
+ a workspace containing a Counter contract example with tests. The Counter
20
+ demonstrates private state, private functions, and utility reads.
21
21
 
22
- If a workspace already exists in the current directory, use
23
- 'aztec new <name>' instead to add another contract.
22
+ Use 'aztec new <name>' to create a blank contract project, or to add another
23
+ contract to an existing workspace.
24
24
  EOF
25
25
  exit 0
26
26
  ;;
@@ -36,4 +36,4 @@ done
36
36
  package_name="$(basename $(pwd))"
37
37
 
38
38
  echo "Initializing Aztec contract project..."
39
- $script_path/setup_workspace.sh "$package_name"
39
+ $script_path/setup_workspace.sh "$package_name" counter
package/scripts/new.sh CHANGED
@@ -68,7 +68,7 @@ fi
68
68
  if [ -f "Nargo.toml" ] && grep -q '\[workspace\]' Nargo.toml; then
69
69
  # Add crate pair to existing workspace
70
70
  echo "Adding contract '$package_name' to existing workspace..."
71
- $script_path/add_crate.sh "$package_name"
71
+ $script_path/add_crate.sh "$package_name" blank
72
72
  else
73
73
  # Create new workspace
74
74
  if [ -d "$project_path" ] && [ "$(ls -A $project_path 2>/dev/null)" ]; then
@@ -79,5 +79,5 @@ else
79
79
  echo "Creating new Aztec contract project at $project_path..."
80
80
  mkdir -p "$project_path"
81
81
  cd "$project_path"
82
- $script_path/setup_workspace.sh "$package_name"
82
+ $script_path/setup_workspace.sh "$package_name" blank
83
83
  fi
@@ -2,10 +2,11 @@
2
2
  set -euo pipefail
3
3
 
4
4
  # Creates an Aztec contract workspace with a contract crate and a test crate.
5
- # Usage: setup_workspace.sh <package_name>
5
+ # Usage: setup_workspace.sh <package_name> <template>
6
6
  # Must be called from the workspace root directory.
7
7
 
8
8
  package_name=$1
9
+ template=$2
9
10
  script_path=$(realpath $(dirname "$0"))
10
11
 
11
12
  if [ -z "$package_name" ]; then
@@ -26,7 +27,7 @@ members = []
26
27
  EOF
27
28
 
28
29
  # Create the first crate pair
29
- $script_path/add_crate.sh "$package_name"
30
+ $script_path/add_crate.sh "$package_name" "$template"
30
31
 
31
32
  # Create README
32
33
  cat > README.md << REOF
@@ -0,0 +1,6 @@
1
+ [package]
2
+ name = "__CRATE_NAME___contract"
3
+ type = "contract"
4
+
5
+ [dependencies]
6
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="aztec" }
@@ -0,0 +1,10 @@
1
+ use aztec::macros::aztec;
2
+
3
+ #[aztec]
4
+ pub contract Main {
5
+ use aztec::macros::functions::{external, initializer};
6
+
7
+ #[initializer]
8
+ #[external("private")]
9
+ fn constructor() {}
10
+ }
@@ -0,0 +1,7 @@
1
+ [package]
2
+ name = "__CRATE_NAME___test"
3
+ type = "lib"
4
+
5
+ [dependencies]
6
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="aztec" }
7
+ __CRATE_NAME___contract = { path = "../__CRATE_NAME___contract" }
@@ -0,0 +1,11 @@
1
+ use aztec::test::helpers::test_environment::TestEnvironment;
2
+ use __CRATE_NAME___contract::Main;
3
+
4
+ #[test]
5
+ unconstrained fn test_constructor() {
6
+ let mut env = TestEnvironment::new();
7
+ let deployer = env.create_light_account();
8
+
9
+ let _contract_address = env.deploy("@__CRATE_NAME___contract/Main")
10
+ .with_private_initializer(deployer, Main::interface().constructor());
11
+ }
@@ -0,0 +1,7 @@
1
+ [package]
2
+ name = "__CRATE_NAME___contract"
3
+ type = "contract"
4
+
5
+ [dependencies]
6
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="aztec" }
7
+ balance_set = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="balance-set" }
@@ -0,0 +1,48 @@
1
+ use aztec::macros::aztec;
2
+
3
+ #[aztec]
4
+ pub contract Counter {
5
+ use aztec::{
6
+ macros::{functions::{external, initializer}, storage::storage},
7
+ messages::delivery::MessageDelivery,
8
+ protocol::address::AztecAddress,
9
+ state_vars::Owned,
10
+ };
11
+ use balance_set::BalanceSet;
12
+
13
+ #[storage]
14
+ struct Storage<Context> {
15
+ // Each owner has their own counter, stored as private encrypted notes.
16
+ // Owned: dictates who will receive the encrypted notes.
17
+ // BalanceSet: manages the underlying notes, providing add/sub/balance_of.
18
+ counters: Owned<BalanceSet<Context>, Context>,
19
+ }
20
+
21
+ // Sets the owner's counter to an initial value.
22
+ //
23
+ // #[external("private")]: executes on the user's device, inputs are hidden from everyone.
24
+ #[initializer]
25
+ #[external("private")]
26
+ fn constructor(initial_value: u128, owner: AztecAddress) {
27
+ // Delivers the note to the recipient onchain.
28
+ // Without delivery, the recipient can't find or decrypt the note.
29
+ self.storage.counters.at(owner).add(initial_value).deliver(
30
+ MessageDelivery::onchain_unconstrained(),
31
+ );
32
+ }
33
+
34
+ // Adds 1 to the owner's counter.
35
+ #[external("private")]
36
+ fn increment(owner: AztecAddress) {
37
+ self.storage.counters.at(owner).add(1).deliver(MessageDelivery::onchain_unconstrained());
38
+ }
39
+
40
+ // Returns the current value of the owner's counter.
41
+ //
42
+ // #[external("utility")]: runs off-chain, no transaction created, no cost.
43
+ // Only the owner can decrypt and read their own counter.
44
+ #[external("utility")]
45
+ unconstrained fn get_counter(owner: AztecAddress) -> u128 {
46
+ self.storage.counters.at(owner).balance_of()
47
+ }
48
+ }
@@ -0,0 +1,7 @@
1
+ [package]
2
+ name = "__CRATE_NAME___test"
3
+ type = "lib"
4
+
5
+ [dependencies]
6
+ aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v__AZTEC_VERSION__", directory="aztec" }
7
+ __CRATE_NAME___contract = { path = "../__CRATE_NAME___contract" }
@@ -0,0 +1,32 @@
1
+ use aztec::{protocol::address::AztecAddress, test::helpers::test_environment::TestEnvironment};
2
+ use __CRATE_NAME___contract::Counter;
3
+
4
+ unconstrained fn setup(initial_value: u128) -> (TestEnvironment, AztecAddress, AztecAddress) {
5
+ let mut env = TestEnvironment::new();
6
+ let owner = env.create_light_account();
7
+
8
+ let contract_address = env.deploy("@__CRATE_NAME___contract/Counter")
9
+ .with_private_initializer(owner, Counter::interface().constructor(initial_value, owner));
10
+
11
+ (env, contract_address, owner)
12
+ }
13
+
14
+ #[test]
15
+ unconstrained fn test_constructor() {
16
+ let initial_value = 5;
17
+ let (env, contract_address, owner) = setup(initial_value);
18
+
19
+ let counter = env.execute_utility(Counter::at(contract_address).get_counter(owner));
20
+ assert_eq(counter, initial_value);
21
+ }
22
+
23
+ #[test]
24
+ unconstrained fn test_increment() {
25
+ let initial_value = 5;
26
+ let (mut env, contract_address, owner) = setup(initial_value);
27
+
28
+ env.call_private(owner, Counter::at(contract_address).increment(owner));
29
+
30
+ let counter = env.execute_utility(Counter::at(contract_address).get_counter(owner));
31
+ assert_eq(counter, initial_value + 1);
32
+ }
package/src/bin/index.ts CHANGED
@@ -18,6 +18,7 @@ import { Command } from 'commander';
18
18
  import { injectCompileCommand } from '../cli/cmds/compile.js';
19
19
  import { injectMigrateCommand } from '../cli/cmds/migrate_ha_db.js';
20
20
  import { injectProfileCommand } from '../cli/cmds/profile.js';
21
+ import { injectProverCommand } from '../cli/cmds/prover.js';
21
22
  import { injectAztecCommands } from '../cli/index.js';
22
23
 
23
24
  const NETWORK_FLAG = 'network';
@@ -47,7 +48,7 @@ async function main() {
47
48
  await enrichEnvironmentWithNetworkConfig(networkName);
48
49
  enrichEnvironmentWithChainName(networkName);
49
50
 
50
- const cliVersion = getPackageVersion() ?? 'unknown';
51
+ const cliVersion = getPackageVersion();
51
52
  let program = new Command('aztec');
52
53
  program.description('Aztec command line interface').version(cliVersion).enablePositionalOptions();
53
54
  program = injectAztecCommands(program, userLog, debugLogger);
@@ -61,6 +62,7 @@ async function main() {
61
62
  program = injectCompileCommand(program, userLog);
62
63
  program = injectProfileCommand(program, userLog);
63
64
  program = injectMigrateCommand(program, userLog);
65
+ program = injectProverCommand(program, userLog);
64
66
 
65
67
  await program.parseAsync(process.argv);
66
68
  }
@@ -1,3 +1,4 @@
1
+ import { registerAztecNodeRpcHandlers } from '@aztec/aztec-node';
1
2
  import { getActiveNetworkName } from '@aztec/foundation/config';
2
3
  import {
3
4
  type NamespacedApiHandlers,
@@ -7,10 +8,9 @@ import {
7
8
  } from '@aztec/foundation/json-rpc/server';
8
9
  import type { LogFn, Logger } from '@aztec/foundation/log';
9
10
  import type { ChainConfig } from '@aztec/stdlib/config';
10
- import { AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
11
11
  import { getPackageVersion } from '@aztec/stdlib/update-checker';
12
12
  import { getVersioningMiddleware } from '@aztec/stdlib/versioning';
13
- import { getOtelJsonRpcPropagationMiddleware } from '@aztec/telemetry-client';
13
+ import { getOtelJsonRpcDiagnosticsMiddleware, getOtelJsonRpcPropagationMiddleware } from '@aztec/telemetry-client';
14
14
 
15
15
  import { createLocalNetwork } from '../local-network/index.js';
16
16
  import { github, splash } from '../splash.js';
@@ -23,33 +23,26 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
23
23
  const signalHandlers: Array<() => Promise<void>> = [];
24
24
  const services: NamespacedApiHandlers = {};
25
25
  const adminServices: NamespacedApiHandlers = {};
26
+ const packageVersion = getPackageVersion();
26
27
  let config: ChainConfig | undefined = undefined;
27
28
 
28
29
  if (options.localNetwork) {
29
- const cliVersion = getPackageVersion() ?? 'unknown';
30
- const localNetwork = extractNamespacedOptions(options, 'local-network');
31
- localNetwork.testAccounts = true;
30
+ const localNetwork = extractNamespacedOptions(options, 'localNetwork');
32
31
  userLog(`${splash}\n${github}\n\n`);
33
- userLog(`Setting up Aztec local network ${cliVersion}, please stand by...`);
32
+ userLog(`Setting up Aztec local network ${packageVersion}, please stand by...`);
34
33
 
35
34
  const { node, stop } = await createLocalNetwork(
36
35
  {
37
36
  l1Mnemonic: localNetwork.l1Mnemonic,
38
37
  l1RpcUrls: options.l1RpcUrls,
39
38
  testAccounts: localNetwork.testAccounts,
40
- realProofs: false,
41
- // Setting the epoch duration to 2 by default for local network. This allows the epoch to be "proven" faster, so
42
- // the users can consume out hash without having to wait for a long time.
43
- // Note: We are not proving anything in the local network (realProofs == false). But in `createLocalNetwork`,
44
- // the EpochTestSettler will set the out hash to the outbox when an epoch is complete.
45
- aztecEpochDuration: 2,
46
39
  },
47
40
  userLog,
48
41
  );
49
42
 
50
43
  // Start Node and PXE JSON-RPC server
51
44
  signalHandlers.push(stop);
52
- services.node = [node, AztecNodeApiSchema];
45
+ registerAztecNodeRpcHandlers(node, services, adminServices, { debug: true });
53
46
  } else {
54
47
  // Route --prover-node through startNode
55
48
  if (options.proverNode && !options.node) {
@@ -63,9 +56,6 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
63
56
  } else if (options.bot) {
64
57
  const { startBot } = await import('./cmds/start_bot.js');
65
58
  await startBot(options, signalHandlers, services, userLog);
66
- } else if (options.archiver) {
67
- const { startArchiver } = await import('./cmds/start_archiver.js');
68
- ({ config } = await startArchiver(options, signalHandlers, services));
69
59
  } else if (options.p2pBootstrap) {
70
60
  const { startP2PBootstrap } = await import('./cmds/start_p2p_bootstrap.js');
71
61
  ({ config } = await startP2PBootstrap(options, signalHandlers, services, userLog));
@@ -77,7 +67,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
77
67
  await startProverBroker(options, signalHandlers, services, userLog);
78
68
  } else if (options.txe) {
79
69
  const { startTXE } = await import('./cmds/start_txe.js');
80
- await startTXE(options, debugLogger);
70
+ await startTXE(options, signalHandlers, debugLogger);
81
71
  } else if (options.sequencer) {
82
72
  userLog(`Cannot run a standalone sequencer without a node`);
83
73
  process.exit(1);
@@ -89,13 +79,21 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
89
79
 
90
80
  installSignalHandlers(debugLogger.info, signalHandlers);
91
81
  const versions = getVersions(config);
82
+ const versioningOpts = { packageVersion };
92
83
 
93
84
  // Start the main JSON-RPC server
94
85
  if (Object.entries(services).length > 0) {
86
+ if (services.aztec) {
87
+ const { BarretenbergSync } = await import('@aztec/bb.js');
88
+ // JSON-RPC schema parsing may decompress compressed Chonk proofs before the node handler runs.
89
+ await BarretenbergSync.initSingleton();
90
+ }
91
+
95
92
  const rpcServer = createNamespacedSafeJsonRpcServer(services, {
93
+ diagnostic: getOtelJsonRpcDiagnosticsMiddleware(),
96
94
  http200OnError: false,
97
95
  log: debugLogger,
98
- middlewares: [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions)],
96
+ middlewares: [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions, versioningOpts)],
99
97
  maxBatchSize: options.rpcMaxBatchSize,
100
98
  maxBodySizeBytes: options.rpcMaxBodySize,
101
99
  });
@@ -105,7 +103,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
105
103
 
106
104
  // If there are any admin services, start a separate JSON-RPC server for them
107
105
  if (Object.entries(adminServices).length > 0) {
108
- const adminMiddlewares = [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions)];
106
+ const adminMiddlewares = [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions, versioningOpts)];
109
107
 
110
108
  // Resolve the admin API key (auto-generated and persisted, or opt-out)
111
109
  const apiKeyResolution = await resolveAdminApiKey(
@@ -124,6 +122,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
124
122
  }
125
123
 
126
124
  const rpcServer = createNamespacedSafeJsonRpcServer(adminServices, {
125
+ diagnostic: getOtelJsonRpcDiagnosticsMiddleware(),
127
126
  http200OnError: false,
128
127
  log: debugLogger,
129
128
  middlewares: adminMiddlewares,
@@ -36,7 +36,7 @@ export interface AztecStartOption {
36
36
  parseVal?: (val: string) => any;
37
37
  }
38
38
 
39
- export const getOptions = (namespace: string, configMappings: Record<string, ConfigMapping>) => {
39
+ export const getOptions = (namespace: string, configMappings: Record<string, ConfigMapping<unknown>>) => {
40
40
  const options: AztecStartOption[] = [];
41
41
  for (const [key, { env, defaultValue: def, parseEnv, description, printDefault, fallback }] of Object.entries(
42
42
  configMappings,
@@ -58,7 +58,11 @@ export const getOptions = (namespace: string, configMappings: Record<string, Con
58
58
  return options;
59
59
  };
60
60
 
61
- const configToFlag = (flag: string, configMapping: ConfigMapping, overrideDefaultValue?: any): AztecStartOption => {
61
+ const configToFlag = (
62
+ flag: string,
63
+ configMapping: ConfigMapping<unknown>,
64
+ overrideDefaultValue?: any,
65
+ ): AztecStartOption => {
62
66
  if (!configMapping.isBoolean) {
63
67
  flag += ' <value>';
64
68
  }
@@ -105,7 +109,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
105
109
  env: 'NETWORK',
106
110
  },
107
111
 
108
- configToFlag('--enable-version-check', sharedNodeConfigMappings.enableVersionCheck),
112
+ configToFlag('--enable-auto-shutdown', sharedNodeConfigMappings.enableAutoShutdown),
109
113
 
110
114
  configToFlag('--sync-mode', sharedNodeConfigMappings.syncMode),
111
115
  configToFlag('--snapshots-urls', sharedNodeConfigMappings.snapshotsUrls),
@@ -125,6 +129,12 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
125
129
  defaultValue: DefaultMnemonic,
126
130
  env: 'MNEMONIC',
127
131
  },
132
+ {
133
+ flag: '--local-network.testAccounts',
134
+ description: 'Deploy test accounts on local network start',
135
+ env: 'TEST_ACCOUNTS',
136
+ ...booleanConfigHelper(true),
137
+ },
128
138
  ],
129
139
  API: [
130
140
  {
@@ -165,6 +175,13 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
165
175
  env: 'AZTEC_RESET_ADMIN_API_KEY',
166
176
  parseVal: val => val === 'true' || val === '1',
167
177
  },
178
+ {
179
+ flag: '--node-debug',
180
+ description: 'Expose debug endpoints (e.g. mineBlock) on the main RPC port',
181
+ defaultValue: false,
182
+ env: 'AZTEC_NODE_DEBUG',
183
+ parseVal: val => val === undefined || val === 'true' || val === '1',
184
+ },
168
185
  {
169
186
  flag: '--api-prefix <value>',
170
187
  description: 'Prefix for API routes on any service that is started',
@@ -205,12 +222,6 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
205
222
  },
206
223
  ],
207
224
  ARCHIVER: [
208
- {
209
- flag: '--archiver',
210
- description: 'Starts Aztec Archiver with options',
211
- defaultValue: undefined,
212
- env: undefined,
213
- },
214
225
  ...getOptions(
215
226
  'archiver',
216
227
  omitConfigMappings(archiverConfigMappings, Object.keys(l1ContractsConfigMappings) as (keyof ArchiverConfig)[]),
@@ -257,11 +268,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
257
268
  defaultValue: undefined,
258
269
  env: undefined,
259
270
  },
260
- ...getOptions(
261
- 'proverBroker',
262
- // filter out archiver options from prover node options as they're passed separately in --archiver
263
- proverBrokerConfigMappings,
264
- ),
271
+ ...getOptions('proverBroker', proverBrokerConfigMappings),
265
272
  ],
266
273
  'PROVER AGENT': [
267
274
  {
@@ -309,15 +316,7 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
309
316
  },
310
317
  ...getOptions('bot', botConfigMappings),
311
318
  ],
312
- PXE: [
313
- {
314
- flag: '--pxe',
315
- description: 'Starts Aztec PXE with options',
316
- defaultValue: undefined,
317
- env: undefined,
318
- },
319
- ...getOptions('pxe', allPxeConfigMappings),
320
- ],
319
+ PXE: [...getOptions('pxe', allPxeConfigMappings)],
321
320
  TXE: [
322
321
  {
323
322
  flag: '--txe',
@@ -1,4 +1,6 @@
1
+ import { findBbBinary } from '@aztec/bb.js';
1
2
  import type { LogFn } from '@aztec/foundation/log';
3
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
2
4
 
3
5
  import { execFileSync } from 'child_process';
4
6
  import type { Command } from 'commander';
@@ -8,9 +10,10 @@ import { join } from 'path';
8
10
  import { readArtifactFiles } from './utils/artifacts.js';
9
11
  import { needsRecompile } from './utils/needs_recompile.js';
10
12
  import { run } from './utils/spawn.js';
13
+ import { warnIfAztecVersionMismatch } from './utils/warn_if_aztec_version_mismatch.js';
11
14
 
12
- /** Returns paths to contract artifacts in the target directory. */
13
- async function collectContractArtifacts(): Promise<string[]> {
15
+ /** Returns contract artifacts in the target directory along with whether each has already been postprocessed. */
16
+ async function collectContractArtifacts(): Promise<ContractArtifactInfo[]> {
14
17
  let files;
15
18
  try {
16
19
  files = await readArtifactFiles('target');
@@ -20,18 +23,18 @@ async function collectContractArtifacts(): Promise<string[]> {
20
23
  }
21
24
  throw err;
22
25
  }
23
- return files.filter(f => Array.isArray(f.content.functions)).map(f => f.filePath);
26
+ return files
27
+ .filter(f => Array.isArray(f.content.functions))
28
+ .map(f => ({ filePath: f.filePath, transpiled: f.content.transpiled === true }));
24
29
  }
25
30
 
26
- /** Strips the `__aztec_nr_internals__` prefix from function names in contract artifacts. */
27
- async function stripInternalPrefixes(artifactPaths: string[]): Promise<void> {
31
+ /** Stamps the Aztec stack version into the contract artifacts. */
32
+ async function stampAztecVersion(artifactPaths: string[]): Promise<void> {
33
+ const version = getPackageVersion();
28
34
  for (const path of artifactPaths) {
29
35
  const artifact = JSON.parse(await readFile(path, 'utf-8'));
30
- for (const fn of artifact.functions) {
31
- if (typeof fn.name === 'string') {
32
- fn.name = fn.name.replace(/^__aztec_nr_internals__/, '');
33
- }
34
- }
36
+ // eslint-disable-next-line camelcase
37
+ artifact.aztec_version = version;
35
38
  await writeFile(path, JSON.stringify(artifact, null, 2) + '\n');
36
39
  }
37
40
  }
@@ -138,31 +141,36 @@ async function checkNoTestsInContracts(nargo: string, log: LogFn): Promise<void>
138
141
 
139
142
  /** Compiles Aztec Noir contracts and postprocesses artifacts. */
140
143
  async function compileAztecContract(nargoArgs: string[], log: LogFn): Promise<void> {
141
- if (!(await needsRecompile())) {
142
- log('No source changes detected, skipping compilation.');
143
- return;
144
- }
144
+ await warnIfAztecVersionMismatch(log);
145
145
 
146
146
  const nargo = process.env.NARGO ?? 'nargo';
147
- const bb = process.env.BB ?? 'bb';
147
+ const bb = process.env.BB ?? findBbBinary() ?? 'bb';
148
148
 
149
- await run(nargo, ['compile', ...nargoArgs]);
149
+ const shouldRecompile = await needsRecompile();
150
+ if (shouldRecompile) {
151
+ await run(nargo, ['compile', ...nargoArgs]);
150
152
 
151
- // Ensure contract crates contain no tests (tests belong in the test crate).
152
- await checkNoTestsInContracts(nargo, log);
153
+ // Ensure contract crates contain no tests (tests belong in the test crate).
154
+ await checkNoTestsInContracts(nargo, log);
155
+ }
153
156
 
154
- const artifacts = await collectContractArtifacts();
157
+ // Postprocess any untranspiled artifacts: those just produced by nargo above, and any left behind by a bare
158
+ // `nargo compile` run outside `aztec compile`.
159
+ const unprocessed = (await collectContractArtifacts()).filter(a => !a.transpiled).map(a => a.filePath);
155
160
 
156
- if (artifacts.length > 0) {
161
+ if (unprocessed.length > 0) {
157
162
  log('Postprocessing contracts...');
158
- const bbArgs = artifacts.flatMap(a => ['-i', a]);
163
+ const bbArgs = unprocessed.flatMap(a => ['-i', a]);
159
164
  await run(bb, ['aztec_process', ...bbArgs]);
160
165
 
161
- // TODO: This should be part of bb aztec_process!
162
- await stripInternalPrefixes(artifacts);
166
+ await stampAztecVersion(unprocessed);
163
167
  }
164
168
 
165
- log('Compilation complete!');
169
+ if (shouldRecompile || unprocessed.length > 0) {
170
+ log('Compilation complete!');
171
+ } else {
172
+ log('No source changes detected, skipping compilation.');
173
+ }
166
174
  }
167
175
 
168
176
  export function injectCompileCommand(program: Command, log: LogFn): Command {
@@ -188,3 +196,10 @@ export function injectCompileCommand(program: Command, log: LogFn): Command {
188
196
 
189
197
  return program;
190
198
  }
199
+
200
+ interface ContractArtifactInfo {
201
+ /** Path to the artifact JSON in the target directory. */
202
+ filePath: string;
203
+ /** Whether the artifact has already been transpiled and had its verification keys generated. */
204
+ transpiled: boolean;
205
+ }