@aztec/aztec 0.0.1-commit.7b97ef96e → 0.0.1-commit.7cbc774

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 (143) hide show
  1. package/dest/bin/index.js +4 -2
  2. package/dest/cli/admin_api_key_store.d.ts +3 -3
  3. package/dest/cli/admin_api_key_store.d.ts.map +1 -1
  4. package/dest/cli/admin_api_key_store.js +3 -3
  5. package/dest/cli/aztec_start_action.d.ts +1 -1
  6. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  7. package/dest/cli/aztec_start_action.js +33 -16
  8. package/dest/cli/aztec_start_options.d.ts +2 -2
  9. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  10. package/dest/cli/aztec_start_options.js +20 -20
  11. package/dest/cli/cli.js +3 -3
  12. package/dest/cli/cmds/compile.d.ts +1 -1
  13. package/dest/cli/cmds/compile.d.ts.map +1 -1
  14. package/dest/cli/cmds/compile.js +114 -43
  15. package/dest/cli/cmds/profile.d.ts +4 -0
  16. package/dest/cli/cmds/profile.d.ts.map +1 -0
  17. package/dest/cli/cmds/profile.js +8 -0
  18. package/dest/cli/cmds/profile_flamegraph.d.ts +4 -0
  19. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -0
  20. package/dest/cli/cmds/profile_flamegraph.js +52 -0
  21. package/dest/cli/cmds/profile_gates.d.ts +4 -0
  22. package/dest/cli/cmds/profile_gates.d.ts.map +1 -0
  23. package/dest/cli/cmds/profile_gates.js +76 -0
  24. package/dest/cli/cmds/profile_utils.d.ts +18 -0
  25. package/dest/cli/cmds/profile_utils.d.ts.map +1 -0
  26. package/dest/cli/cmds/profile_utils.js +50 -0
  27. package/dest/cli/cmds/standby.d.ts +30 -0
  28. package/dest/cli/cmds/standby.d.ts.map +1 -0
  29. package/dest/cli/cmds/standby.js +97 -0
  30. package/dest/cli/cmds/start_bot.d.ts +1 -1
  31. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  32. package/dest/cli/cmds/start_bot.js +3 -3
  33. package/dest/cli/cmds/start_node.d.ts +3 -2
  34. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  35. package/dest/cli/cmds/start_node.js +28 -40
  36. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  37. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  38. package/dest/cli/cmds/start_prover_agent.js +5 -17
  39. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  40. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  41. package/dest/cli/cmds/start_prover_broker.js +22 -13
  42. package/dest/cli/cmds/start_txe.d.ts +2 -2
  43. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  44. package/dest/cli/cmds/start_txe.js +6 -5
  45. package/dest/cli/cmds/utils/artifacts.d.ts +21 -0
  46. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -0
  47. package/dest/cli/cmds/utils/artifacts.js +24 -0
  48. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
  49. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
  50. package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
  51. package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
  52. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
  53. package/dest/cli/cmds/utils/needs_recompile.js +90 -0
  54. package/dest/cli/cmds/utils/spawn.d.ts +3 -0
  55. package/dest/cli/cmds/utils/spawn.d.ts.map +1 -0
  56. package/dest/cli/cmds/utils/spawn.js +16 -0
  57. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
  58. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
  59. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
  60. package/dest/cli/util.d.ts +3 -5
  61. package/dest/cli/util.d.ts.map +1 -1
  62. package/dest/cli/util.js +46 -85
  63. package/dest/examples/token.js +4 -4
  64. package/dest/local-network/auth_registry.d.ts +4 -0
  65. package/dest/local-network/auth_registry.d.ts.map +1 -0
  66. package/dest/local-network/auth_registry.js +15 -0
  67. package/dest/local-network/banana_fpc.d.ts +1 -1
  68. package/dest/local-network/banana_fpc.d.ts.map +1 -1
  69. package/dest/local-network/banana_fpc.js +9 -7
  70. package/dest/local-network/local-network.d.ts +5 -28
  71. package/dest/local-network/local-network.d.ts.map +1 -1
  72. package/dest/local-network/local-network.js +44 -17
  73. package/dest/testing/anvil_test_watcher.d.ts +15 -3
  74. package/dest/testing/anvil_test_watcher.d.ts.map +1 -1
  75. package/dest/testing/anvil_test_watcher.js +68 -14
  76. package/dest/testing/cheat_codes.d.ts +18 -17
  77. package/dest/testing/cheat_codes.d.ts.map +1 -1
  78. package/dest/testing/cheat_codes.js +72 -36
  79. package/dest/testing/epoch_test_settler.d.ts +1 -1
  80. package/dest/testing/epoch_test_settler.d.ts.map +1 -1
  81. package/dest/testing/epoch_test_settler.js +9 -8
  82. package/dest/testing/index.d.ts +3 -2
  83. package/dest/testing/index.d.ts.map +1 -1
  84. package/dest/testing/index.js +1 -0
  85. package/dest/testing/token_allowed_setup.d.ts +7 -0
  86. package/dest/testing/token_allowed_setup.d.ts.map +1 -0
  87. package/dest/testing/token_allowed_setup.js +20 -0
  88. package/package.json +35 -34
  89. package/scripts/add_crate.sh +53 -0
  90. package/scripts/aztec.sh +15 -4
  91. package/scripts/init.sh +23 -19
  92. package/scripts/new.sh +48 -24
  93. package/scripts/setup_workspace.sh +69 -0
  94. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  95. package/scripts/templates/blank/contract/src/main.nr +10 -0
  96. package/scripts/templates/blank/test/Nargo.toml +7 -0
  97. package/scripts/templates/blank/test/src/lib.nr +11 -0
  98. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  99. package/scripts/templates/counter/contract/src/main.nr +48 -0
  100. package/scripts/templates/counter/test/Nargo.toml +7 -0
  101. package/scripts/templates/counter/test/src/lib.nr +32 -0
  102. package/src/bin/index.ts +4 -2
  103. package/src/cli/admin_api_key_store.ts +4 -4
  104. package/src/cli/aztec_start_action.ts +22 -16
  105. package/src/cli/aztec_start_options.ts +27 -28
  106. package/src/cli/cli.ts +3 -3
  107. package/src/cli/cmds/compile.ts +129 -44
  108. package/src/cli/cmds/profile.ts +26 -0
  109. package/src/cli/cmds/profile_flamegraph.ts +64 -0
  110. package/src/cli/cmds/profile_gates.ts +84 -0
  111. package/src/cli/cmds/profile_utils.ts +58 -0
  112. package/src/cli/cmds/standby.ts +132 -0
  113. package/src/cli/cmds/start_bot.ts +3 -5
  114. package/src/cli/cmds/start_node.ts +43 -39
  115. package/src/cli/cmds/start_prover_agent.ts +5 -8
  116. package/src/cli/cmds/start_prover_broker.ts +23 -24
  117. package/src/cli/cmds/start_txe.ts +7 -5
  118. package/src/cli/cmds/utils/artifacts.ts +44 -0
  119. package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
  120. package/src/cli/cmds/utils/needs_recompile.ts +98 -0
  121. package/src/cli/cmds/utils/spawn.ts +16 -0
  122. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
  123. package/src/cli/util.ts +49 -82
  124. package/src/examples/token.ts +6 -4
  125. package/src/local-network/auth_registry.ts +14 -0
  126. package/src/local-network/banana_fpc.ts +5 -8
  127. package/src/local-network/local-network.ts +43 -14
  128. package/src/testing/anvil_test_watcher.ts +76 -13
  129. package/src/testing/cheat_codes.ts +92 -39
  130. package/src/testing/epoch_test_settler.ts +6 -8
  131. package/src/testing/index.ts +2 -1
  132. package/src/testing/token_allowed_setup.ts +19 -0
  133. package/dest/cli/cmds/start_archiver.d.ts +0 -9
  134. package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
  135. package/dest/cli/cmds/start_archiver.js +0 -48
  136. package/dest/cli/release_version.d.ts +0 -2
  137. package/dest/cli/release_version.d.ts.map +0 -1
  138. package/dest/cli/release_version.js +0 -14
  139. package/scripts/extract_function.js +0 -47
  140. package/scripts/flamegraph.sh +0 -59
  141. package/scripts/setup_project.sh +0 -31
  142. package/src/cli/cmds/start_archiver.ts +0 -50
  143. package/src/cli/release_version.ts +0 -21
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Creates a contract+test crate pair and adds them to an existing workspace.
5
+ # Usage: add_crate.sh <crate_name> <template>
6
+ # Must be called from a workspace root that already has Nargo.toml with [workspace].
7
+
8
+ crate_name=$1
9
+ template=$2
10
+
11
+ if [ -z "$crate_name" ]; then
12
+ echo "Error: crate name is required"
13
+ exit 1
14
+ fi
15
+
16
+ if [[ "$crate_name" == *"/"* ]] || [[ "$crate_name" == *"\\"* ]]; then
17
+ echo "Error: crate name must not contain path separators"
18
+ exit 1
19
+ fi
20
+
21
+ contract_dir="${crate_name}_contract"
22
+ test_dir="${crate_name}_test"
23
+
24
+ if [ -d "$contract_dir" ]; then
25
+ echo "Error: directory '$contract_dir' already exists"
26
+ exit 1
27
+ fi
28
+ if [ -d "$test_dir" ]; then
29
+ echo "Error: directory '$test_dir' already exists"
30
+ exit 1
31
+ fi
32
+
33
+ # Get the actual aztec version for the git tag.
34
+ AZTEC_VERSION=$(jq -r '.version' $(dirname $0)/../package.json)
35
+ TEMPLATE_DIR="$(dirname $0)/templates/$template"
36
+
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" {} +
43
+
44
+ # Add members to workspace Nargo.toml
45
+ if grep -q 'members\s*=\s*\[\s*\]' Nargo.toml; then
46
+ # Empty array: members = []
47
+ perl -i -pe "s|members\s*=\s*\[\s*\]|members = [\"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
48
+ else
49
+ # Non-empty array: add before closing ]
50
+ perl -i -pe "s|(members\s*=\s*\[.*)\]|\1, \"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml
51
+ fi
52
+
53
+ echo "Created crates '${contract_dir}' and '${test_dir}'"
package/scripts/aztec.sh CHANGED
@@ -20,13 +20,20 @@ function aztec {
20
20
 
21
21
  case $cmd in
22
22
  test)
23
- export LOG_LEVEL="${LOG_LEVEL:-"error;trace:contract_log"}"
23
+ # Attempt to compile, no-op if there are no changes
24
+ node --no-warnings "$script_dir/../dest/bin/index.js" compile
25
+
26
+ export LOG_LEVEL="${LOG_LEVEL:-"error;trace:^contract:"}"
24
27
  aztec start --txe --port 8081 &
25
28
  server_pid=$!
26
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
27
34
  while ! nc -z 127.0.0.1 8081 &>/dev/null; do sleep 0.2; done
28
35
  export NARGO_FOREIGN_CALL_TIMEOUT=300000
29
- 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 "$@"
30
37
  ;;
31
38
  start)
32
39
  if [ "${1:-}" == "--local-network" ]; then
@@ -46,16 +53,20 @@ case $cmd in
46
53
  export ETHEREUM_HOSTS=${ETHEREUM_HOSTS:-"http://127.0.0.1:${ANVIL_PORT}"}
47
54
 
48
55
  anvil --version
49
- anvil --silent &
56
+ anvil --silent --port "$ANVIL_PORT" &
50
57
  anvil_pid=$!
51
58
  trap 'kill $anvil_pid &>/dev/null' EXIT
52
59
  fi
53
60
 
54
61
  aztec start "$@"
55
62
  ;;
56
- new|init|flamegraph)
63
+ new|init)
57
64
  $script_dir/${cmd}.sh "$@"
58
65
  ;;
66
+ flamegraph)
67
+ echo "Warning: 'aztec flamegraph' is deprecated. Use 'aztec profile flamegraph' instead." >&2
68
+ aztec profile flamegraph "$@"
69
+ ;;
59
70
  *)
60
71
  aztec $cmd "$@"
61
72
  ;;
package/scripts/init.sh CHANGED
@@ -1,35 +1,39 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
 
4
- NARGO=${NARGO:-nargo}
5
4
  script_path=$(realpath $(dirname "$0"))
6
5
 
7
- for arg in "$@"; do
8
- if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]; then
9
- cat << 'EOF'
6
+ # Parse arguments
7
+ while [[ $# -gt 0 ]]; do
8
+ case $1 in
9
+ --help|-h)
10
+ cat << 'EOF'
10
11
  Aztec Init - Create a new Aztec Noir project in the current directory
11
12
 
12
- Usage: aztec init [OPTIONS]
13
+ Usage: aztec init
13
14
 
14
15
  Options:
15
- --name <NAME> Name of the package [default: current directory name]
16
- --lib Use a library template
17
16
  -h, --help Print help
18
17
 
19
- This command creates a new Aztec Noir project in the current directory using nargo
20
- and automatically adds the Aztec.nr dependency to your Nargo.toml file.
18
+ This command creates a new Aztec Noir project in the current directory with
19
+ a workspace containing a Counter contract example with tests. The Counter
20
+ demonstrates private state, private functions, and utility reads.
21
21
 
22
+ Use 'aztec new <name>' to create a blank contract project, or to add another
23
+ contract to an existing workspace.
22
24
  EOF
23
- exit 0
24
- fi
25
- if [ "$arg" == "--lib" ]; then
26
- is_contract=0
27
- fi
25
+ exit 0
26
+ ;;
27
+ *)
28
+ echo "Error: unexpected argument '$1'"
29
+ echo "Usage: aztec init"
30
+ echo "Run 'aztec init --help' for more information"
31
+ exit 1
32
+ ;;
33
+ esac
28
34
  done
29
35
 
30
- echo "Initializing Noir project..."
31
- $NARGO init "$@"
36
+ package_name="$(basename $(pwd))"
32
37
 
33
- if [ "${is_contract:-1}" -eq 1 ]; then
34
- $script_path/setup_project.sh
35
- fi
38
+ echo "Initializing Aztec contract project..."
39
+ $script_path/setup_workspace.sh "$package_name" counter
package/scripts/new.sh CHANGED
@@ -1,59 +1,83 @@
1
1
  #!/usr/bin/env bash
2
2
  set -euo pipefail
3
3
 
4
- NARGO=${NARGO:-nargo}
5
4
  script_path=$(realpath $(dirname "$0"))
6
5
 
7
- type_arg="--contract"
6
+ project_path=""
8
7
 
9
8
  while [[ $# -gt 0 ]]; do
10
9
  case $1 in
11
10
  --help|-h)
12
11
  cat << 'EOF'
13
- Aztec New - Create a new Aztec Noir project in a new directory
12
+ Aztec New - Create a new Aztec Noir project or add a contract to an existing workspace
14
13
 
15
- Usage: aztec new [OPTIONS] <PATH>
14
+ Usage: aztec new <NAME>
16
15
 
17
16
  Arguments:
18
- <PATH> The path to save the new project
17
+ <NAME> The name for the new contract (also used as the directory name when
18
+ creating a new workspace)
19
19
 
20
20
  Options:
21
- --name <NAME> Name of the package [default: package directory name]
22
- --lib Create a library template instead of a contract
23
21
  -h, --help Print help
24
22
 
25
- This command creates a new Aztec Noir project using nargo and automatically
26
- adds the Aztec.nr dependency to your Nargo.toml file.
23
+ When run outside an existing workspace:
24
+ Creates a new directory with a workspace containing a contract crate and a
25
+ test crate, and automatically adds the Aztec.nr dependency to both.
26
+
27
+ When run inside an existing workspace (Nargo.toml with [workspace] exists):
28
+ Adds a new contract crate and test crate to the existing workspace.
27
29
  EOF
28
30
  exit 0
29
31
  ;;
30
- --lib)
31
- type_arg="--lib"
32
- shift
33
- ;;
34
- --name)
35
- name_arg="--name $2"
36
- shift 2
32
+ -*)
33
+ echo "Error: unknown option '$1'"
34
+ echo "Usage: aztec new <NAME>"
35
+ echo "Run 'aztec new --help' for more information"
36
+ exit 1
37
37
  ;;
38
38
  *)
39
+ if [ -n "$project_path" ]; then
40
+ echo "Error: unexpected argument '$1'"
41
+ echo "Usage: aztec new <NAME>"
42
+ echo "Run 'aztec new --help' for more information"
43
+ exit 1
44
+ fi
39
45
  project_path=$1
40
46
  shift
41
- break
42
47
  ;;
43
48
  esac
44
49
  done
45
50
 
46
51
  if [ -z "$project_path" ]; then
47
- echo "Error: PATH argument is required"
48
- echo "Usage: aztec new [OPTIONS] <PATH>"
52
+ echo "Error: NAME argument is required"
53
+ echo "Usage: aztec new <NAME>"
49
54
  echo "Run 'aztec new --help' for more information"
50
55
  exit 1
51
56
  fi
52
57
 
53
- echo "Creating new Noir project at $project_path..."
54
- $NARGO new $type_arg ${name_arg:-} $project_path
58
+ package_name="$(basename $project_path)"
59
+
60
+ # Validate that the name contains only valid Noir identifier characters
61
+ if ! [[ "$package_name" =~ ^[a-zA-Z][a-zA-Z0-9_]*$ ]]; then
62
+ echo "Error: '$package_name' is not a valid contract name"
63
+ echo "Name must start with a letter and contain only letters, digits, and underscores"
64
+ exit 1
65
+ fi
66
+
67
+ # Check if we're inside an existing workspace
68
+ if [ -f "Nargo.toml" ] && grep -q '\[workspace\]' Nargo.toml; then
69
+ # Add crate pair to existing workspace
70
+ echo "Adding contract '$package_name' to existing workspace..."
71
+ $script_path/add_crate.sh "$package_name" blank
72
+ else
73
+ # Create new workspace
74
+ if [ -d "$project_path" ] && [ "$(ls -A $project_path 2>/dev/null)" ]; then
75
+ echo "Error: $project_path already exists and is not empty"
76
+ exit 1
77
+ fi
55
78
 
56
- if [ "$type_arg" == "--contract" ]; then
57
- cd $project_path
58
- $script_path/setup_project.sh
79
+ echo "Creating new Aztec contract project at $project_path..."
80
+ mkdir -p "$project_path"
81
+ cd "$project_path"
82
+ $script_path/setup_workspace.sh "$package_name" blank
59
83
  fi
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ # Creates an Aztec contract workspace with a contract crate and a test crate.
5
+ # Usage: setup_workspace.sh <package_name> <template>
6
+ # Must be called from the workspace root directory.
7
+
8
+ package_name=$1
9
+ template=$2
10
+ script_path=$(realpath $(dirname "$0"))
11
+
12
+ if [ -z "$package_name" ]; then
13
+ echo "Error: package name is required"
14
+ exit 1
15
+ fi
16
+
17
+ if [ -f "Nargo.toml" ]; then
18
+ echo "Error: Nargo.toml already exists in the current directory."
19
+ echo "To add another contract crate to this workspace, use 'aztec new <name>' instead."
20
+ exit 1
21
+ fi
22
+
23
+ # Create workspace root Nargo.toml with empty members (add_crate.sh will populate)
24
+ cat > Nargo.toml << 'EOF'
25
+ [workspace]
26
+ members = []
27
+ EOF
28
+
29
+ # Create the first crate pair
30
+ $script_path/add_crate.sh "$package_name" "$template"
31
+
32
+ # Create README
33
+ cat > README.md << REOF
34
+ # ${package_name}
35
+
36
+ An Aztec Noir contract project.
37
+
38
+ ## Compile
39
+
40
+ \`\`\`bash
41
+ aztec compile
42
+ \`\`\`
43
+
44
+ This compiles all contract crates and outputs artifacts to \`target/\`.
45
+
46
+ ## Test
47
+
48
+ \`\`\`bash
49
+ aztec test
50
+ \`\`\`
51
+
52
+ This runs all tests in the workspace.
53
+
54
+ ## Generate TypeScript bindings
55
+
56
+ \`\`\`bash
57
+ aztec codegen target -o src/artifacts
58
+ \`\`\`
59
+
60
+ This generates TypeScript contract artifacts from the compiled output in \`target/\` into \`src/artifacts/\`.
61
+ REOF
62
+
63
+ # Create .gitignore
64
+ cat > .gitignore << 'GEOF'
65
+ target/
66
+ codegenCache.json
67
+ GEOF
68
+
69
+ echo "Created Aztec contract workspace with crates '${package_name}_contract' and '${package_name}_test'"
@@ -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::message_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 with provable correctness.
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_constrained(),
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_constrained());
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
@@ -11,13 +11,14 @@ import { injectCommands as injectMiscCommands } from '@aztec/cli/misc';
11
11
  import { injectCommands as injectValidatorKeysCommands } from '@aztec/cli/validator_keys';
12
12
  import { getActiveNetworkName } from '@aztec/foundation/config';
13
13
  import { createConsoleLogger, createLogger } from '@aztec/foundation/log';
14
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
14
15
 
15
16
  import { Command } from 'commander';
16
17
 
17
18
  import { injectCompileCommand } from '../cli/cmds/compile.js';
18
19
  import { injectMigrateCommand } from '../cli/cmds/migrate_ha_db.js';
20
+ import { injectProfileCommand } from '../cli/cmds/profile.js';
19
21
  import { injectAztecCommands } from '../cli/index.js';
20
- import { getCliVersion } from '../cli/release_version.js';
21
22
 
22
23
  const NETWORK_FLAG = 'network';
23
24
 
@@ -46,7 +47,7 @@ async function main() {
46
47
  await enrichEnvironmentWithNetworkConfig(networkName);
47
48
  enrichEnvironmentWithChainName(networkName);
48
49
 
49
- const cliVersion = getCliVersion();
50
+ const cliVersion = getPackageVersion();
50
51
  let program = new Command('aztec');
51
52
  program.description('Aztec command line interface').version(cliVersion).enablePositionalOptions();
52
53
  program = injectAztecCommands(program, userLog, debugLogger);
@@ -58,6 +59,7 @@ async function main() {
58
59
  program = injectMiscCommands(program, userLog);
59
60
  program = injectValidatorKeysCommands(program, userLog);
60
61
  program = injectCompileCommand(program, userLog);
62
+ program = injectProfileCommand(program, userLog);
61
63
  program = injectMigrateCommand(program, userLog);
62
64
 
63
65
  await program.parseAsync(process.argv);
@@ -28,7 +28,7 @@ export interface ResolveAdminApiKeyOptions {
28
28
  /** SHA-256 hex hash of a pre-generated API key. When set, the node uses this hash directly. */
29
29
  adminApiKeyHash?: string;
30
30
  /** If true, disable admin API key auth entirely. */
31
- noAdminApiKey?: boolean;
31
+ disableAdminApiKey?: boolean;
32
32
  /** If true, force-generate a new key even if one is already persisted. */
33
33
  resetAdminApiKey?: boolean;
34
34
  /** Root data directory for persistent storage. */
@@ -39,7 +39,7 @@ export interface ResolveAdminApiKeyOptions {
39
39
  * Resolves the admin API key for the admin RPC endpoint.
40
40
  *
41
41
  * Strategy:
42
- * 1. If opt-out flag is set (`noAdminApiKey`), return undefined (no auth).
42
+ * 1. If opt-out flag is set (`disableAdminApiKey`), return undefined (no auth).
43
43
  * 2. If a pre-generated hash is provided (`adminApiKeyHash`), use it directly.
44
44
  * 3. If a data directory exists, look for a persisted hash file
45
45
  * at `<dataDirectory>/admin/api_key_hash`:
@@ -58,8 +58,8 @@ export async function resolveAdminApiKey(
58
58
  log: Logger,
59
59
  ): Promise<AdminApiKeyResolution | undefined> {
60
60
  // Operator explicitly opted out of admin auth
61
- if (options.noAdminApiKey) {
62
- log.warn('Admin API key authentication is DISABLED (--no-admin-api-key / AZTEC_NO_ADMIN_API_KEY)');
61
+ if (options.disableAdminApiKey) {
62
+ log.warn('Admin API key authentication is DISABLED (--disable-admin-api-key / AZTEC_DISABLE_ADMIN_API_KEY)');
63
63
  return undefined;
64
64
  }
65
65
 
@@ -1,3 +1,4 @@
1
+ import { getActiveNetworkName } from '@aztec/foundation/config';
1
2
  import {
2
3
  type NamespacedApiHandlers,
3
4
  createNamespacedSafeJsonRpcServer,
@@ -6,14 +7,14 @@ import {
6
7
  } from '@aztec/foundation/json-rpc/server';
7
8
  import type { LogFn, Logger } from '@aztec/foundation/log';
8
9
  import type { ChainConfig } from '@aztec/stdlib/config';
9
- import { AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
10
+ import { AztecNodeAdminApiSchema, AztecNodeApiSchema, AztecNodeDebugApiSchema } from '@aztec/stdlib/interfaces/client';
11
+ import { getPackageVersion } from '@aztec/stdlib/update-checker';
10
12
  import { getVersioningMiddleware } from '@aztec/stdlib/versioning';
11
- import { getOtelJsonRpcPropagationMiddleware } from '@aztec/telemetry-client';
13
+ import { getOtelJsonRpcDiagnosticsMiddleware, getOtelJsonRpcPropagationMiddleware } from '@aztec/telemetry-client';
12
14
 
13
15
  import { createLocalNetwork } from '../local-network/index.js';
14
16
  import { github, splash } from '../splash.js';
15
17
  import { resolveAdminApiKey } from './admin_api_key_store.js';
16
- import { getCliVersion } from './release_version.js';
17
18
  import { extractNamespacedOptions, installSignalHandlers } from './util.js';
18
19
  import { getVersions } from './versioning.js';
19
20
 
@@ -22,14 +23,13 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
22
23
  const signalHandlers: Array<() => Promise<void>> = [];
23
24
  const services: NamespacedApiHandlers = {};
24
25
  const adminServices: NamespacedApiHandlers = {};
26
+ const packageVersion = getPackageVersion();
25
27
  let config: ChainConfig | undefined = undefined;
26
28
 
27
29
  if (options.localNetwork) {
28
- const cliVersion = getCliVersion();
29
- const localNetwork = extractNamespacedOptions(options, 'local-network');
30
- localNetwork.testAccounts = true;
30
+ const localNetwork = extractNamespacedOptions(options, 'localNetwork');
31
31
  userLog(`${splash}\n${github}\n\n`);
32
- userLog(`Setting up Aztec local network ${cliVersion}, please stand by...`);
32
+ userLog(`Setting up Aztec local network ${packageVersion}, please stand by...`);
33
33
 
34
34
  const { node, stop } = await createLocalNetwork(
35
35
  {
@@ -49,6 +49,8 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
49
49
  // Start Node and PXE JSON-RPC server
50
50
  signalHandlers.push(stop);
51
51
  services.node = [node, AztecNodeApiSchema];
52
+ adminServices.node = [node, AztecNodeAdminApiSchema];
53
+ services.nodeDebug = [node, AztecNodeDebugApiSchema];
52
54
  } else {
53
55
  // Route --prover-node through startNode
54
56
  if (options.proverNode && !options.node) {
@@ -57,13 +59,14 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
57
59
 
58
60
  if (options.node) {
59
61
  const { startNode } = await import('./cmds/start_node.js');
60
- ({ config } = await startNode(options, signalHandlers, services, adminServices, userLog));
62
+ const networkName = getActiveNetworkName(options.network);
63
+ ({ config } = await startNode(options, signalHandlers, services, adminServices, userLog, networkName));
64
+ if (options.nodeDebug && services.node) {
65
+ services.nodeDebug = [services.node[0], AztecNodeDebugApiSchema];
66
+ }
61
67
  } else if (options.bot) {
62
68
  const { startBot } = await import('./cmds/start_bot.js');
63
69
  await startBot(options, signalHandlers, services, userLog);
64
- } else if (options.archiver) {
65
- const { startArchiver } = await import('./cmds/start_archiver.js');
66
- ({ config } = await startArchiver(options, signalHandlers, services));
67
70
  } else if (options.p2pBootstrap) {
68
71
  const { startP2PBootstrap } = await import('./cmds/start_p2p_bootstrap.js');
69
72
  ({ config } = await startP2PBootstrap(options, signalHandlers, services, userLog));
@@ -75,7 +78,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
75
78
  await startProverBroker(options, signalHandlers, services, userLog);
76
79
  } else if (options.txe) {
77
80
  const { startTXE } = await import('./cmds/start_txe.js');
78
- await startTXE(options, debugLogger);
81
+ await startTXE(options, signalHandlers, debugLogger);
79
82
  } else if (options.sequencer) {
80
83
  userLog(`Cannot run a standalone sequencer without a node`);
81
84
  process.exit(1);
@@ -87,13 +90,15 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
87
90
 
88
91
  installSignalHandlers(debugLogger.info, signalHandlers);
89
92
  const versions = getVersions(config);
93
+ const versioningOpts = { packageVersion };
90
94
 
91
95
  // Start the main JSON-RPC server
92
96
  if (Object.entries(services).length > 0) {
93
97
  const rpcServer = createNamespacedSafeJsonRpcServer(services, {
98
+ diagnostic: getOtelJsonRpcDiagnosticsMiddleware(),
94
99
  http200OnError: false,
95
100
  log: debugLogger,
96
- middlewares: [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions)],
101
+ middlewares: [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions, versioningOpts)],
97
102
  maxBatchSize: options.rpcMaxBatchSize,
98
103
  maxBodySizeBytes: options.rpcMaxBodySize,
99
104
  });
@@ -103,13 +108,13 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
103
108
 
104
109
  // If there are any admin services, start a separate JSON-RPC server for them
105
110
  if (Object.entries(adminServices).length > 0) {
106
- const adminMiddlewares = [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions)];
111
+ const adminMiddlewares = [getOtelJsonRpcPropagationMiddleware(), getVersioningMiddleware(versions, versioningOpts)];
107
112
 
108
113
  // Resolve the admin API key (auto-generated and persisted, or opt-out)
109
114
  const apiKeyResolution = await resolveAdminApiKey(
110
115
  {
111
116
  adminApiKeyHash: options.adminApiKeyHash,
112
- noAdminApiKey: options.noAdminApiKey,
117
+ disableAdminApiKey: options.disableAdminApiKey,
113
118
  resetAdminApiKey: options.resetAdminApiKey,
114
119
  dataDirectory: options.dataDirectory,
115
120
  },
@@ -122,6 +127,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
122
127
  }
123
128
 
124
129
  const rpcServer = createNamespacedSafeJsonRpcServer(adminServices, {
130
+ diagnostic: getOtelJsonRpcDiagnosticsMiddleware(),
125
131
  http200OnError: false,
126
132
  log: debugLogger,
127
133
  middlewares: adminMiddlewares,
@@ -148,7 +154,7 @@ export async function aztecStart(options: any, userLog: LogFn, debugLogger: Logg
148
154
  userLog(' The key hash has been persisted — on next restart, the same key will be used.');
149
155
  }
150
156
  userLog('');
151
- userLog(' To disable admin auth: --no-admin-api-key or AZTEC_NO_ADMIN_API_KEY=true');
157
+ userLog(' To disable admin auth: --disable-admin-api-key or AZTEC_DISABLE_ADMIN_API_KEY=true');
152
158
  userLog(separator);
153
159
  userLog('');
154
160
  }