From 543a9e0b384c4c738f187fbc0b44022ac4c27427 Mon Sep 17 00:00:00 2001 From: benesjan Date: Mon, 2 Mar 2026 16:27:08 +0000 Subject: [PATCH 1/6] feat: aztec new supporting multiple contract crates --- aztec-up/test/counter_contract.sh | 24 ++--- aztec-up/test/default_scaffold.sh | 42 ++++++-- noir-projects/noir-contracts/Nargo.toml | 2 +- .../contracts/test/counter/Nargo.toml | 2 + .../counter_contract}/Nargo.toml | 0 .../counter_contract}/src/main.nr | 0 .../test => counter/counter_test}/Nargo.toml | 2 +- .../test => counter/counter_test}/src/lib.nr | 0 .../test/counter_contract/Nargo.toml | 2 - yarn-project/aztec/scripts/add_crate.sh | 102 ++++++++++++++++++ yarn-project/aztec/scripts/init.sh | 3 + yarn-project/aztec/scripts/new.sh | 50 +++++---- yarn-project/aztec/scripts/setup_workspace.sh | 76 ++----------- yarn-project/aztec/src/cli/cli.ts | 4 +- 14 files changed, 200 insertions(+), 109 deletions(-) create mode 100644 noir-projects/noir-contracts/contracts/test/counter/Nargo.toml rename noir-projects/noir-contracts/contracts/test/{counter_contract/contract => counter/counter_contract}/Nargo.toml (100%) rename noir-projects/noir-contracts/contracts/test/{counter_contract/contract => counter/counter_contract}/src/main.nr (100%) rename noir-projects/noir-contracts/contracts/test/{counter_contract/test => counter/counter_test}/Nargo.toml (81%) rename noir-projects/noir-contracts/contracts/test/{counter_contract/test => counter/counter_test}/src/lib.nr (100%) delete mode 100644 noir-projects/noir-contracts/contracts/test/counter_contract/Nargo.toml create mode 100755 yarn-project/aztec/scripts/add_crate.sh diff --git a/aztec-up/test/counter_contract.sh b/aztec-up/test/counter_contract.sh index c4ce76350d56..c95bed113ee9 100755 --- a/aztec-up/test/counter_contract.sh +++ b/aztec-up/test/counter_contract.sh @@ -4,38 +4,38 @@ set -euo pipefail export LOG_LEVEL=silent # Execute commands as per: https://docs.aztec.network/tutorials/codealong/contract_tutorials/counter_contract -aztec new counter_contract +aztec new counter # Verify workspace structure -if [ ! -f counter_contract/Nargo.toml ]; then +if [ ! -f counter/Nargo.toml ]; then echo "Failed to create workspace Nargo.toml." exit 1 fi -if [ ! -f counter_contract/contract/Nargo.toml ] || [ ! -f counter_contract/contract/src/main.nr ]; then +if [ ! -f counter/counter_contract/Nargo.toml ] || [ ! -f counter/counter_contract/src/main.nr ]; then echo "Failed to create contract crate." exit 1 fi -if [ ! -f counter_contract/test/Nargo.toml ] || [ ! -f counter_contract/test/src/lib.nr ]; then +if [ ! -f counter/counter_test/Nargo.toml ] || [ ! -f counter/counter_test/src/lib.nr ]; then echo "Failed to create test crate." exit 1 fi -# Check counter_contract dir is owned by ubuntu. -if [ "$(stat -c %U counter_contract)" != "ubuntu" ]; then - echo "counter_contract dir is not owned by ubuntu." +# Check counter dir is owned by ubuntu. +if [ "$(stat -c %U counter)" != "ubuntu" ]; then + echo "counter dir is not owned by ubuntu." exit 1 fi # "Write" our contract over the scaffold. -cp -Rf ./aztec-packages/noir-projects/noir-contracts/contracts/test/counter_contract/* counter_contract/ -cd counter_contract -sed -i 's|\.\./\.\./\.\./\.\./\.\./|/home/ubuntu/aztec-packages/noir-projects/|g' contract/Nargo.toml test/Nargo.toml +cp -Rf ./aztec-packages/noir-projects/noir-contracts/contracts/test/counter/* counter/ +cd counter +sed -i 's|\.\./\.\./\.\./\.\./\.\./|/home/ubuntu/aztec-packages/noir-projects/|g' counter_contract/Nargo.toml counter_test/Nargo.toml # Compile the contract. aztec compile # Codegen -aztec codegen -o contract/src/artifacts target -if [ ! -d contract/src/artifacts ]; then +aztec codegen -o counter_contract/src/artifacts target +if [ ! -d counter_contract/src/artifacts ]; then echo "Failed to codegen TypeScript." exit 1 fi diff --git a/aztec-up/test/default_scaffold.sh b/aztec-up/test/default_scaffold.sh index d652bdbf8326..8b55c1d1ca93 100755 --- a/aztec-up/test/default_scaffold.sh +++ b/aztec-up/test/default_scaffold.sh @@ -2,23 +2,22 @@ set -euo pipefail # Tests that the default scaffold generated by `aztec new` compiles and passes its tests without any modifications. -# This catches regressions in the template files produced by setup_workspace.sh (e.g. syntax errors, stale imports, -# or API changes in aztec-nr) that would otherwise go unnoticed until a user runs `aztec new` themselves. +# Also tests that a second contract can be added to the workspace with `aztec new`. export LOG_LEVEL=silent aztec new my_contract -# Verify workspace structure. +# Verify workspace structure with named crate directories. if [ ! -f my_contract/Nargo.toml ]; then echo "Failed to create workspace Nargo.toml." exit 1 fi -if [ ! -f my_contract/contract/Nargo.toml ] || [ ! -f my_contract/contract/src/main.nr ]; then +if [ ! -f my_contract/my_contract_contract/Nargo.toml ] || [ ! -f my_contract/my_contract_contract/src/main.nr ]; then echo "Failed to create contract crate." exit 1 fi -if [ ! -f my_contract/test/Nargo.toml ] || [ ! -f my_contract/test/src/lib.nr ]; then +if [ ! -f my_contract/my_contract_test/Nargo.toml ] || [ ! -f my_contract/my_contract_test/src/lib.nr ]; then echo "Failed to create test crate." exit 1 fi @@ -27,10 +26,41 @@ cd my_contract # This is unfortunate as it makes the test worse but in CI setting the aztec version is 0.0.1 which doesn't exist as # a remote git tag, so we need to rewrite dependencies to use local aztec-nr. -sed -i 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' contract/Nargo.toml test/Nargo.toml +sed -i 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' \ + my_contract_contract/Nargo.toml my_contract_test/Nargo.toml # Compile the default scaffold contract. aztec compile # Run the default scaffold tests. aztec test + +# --- Test adding a second contract to the workspace --- +aztec new token + +# Verify token crates were created. +if [ ! -f token_contract/Nargo.toml ] || [ ! -f token_contract/src/main.nr ]; then + echo "Failed to create token contract crate." + exit 1 +fi +if [ ! -f token_test/Nargo.toml ] || [ ! -f token_test/src/lib.nr ]; then + echo "Failed to create token test crate." + exit 1 +fi + +# Verify workspace Nargo.toml contains all four members. +if ! grep -q '"my_contract_contract"' Nargo.toml || \ + ! grep -q '"my_contract_test"' Nargo.toml || \ + ! grep -q '"token_contract"' Nargo.toml || \ + ! grep -q '"token_test"' Nargo.toml; then + echo "Workspace Nargo.toml does not contain all expected members." + exit 1 +fi + +# Rewrite aztec deps for token crates too. +sed -i 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' \ + token_contract/Nargo.toml token_test/Nargo.toml + +# Compile and test the full workspace (both contracts). +aztec compile +aztec test diff --git a/noir-projects/noir-contracts/Nargo.toml b/noir-projects/noir-contracts/Nargo.toml index d48af75499ea..a3c05bd05a9c 100644 --- a/noir-projects/noir-contracts/Nargo.toml +++ b/noir-projects/noir-contracts/Nargo.toml @@ -41,7 +41,7 @@ members = [ "contracts/test/avm_test_contract", "contracts/test/benchmarking_contract", "contracts/test/child_contract", - "contracts/test/counter_contract/contract", + "contracts/test/counter/counter_contract", "contracts/test/custom_message_contract", "contracts/test/event_only_contract", "contracts/test/import_test_contract", diff --git a/noir-projects/noir-contracts/contracts/test/counter/Nargo.toml b/noir-projects/noir-contracts/contracts/test/counter/Nargo.toml new file mode 100644 index 000000000000..8bec3f6a6701 --- /dev/null +++ b/noir-projects/noir-contracts/contracts/test/counter/Nargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["counter_contract", "counter_test"] diff --git a/noir-projects/noir-contracts/contracts/test/counter_contract/contract/Nargo.toml b/noir-projects/noir-contracts/contracts/test/counter/counter_contract/Nargo.toml similarity index 100% rename from noir-projects/noir-contracts/contracts/test/counter_contract/contract/Nargo.toml rename to noir-projects/noir-contracts/contracts/test/counter/counter_contract/Nargo.toml diff --git a/noir-projects/noir-contracts/contracts/test/counter_contract/contract/src/main.nr b/noir-projects/noir-contracts/contracts/test/counter/counter_contract/src/main.nr similarity index 100% rename from noir-projects/noir-contracts/contracts/test/counter_contract/contract/src/main.nr rename to noir-projects/noir-contracts/contracts/test/counter/counter_contract/src/main.nr diff --git a/noir-projects/noir-contracts/contracts/test/counter_contract/test/Nargo.toml b/noir-projects/noir-contracts/contracts/test/counter/counter_test/Nargo.toml similarity index 81% rename from noir-projects/noir-contracts/contracts/test/counter_contract/test/Nargo.toml rename to noir-projects/noir-contracts/contracts/test/counter/counter_test/Nargo.toml index 1d5b103087e7..b587b4b2e560 100644 --- a/noir-projects/noir-contracts/contracts/test/counter_contract/test/Nargo.toml +++ b/noir-projects/noir-contracts/contracts/test/counter/counter_test/Nargo.toml @@ -7,4 +7,4 @@ type = "lib" [dependencies] aztec = { path = "../../../../../aztec-nr/aztec" } balance_set = { path = "../../../../../aztec-nr/balance-set" } -counter_contract = { path = "../contract" } +counter_contract = { path = "../counter_contract" } diff --git a/noir-projects/noir-contracts/contracts/test/counter_contract/test/src/lib.nr b/noir-projects/noir-contracts/contracts/test/counter/counter_test/src/lib.nr similarity index 100% rename from noir-projects/noir-contracts/contracts/test/counter_contract/test/src/lib.nr rename to noir-projects/noir-contracts/contracts/test/counter/counter_test/src/lib.nr diff --git a/noir-projects/noir-contracts/contracts/test/counter_contract/Nargo.toml b/noir-projects/noir-contracts/contracts/test/counter_contract/Nargo.toml deleted file mode 100644 index 3ae352f74220..000000000000 --- a/noir-projects/noir-contracts/contracts/test/counter_contract/Nargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[workspace] -members = ["contract", "test"] diff --git a/yarn-project/aztec/scripts/add_crate.sh b/yarn-project/aztec/scripts/add_crate.sh new file mode 100755 index 000000000000..fea8a4b66e42 --- /dev/null +++ b/yarn-project/aztec/scripts/add_crate.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Creates a contract+test crate pair and adds them to an existing workspace. +# Usage: add_crate.sh +# Must be called from a workspace root that already has Nargo.toml with [workspace]. + +crate_name=$1 + +if [ -z "$crate_name" ]; then + echo "Error: crate name is required" + exit 1 +fi + +if [[ "$crate_name" == *"/"* ]] || [[ "$crate_name" == *"\\"* ]]; then + echo "Error: crate name must not contain path separators" + exit 1 +fi + +contract_dir="${crate_name}_contract" +test_dir="${crate_name}_test" + +if [ -d "$contract_dir" ]; then + echo "Error: directory '$contract_dir' already exists" + exit 1 +fi +if [ -d "$test_dir" ]; then + echo "Error: directory '$test_dir' already exists" + exit 1 +fi + +# Get the actual aztec version for the git tag. +AZTEC_VERSION=$(jq -r '.version' $(dirname $0)/../package.json) + +# Create contract crate +mkdir -p "$contract_dir/src" +cat > "$contract_dir/Nargo.toml" << CEOF +[package] +name = "${crate_name}_contract" +type = "contract" + +[dependencies] +aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" } +CEOF + +cat > "$contract_dir/src/main.nr" << 'EOF' +use aztec::macros::aztec; + +#[aztec] +pub contract Main { + use aztec::macros::functions::{external, initializer}; + + #[initializer] + #[external("private")] + fn constructor() {} +} +EOF + +# Create test crate +mkdir -p "$test_dir/src" +cat > "$test_dir/Nargo.toml" << TEOF +[package] +name = "${crate_name}_test" +type = "lib" + +[dependencies] +aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" } +${crate_name}_contract = { path = "../${contract_dir}" } +TEOF + +cat > "$test_dir/src/lib.nr" << 'NOIR' +use aztec::test::helpers::test_environment::TestEnvironment; +use __CRATE_NAME___contract::Main; + +#[test] +unconstrained fn test_constructor() { + let mut env = TestEnvironment::new(); + let deployer = env.create_light_account(); + + // Deploy the contract with the default constructor: + let contract_address = env.deploy("@__CRATE_NAME___contract/Main").with_private_initializer( + deployer, + Main::interface().constructor(), + ); + + // Deploy without an initializer: + let contract_address = env.deploy("@__CRATE_NAME___contract/Main").without_initializer(); +} +NOIR + +sed -i "s/__CRATE_NAME__/${crate_name}/g" "$test_dir/src/lib.nr" + +# Add members to workspace Nargo.toml +if grep -q 'members\s*=\s*\[\s*\]' Nargo.toml; then + # Empty array: members = [] + sed -i "s|members\s*=\s*\[\s*\]|members = [\"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml +else + # Non-empty array: add before closing ] + sed -i "s|\(members\s*=\s*\[.*\)\]|\1, \"${contract_dir}\", \"${test_dir}\"]|" Nargo.toml +fi + +echo "Created crates '${contract_dir}' and '${test_dir}'" diff --git a/yarn-project/aztec/scripts/init.sh b/yarn-project/aztec/scripts/init.sh index 3fae0e67f894..84107dfdd247 100755 --- a/yarn-project/aztec/scripts/init.sh +++ b/yarn-project/aztec/scripts/init.sh @@ -20,6 +20,9 @@ Options: This command creates a new Aztec Noir project in the current directory with a workspace containing a contract crate and a test crate, and automatically adds the Aztec.nr dependency to both. + +If a workspace already exists in the current directory, use +'aztec new ' instead to add another contract. EOF exit 0 fi diff --git a/yarn-project/aztec/scripts/new.sh b/yarn-project/aztec/scripts/new.sh index 37584fffae0a..340f0ca00c89 100755 --- a/yarn-project/aztec/scripts/new.sh +++ b/yarn-project/aztec/scripts/new.sh @@ -10,20 +10,24 @@ while [[ $# -gt 0 ]]; do case $1 in --help|-h) cat << 'EOF' -Aztec New - Create a new Aztec Noir project in a new directory +Aztec New - Create a new Aztec Noir project or add a contract to an existing workspace -Usage: aztec new [OPTIONS] +Usage: aztec new [OPTIONS] Arguments: - The path to save the new project + The name for the new contract (also used as the directory name when + creating a new workspace) Options: - --name Name of the package [default: package directory name] + --name Name of the package [default: derived from argument] -h, --help Print help -This command creates a new Aztec Noir project with a workspace containing -a contract crate and a test crate, and automatically adds the Aztec.nr -dependency to both. +When run outside an existing workspace: + Creates a new directory with a workspace containing a contract crate and a + test crate, and automatically adds the Aztec.nr dependency to both. + +When run inside an existing workspace (Nargo.toml with [workspace] exists): + Adds a new contract crate and test crate to the existing workspace. EOF exit 0 ;; @@ -40,21 +44,29 @@ EOF done if [ -z "$project_path" ]; then - echo "Error: PATH argument is required" - echo "Usage: aztec new [OPTIONS] " + echo "Error: NAME argument is required" + echo "Usage: aztec new [OPTIONS] " echo "Run 'aztec new --help' for more information" exit 1 fi -if [ -d "$project_path" ] && [ "$(ls -A $project_path 2>/dev/null)" ]; then - echo "Error: $project_path already exists and is not empty" - exit 1 -fi - -# Derive package name: use --name if provided, otherwise use directory basename +# Derive package name: use --name if provided, otherwise use the argument package_name="${name_arg:-$(basename $project_path)}" -echo "Creating new Aztec contract project at $project_path..." -mkdir -p "$project_path" -cd "$project_path" -$script_path/setup_workspace.sh "$package_name" +# Check if we're inside an existing workspace +if [ -f "Nargo.toml" ] && grep -q '\[workspace\]' Nargo.toml; then + # Add crate pair to existing workspace + echo "Adding contract '$package_name' to existing workspace..." + $script_path/add_crate.sh "$package_name" +else + # Create new workspace + if [ -d "$project_path" ] && [ "$(ls -A $project_path 2>/dev/null)" ]; then + echo "Error: $project_path already exists and is not empty" + exit 1 + fi + + echo "Creating new Aztec contract project at $project_path..." + mkdir -p "$project_path" + cd "$project_path" + $script_path/setup_workspace.sh "$package_name" +fi diff --git a/yarn-project/aztec/scripts/setup_workspace.sh b/yarn-project/aztec/scripts/setup_workspace.sh index 11ca9deb68f0..e08f1665136a 100755 --- a/yarn-project/aztec/scripts/setup_workspace.sh +++ b/yarn-project/aztec/scripts/setup_workspace.sh @@ -6,6 +6,7 @@ set -euo pipefail # Must be called from the workspace root directory. package_name=$1 +script_path=$(realpath $(dirname "$0")) if [ -z "$package_name" ]; then echo "Error: package name is required" @@ -13,76 +14,19 @@ if [ -z "$package_name" ]; then fi if [ -f "Nargo.toml" ]; then - echo "Error: Nargo.toml already exists in the current directory" + echo "Error: Nargo.toml already exists in the current directory." + echo "To add another contract crate to this workspace, use 'aztec new ' instead." exit 1 fi -# Get the actual aztec version for the git tag. -AZTEC_VERSION=$(jq -r '.version' $(dirname $0)/../package.json) - -# Create workspace root Nargo.toml +# Create workspace root Nargo.toml with empty members (add_crate.sh will populate) cat > Nargo.toml << 'EOF' [workspace] -members = ["contract", "test"] -EOF - -# Create contract crate -mkdir -p contract/src -cat > contract/Nargo.toml << CEOF -[package] -name = "${package_name}" -type = "contract" - -[dependencies] -aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" } -CEOF - -cat > contract/src/main.nr << 'EOF' -use aztec::macros::aztec; - -#[aztec] -pub contract Main { - use aztec::macros::functions::{external, initializer}; - - #[initializer] - #[external("private")] - fn constructor() {} -} +members = [] EOF -# Create test crate -mkdir -p test/src -cat > test/Nargo.toml << TEOF -[package] -name = "${package_name}_test" -type = "lib" - -[dependencies] -aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag="v${AZTEC_VERSION}", directory="aztec" } -${package_name} = { path = "../contract" } -TEOF - -cat > test/src/lib.nr << 'NOIR' -use aztec::test::helpers::test_environment::TestEnvironment; -use __PACKAGE_NAME__::Main; - -#[test] -unconstrained fn test_constructor() { - let mut env = TestEnvironment::new(); - let deployer = env.create_light_account(); - - // Deploy the contract with the default constructor: - let contract_address = env.deploy("@__PACKAGE_NAME__/Main").with_private_initializer( - deployer, - Main::interface().constructor(), - ); - - // Deploy without an initializer: - let contract_address = env.deploy("@__PACKAGE_NAME__/Main").without_initializer(); -} -NOIR - -sed -i "s/__PACKAGE_NAME__/${package_name}/g" test/src/lib.nr +# Create the first crate pair +$script_path/add_crate.sh "$package_name" # Create README cat > README.md << REOF @@ -96,7 +40,7 @@ An Aztec Noir contract project. aztec compile \`\`\` -This compiles the contract in \`contract/\` and outputs artifacts to \`target/\`. +This compiles all contract crates and outputs artifacts to \`target/\`. ## Test @@ -104,7 +48,7 @@ This compiles the contract in \`contract/\` and outputs artifacts to \`target/\` aztec test \`\`\` -This runs the tests in \`test/\`. +This runs all tests in the workspace. ## Generate TypeScript bindings @@ -121,4 +65,4 @@ target/ codegenCache.json GEOF -echo "Created Aztec contract workspace with crates '${package_name}' and '${package_name}_test'" +echo "Created Aztec contract workspace with crates '${package_name}_contract' and '${package_name}_test'" diff --git a/yarn-project/aztec/src/cli/cli.ts b/yarn-project/aztec/src/cli/cli.ts index 1c79cf24f294..fdb364ce6ff4 100644 --- a/yarn-project/aztec/src/cli/cli.ts +++ b/yarn-project/aztec/src/cli/cli.ts @@ -37,8 +37,8 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge ` Additional commands: - init [folder] [options] creates a new Aztec Noir project. - new [options] creates a new Aztec Noir project in a new directory. + init [options] creates a new Aztec Noir workspace in the current directory. + new [options] creates a new Aztec Noir workspace in its own directory (or creates a new contract-test crates pair and adds it to the current workspace if run in workspace). test [options] starts a TXE and runs "nargo test" using it as the oracle resolver. `, ); From e841ea6e60332d9e53407c6ccba249d0ce9411aa Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 3 Mar 2026 02:06:20 +0000 Subject: [PATCH 2/6] compiltaion fixes --- yarn-project/noir-contracts.js/scripts/generate-types.sh | 2 +- yarn-project/noir-test-contracts.js/scripts/generate-types.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/noir-contracts.js/scripts/generate-types.sh b/yarn-project/noir-contracts.js/scripts/generate-types.sh index 04ecfe03a107..ce75af14440b 100755 --- a/yarn-project/noir-contracts.js/scripts/generate-types.sh +++ b/yarn-project/noir-contracts.js/scripts/generate-types.sh @@ -12,7 +12,7 @@ fi mkdir -p $OUT_DIR # Extract contract names from Nargo.toml, excluding test contracts -CONTRACTS=$(grep "contracts/" ../../noir-projects/noir-contracts/Nargo.toml | grep -v "contracts/test/" | sed 's/.*contracts\/[^/]*\/\([^"]*\)_contract.*/\1/') +CONTRACTS=$(grep "contracts/" ../../noir-projects/noir-contracts/Nargo.toml | grep -v "contracts/test/" | sed 's/.*\/\([^/"]*\)_contract.*/\1/') # Check for .json files existence if ! ls ../../noir-projects/noir-contracts/target/*.json >/dev/null 2>&1; then diff --git a/yarn-project/noir-test-contracts.js/scripts/generate-types.sh b/yarn-project/noir-test-contracts.js/scripts/generate-types.sh index 53ad93b684a9..6890206f7e11 100755 --- a/yarn-project/noir-test-contracts.js/scripts/generate-types.sh +++ b/yarn-project/noir-test-contracts.js/scripts/generate-types.sh @@ -12,7 +12,7 @@ fi mkdir -p $OUT_DIR # Extract test contract names from Nargo.toml -TEST_CONTRACTS=$(grep "contracts/test/" ../../noir-projects/noir-contracts/Nargo.toml | sed 's/.*contracts\/test\/\([^"]*\)_contract.*/\1/') +TEST_CONTRACTS=$(grep "contracts/test/" ../../noir-projects/noir-contracts/Nargo.toml | sed 's/.*\/\([^/"]*\)_contract.*/\1/') # Check for .json files existence if ! ls ../../noir-projects/noir-contracts/target/*.json >/dev/null 2>&1; then From 84f06d5cc8c7bfb4a28685635c8654382f5e0220 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 3 Mar 2026 02:28:43 +0000 Subject: [PATCH 3/6] fix --- aztec-up/test/default_scaffold.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/aztec-up/test/default_scaffold.sh b/aztec-up/test/default_scaffold.sh index 8b55c1d1ca93..9eb08df644fd 100755 --- a/aztec-up/test/default_scaffold.sh +++ b/aztec-up/test/default_scaffold.sh @@ -6,28 +6,28 @@ set -euo pipefail export LOG_LEVEL=silent -aztec new my_contract +aztec new my_workspace # Verify workspace structure with named crate directories. -if [ ! -f my_contract/Nargo.toml ]; then +if [ ! -f my_workspace/Nargo.toml ]; then echo "Failed to create workspace Nargo.toml." exit 1 fi -if [ ! -f my_contract/my_contract_contract/Nargo.toml ] || [ ! -f my_contract/my_contract_contract/src/main.nr ]; then +if [ ! -f my_workspace/my_workspace_contract/Nargo.toml ] || [ ! -f my_workspace/my_workspace_contract/src/main.nr ]; then echo "Failed to create contract crate." exit 1 fi -if [ ! -f my_contract/my_contract_test/Nargo.toml ] || [ ! -f my_contract/my_contract_test/src/lib.nr ]; then +if [ ! -f my_workspace/my_workspace_test/Nargo.toml ] || [ ! -f my_workspace/my_workspace_test/src/lib.nr ]; then echo "Failed to create test crate." exit 1 fi -cd my_contract +cd my_workspace # This is unfortunate as it makes the test worse but in CI setting the aztec version is 0.0.1 which doesn't exist as # a remote git tag, so we need to rewrite dependencies to use local aztec-nr. sed -i 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' \ - my_contract_contract/Nargo.toml my_contract_test/Nargo.toml + my_workspace_contract/Nargo.toml my_workspace_test/Nargo.toml # Compile the default scaffold contract. aztec compile @@ -49,8 +49,8 @@ if [ ! -f token_test/Nargo.toml ] || [ ! -f token_test/src/lib.nr ]; then fi # Verify workspace Nargo.toml contains all four members. -if ! grep -q '"my_contract_contract"' Nargo.toml || \ - ! grep -q '"my_contract_test"' Nargo.toml || \ +if ! grep -q '"my_workspace_contract"' Nargo.toml || \ + ! grep -q '"my_workspace_test"' Nargo.toml || \ ! grep -q '"token_contract"' Nargo.toml || \ ! grep -q '"token_test"' Nargo.toml; then echo "Workspace Nargo.toml does not contain all expected members." From 0272faa42634d7a3dffd4e9d4c8f4c2b8e24707d Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 3 Mar 2026 04:24:35 +0000 Subject: [PATCH 4/6] docs and such --- docs/CLAUDE.md | 1 + .../contract_structure.md | 24 ++++++++++--------- docs/docs-developers/docs/aztec-nr/index.md | 6 ++--- .../docs/aztec-nr/testing_contracts.md | 12 +++++----- .../docs/cli/aztec_cli_reference.md | 4 ++-- .../docs/resources/migration_notes.md | 23 ++++++++++++++++++ .../contract_tutorials/counter_contract.md | 16 ++++++------- .../contract_tutorials/token_contract.md | 10 ++++---- .../tutorials/js_tutorials/token_bridge.md | 16 ++++++------- 9 files changed, 69 insertions(+), 43 deletions(-) diff --git a/docs/CLAUDE.md b/docs/CLAUDE.md index 3a72d0b1d19d..87bddd9ed26c 100644 --- a/docs/CLAUDE.md +++ b/docs/CLAUDE.md @@ -274,6 +274,7 @@ The description should: - ❌ Legal disclaimers or license text - ❌ Direct quotes from external sources - ❌ API endpoint URLs or configuration values +- ❌ Existing migration notes in `resources/migration_notes.md` — never modify already-published migration entries. Instead, add new migration notes to the `## TBD` section at the top of the file. ## Review Output Format diff --git a/docs/docs-developers/docs/aztec-nr/framework-description/contract_structure.md b/docs/docs-developers/docs/aztec-nr/framework-description/contract_structure.md index 6e605555b99a..d3c5d4068775 100644 --- a/docs/docs-developers/docs/aztec-nr/framework-description/contract_structure.md +++ b/docs/docs-developers/docs/aztec-nr/framework-description/contract_structure.md @@ -10,25 +10,27 @@ High-level structure of how Aztec smart contracts including the different compon ## Directory structure -When you create a new project with `aztec new`, it generates a workspace with two crates: a `contract` crate for your smart contract and a `test` crate for Noir tests. +When you create a new project with `aztec new my_project`, it generates a workspace with two crates named after your project: a `my_project_contract` crate for your smart contract and a `my_project_test` crate for Noir tests. ```text title="layout of an aztec contract project" -─── my_aztec_contract_project - ├── Nargo.toml <-- workspace root - ├── contract +─── my_project + ├── Nargo.toml <-- workspace root + ├── my_project_contract │ ├── src - │ │ └── main.nr <-- your contract - │ └── Nargo.toml <-- contract package and dependencies - └── test + │ │ └── main.nr <-- your contract + │ └── Nargo.toml <-- contract package and dependencies + └── my_project_test ├── src - │ └── lib.nr <-- your tests - └── Nargo.toml <-- test package and dependencies + │ └── lib.nr <-- your tests + └── Nargo.toml <-- test package and dependencies ``` -The workspace root `Nargo.toml` declares both crates as workspace members. The contract code lives in `contract/src/main.nr`, and tests live in a separate `test` crate that depends on the contract crate. +The workspace root `Nargo.toml` declares both crates as workspace members. The contract code lives in `my_project_contract/src/main.nr`, and tests live in a separate `my_project_test` crate that depends on the contract crate. + +You can add more contracts to an existing workspace by running `aztec new ` from inside the workspace directory. This creates a new `_contract` and `_test` crate pair and adds them to the workspace. :::warning Keep tests out of the contract crate -Do not add `#[test]` functions to the `contract` crate. Because the contract artifact depends on everything in its crate, any change — including a test-only change — forces a full recompilation of the contract. The separate `test` crate lets you iterate on tests without rebuilding the contract. See [Testing Contracts](../testing_contracts.md#keep-tests-in-the-test-crate) for details. +Do not add `#[test]` functions to the `_contract` crate. Because the contract artifact depends on everything in its crate, any change — including a test-only change — forces a full recompilation of the contract. The separate `_test` crate lets you iterate on tests without rebuilding the contract. See [Testing Contracts](../testing_contracts.md#keep-tests-in-the-test-crate) for details. ::: See the vanilla Noir docs for [more info on packages](https://noir-lang.org/docs/noir/modules_packages_crates/crates_and_packages). diff --git a/docs/docs-developers/docs/aztec-nr/index.md b/docs/docs-developers/docs/aztec-nr/index.md index 34fe5705cc8f..2292165c6757 100644 --- a/docs/docs-developers/docs/aztec-nr/index.md +++ b/docs/docs-developers/docs/aztec-nr/index.md @@ -42,15 +42,15 @@ storage.votes.insert(new_vote).deliver(vote_counter); // the vote counter accoun ### Flow -1. Write your contract and specify your contract dependencies. Create a new project with `aztec new my_project`, which sets up a workspace with a `contract` crate and a `test` crate, with the `aztec` dependency already configured. If you need additional dependencies, add them to `contract/Nargo.toml`: +1. Write your contract and specify your contract dependencies. Create a new project with `aztec new my_project`, which sets up a workspace with a `my_project_contract` crate and a `my_project_test` crate, with the `aztec` dependency already configured. If you need additional dependencies, add them to `my_project_contract/Nargo.toml`: ```toml -# contract/Nargo.toml +# my_project_contract/Nargo.toml [dependencies] aztec = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_aztec_version", directory="aztec" } ``` -Update your `contract/src/main.nr` contract file to use the Aztec.nr macros for writing contracts. +Update your `my_project_contract/src/main.nr` contract file to use the Aztec.nr macros for writing contracts. #include_code setup /docs/examples/contracts/counter_contract/src/main.nr rust diff --git a/docs/docs-developers/docs/aztec-nr/testing_contracts.md b/docs/docs-developers/docs/aztec-nr/testing_contracts.md index a3b2c01bfade..03d19207600d 100644 --- a/docs/docs-developers/docs/aztec-nr/testing_contracts.md +++ b/docs/docs-developers/docs/aztec-nr/testing_contracts.md @@ -46,7 +46,7 @@ Always use `aztec test` instead of `nargo test`. The `TestEnvironment` requires ## Keep tests in the test crate -When you create a project with `aztec new` or `aztec init`, the generated workspace has two crates: `contract` and `test`. It is important that all tests live in the `test` crate, **not** in the `contract` crate. +When you create a project with `aztec new` or `aztec init`, the generated workspace has two crates: `_contract` and `_test`. It is important that all tests live in the `_test` crate, **not** in the `_contract` crate. If you place `#[test]` functions inside the contract crate, `aztec compile` will emit a warning: @@ -60,7 +60,7 @@ The reason is **unnecessary recompilation**: the contract artifact depends on ev ## Basic test structure -Tests live in `test/src/lib.nr` and import the contract crate by name (not `crate::`): +Tests live in `_test/src/lib.nr` and import the contract crate by name (not `crate::`): ```rust use my_contract::MyContract; @@ -88,11 +88,11 @@ unconstrained fn test_basic_flow() { ::: :::tip Organizing test files -Tests live in the separate `test` crate that `aztec new` creates. You can organize them into modules: +Tests live in the separate `_test` crate that `aztec new` creates. You can organize them into modules: -- Split tests into modules like `test/src/transfer_tests.nr`, `test/src/auth_tests.nr` -- Import them in `test/src/lib.nr` with `mod transfer_tests;`, `mod auth_tests;` -- Share setup functions in `test/src/utils.nr` +- Split tests into modules like `_test/src/transfer_tests.nr`, `_test/src/auth_tests.nr` +- Import them in `_test/src/lib.nr` with `mod transfer_tests;`, `mod auth_tests;` +- Share setup functions in `_test/src/utils.nr` ::: ## Deploying contracts diff --git a/docs/docs-developers/docs/cli/aztec_cli_reference.md b/docs/docs-developers/docs/cli/aztec_cli_reference.md index 725678e97816..a4621c23ab45 100644 --- a/docs/docs-developers/docs/cli/aztec_cli_reference.md +++ b/docs/docs-developers/docs/cli/aztec_cli_reference.md @@ -109,10 +109,10 @@ aztec [options] [command] - `get-logs [options]` - Gets all the public logs from an intersection of all the filter params. - `get-node-info [options]` - Gets the information of an Aztec node from a PXE or directly from an Aztec node. - `help [command]` - display help for command -- `init [folder] [options]` - creates a new Noir project +- `init [options]` - creates a new Noir workspace in the current directory - `inspect-contract ` - Shows list of external callable functions for a contract - `lsp` - starts the Nargo Language Server Protocol server -- `new [options]` - creates a new Noir project in a new directory +- `new [options]` - creates a new Noir workspace (or adds a contract to an existing workspace) - `parse-parameter-struct [options] ` - Helper for parsing an encoded string into a contract's parameter struct. - `preload-crs` - Preload the points data needed for proving and verifying - `propose-with-lock [options]` - Makes a proposal to governance with a lock diff --git a/docs/docs-developers/docs/resources/migration_notes.md b/docs/docs-developers/docs/resources/migration_notes.md index 63c71c0e7bbd..8fd143a0b446 100644 --- a/docs/docs-developers/docs/resources/migration_notes.md +++ b/docs/docs-developers/docs/resources/migration_notes.md @@ -9,6 +9,29 @@ Aztec is in active development. Each version may introduce breaking changes that ## TBD +### `aztec new` crate directories are now named after the contract + +`aztec new` and `aztec init` now name the generated crate directories after the contract instead of using generic `contract/` and `test/` names. For example, `aztec new counter` now creates: + +``` +counter/ +├── Nargo.toml # [workspace] members = ["counter_contract", "counter_test"] +├── counter_contract/ +│ ├── src/main.nr +│ └── Nargo.toml # type = "contract" +└── counter_test/ + ├── src/lib.nr + └── Nargo.toml # type = "lib" +``` + +This enables adding multiple contracts to a single workspace. Running `aztec new ` inside an existing workspace (a directory with a `Nargo.toml` containing `[workspace]`) now adds a new `_contract` and `_test` crate pair to the workspace instead of creating a new directory. + +**What changed:** +- Crate directories are now `_contract/` and `_test/` instead of `contract/` and `test/`. +- Contract code is now at `_contract/src/main.nr` instead of `contract/src/main.nr`. +- Contract dependencies go in `_contract/Nargo.toml` instead of `contract/Nargo.toml`. +- Tests import the contract by its new crate name (e.g., `use counter_contract::Main;` instead of `use counter::Main;`). + ### [Aztec.js] Removed `SingleKeyAccountContract` The `SchnorrSingleKeyAccount` contract and its TypeScript wrapper `SingleKeyAccountContract` have been removed. This contract was insecure: it used `ivpk_m` (incoming viewing public key) as its Schnorr signing key, meaning anyone who received a user's viewing key could sign transactions on their behalf. diff --git a/docs/docs-developers/docs/tutorials/contract_tutorials/counter_contract.md b/docs/docs-developers/docs/tutorials/contract_tutorials/counter_contract.md index 817aa4f78273..39fe64bd857f 100644 --- a/docs/docs-developers/docs/tutorials/contract_tutorials/counter_contract.md +++ b/docs/docs-developers/docs/tutorials/contract_tutorials/counter_contract.md @@ -30,20 +30,20 @@ Your structure should look like this: ```tree . |-counter -| |-Nargo.toml <-- workspace root -| |-contract +| |-Nargo.toml <-- workspace root +| |-counter_contract | | |-src | | | |-main.nr -| | |-Nargo.toml <-- contract package config -| |-test +| | |-Nargo.toml <-- contract package config +| |-counter_test | | |-src | | | |-lib.nr -| | |-Nargo.toml <-- test package config +| | |-Nargo.toml <-- test package config ``` -The `aztec new` command creates a workspace with two crates: a `contract` crate for your smart contract code and a `test` crate for Noir tests. The file `contract/src/main.nr` will soon turn into our smart contract! +The `aztec new` command creates a workspace with two crates: a `counter_contract` crate for your smart contract code and a `counter_test` crate for Noir tests. The file `counter_contract/src/main.nr` will soon turn into our smart contract! -Add the following dependency to `contract/Nargo.toml` under the existing `aztec` dependency: +Add the following dependency to `counter_contract/Nargo.toml` under the existing `aztec` dependency: ```toml [dependencies] @@ -53,7 +53,7 @@ balance_set = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_ ## Define the functions -Go to `contract/src/main.nr`, and replace the boilerplate code with this contract initialization: +Go to `counter_contract/src/main.nr`, and replace the boilerplate code with this contract initialization: ```rust #include_code setup /docs/examples/contracts/counter_contract/src/main.nr raw diff --git a/docs/docs-developers/docs/tutorials/contract_tutorials/token_contract.md b/docs/docs-developers/docs/tutorials/contract_tutorials/token_contract.md index 98e5fdc0fb60..677f88f0dda4 100644 --- a/docs/docs-developers/docs/tutorials/contract_tutorials/token_contract.md +++ b/docs/docs-developers/docs/tutorials/contract_tutorials/token_contract.md @@ -39,8 +39,8 @@ We'll create BOB tokens with: Let's create a simple yarn + aztec.nr project: ```bash -mkdir bob_token_contract -cd bob_token_contract +mkdir bob_token +cd bob_token yarn init # This is to ensure yarn uses node_modules instead of pnp for dependency installation yarn config set nodeLinker node-modules @@ -50,7 +50,7 @@ aztec init ## Contract structure -The `aztec init` command created a workspace with two crates: a `contract` crate for your smart contract code and a `test` crate for Noir tests. In `contract/src/main.nr` we even have a proto-contract. Let's replace it with a simple starting point: +The `aztec init` command created a workspace with two crates: a `bob_token_contract` crate for your smart contract code and a `bob_token_test` crate for Noir tests. In `bob_token_contract/src/main.nr` we even have a proto-contract. Let's replace it with a simple starting point: ```rust #include_code start /docs/examples/contracts/bob_token_contract/src/main.nr raw @@ -60,7 +60,7 @@ The `aztec init` command created a workspace with two crates: a `contract` crate The `#[aztec]` macro transforms our contract code to work with Aztec's privacy protocol. -Let's make sure the Aztec.nr library is listed in our dependencies in `contract/Nargo.toml`: +Let's make sure the Aztec.nr library is listed in our dependencies in `bob_token_contract/Nargo.toml`: ```toml [package] @@ -254,7 +254,7 @@ In this case, all that the network sees (including Giggle) is just "something ha ### Updating Storage for Privacy -For something like balances, you can use a simple library called `easy_private_state` which abstracts away a custom private Note. A Note is at the core of how private state works in Aztec and you can read about it [here](../../foundational-topics/state_management.md). For now, let's just import the library in `contract/Nargo.toml`: +For something like balances, you can use a simple library called `easy_private_state` which abstracts away a custom private Note. A Note is at the core of how private state works in Aztec and you can read about it [here](../../foundational-topics/state_management.md). For now, let's just import the library in `bob_token_contract/Nargo.toml`: ```toml [dependencies] diff --git a/docs/docs-developers/docs/tutorials/js_tutorials/token_bridge.md b/docs/docs-developers/docs/tutorials/js_tutorials/token_bridge.md index f80d3c6897a5..fe4df0b37ba2 100644 --- a/docs/docs-developers/docs/tutorials/js_tutorials/token_bridge.md +++ b/docs/docs-developers/docs/tutorials/js_tutorials/token_bridge.md @@ -86,7 +86,7 @@ aztec new contracts/aztec/nft cd contracts/aztec/nft ``` -This creates a workspace with two crates: a `contract` crate for the smart contract code and a `test` crate for Noir tests. The `aztec` dependency is already configured in `contract/Nargo.toml`. +This creates a workspace with two crates: an `nft_contract` crate for the smart contract code and an `nft_test` crate for Noir tests. The `aztec` dependency is already configured in `nft_contract/Nargo.toml`. :::tip Noir Language Server @@ -96,10 +96,10 @@ If you're using VS Code, install the [Noir Language Support extension](https://m ### Create the NFT Note -First, let's create a custom note type for private NFT ownership. In the `contract/src/` directory, create a new file called `nft.nr`: +First, let's create a custom note type for private NFT ownership. In the `nft_contract/src/` directory, create a new file called `nft.nr`: ```bash -touch contract/src/nft.nr +touch nft_contract/src/nft.nr ``` In this file, you're going to create a **private note** that represents NFT ownership. This is a struct with macros that indicate it is a note that can be compared and packed: @@ -116,7 +116,7 @@ Notes are powerful concepts. Learn more about how to use them in the [state mana ### Define Storage -Back in `contract/src/main.nr`, you can now build the contract storage. You need: +Back in `nft_contract/src/main.nr`, you can now build the contract storage. You need: - **admin**: Who controls the contract (set once, never changes) - **minter**: The bridge address (set once by admin) @@ -125,7 +125,7 @@ Back in `contract/src/main.nr`, you can now build the contract storage. You need One interesting aspect of this storage configuration is the use of `DelayedPublicMutable`, which allows private functions to read and use public state. You're using it to publicly track which NFTs are already minted while keeping their owners private. Read more about `DelayedPublicMutable` in [the storage guide](../../aztec-nr/framework-description/state_variables.md). -Write the storage struct and a simple [initializer](../../foundational-topics/contract_creation.md#initialization) to set the admin in the `contract/src/main.nr` file: +Write the storage struct and a simple [initializer](../../foundational-topics/contract_creation.md#initialization) to set the admin in the `nft_contract/src/main.nr` file: @@ -213,12 +213,12 @@ aztec new nft_bridge cd nft_bridge ``` -Now add the `NFTPunk` contract dependency to `contract/Nargo.toml`. The `aztec` dependency is already there: +Now add the `NFTPunk` contract dependency to `nft_bridge_contract/Nargo.toml`. The `aztec` dependency is already there: ```toml [dependencies] aztec = { git="https://github.com/AztecProtocol/aztec-nr", tag = "#include_aztec_version", directory = "aztec" } -NFTPunk = { path = "../../nft/contract" } +NFTPunk = { path = "../../nft/nft_contract" } ``` ### Understanding Bridges @@ -232,7 +232,7 @@ This means having knowledge about the L2 NFT contract, and the bridge on the L1 ### Bridge Storage -Clean up `contract/src/main.nr` which is just a placeholder, and let's write the storage struct and the constructor. We'll use `PublicImmutable` since these values never change: +Clean up `nft_bridge_contract/src/main.nr` which is just a placeholder, and let's write the storage struct and the constructor. We'll use `PublicImmutable` since these values never change: From 13ee959f19285b4c6a351c1258391dc25cbc0d97 Mon Sep 17 00:00:00 2001 From: benesjan Date: Tue, 3 Mar 2026 04:41:35 +0000 Subject: [PATCH 5/6] cleanup --- yarn-project/aztec/scripts/init.sh | 21 ++------------------- yarn-project/aztec/scripts/new.sh | 13 +++---------- yarn-project/aztec/src/cli/cli.ts | 6 +++--- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/yarn-project/aztec/scripts/init.sh b/yarn-project/aztec/scripts/init.sh index 84107dfdd247..60c88edc666c 100755 --- a/yarn-project/aztec/scripts/init.sh +++ b/yarn-project/aztec/scripts/init.sh @@ -3,18 +3,15 @@ set -euo pipefail script_path=$(realpath $(dirname "$0")) -name_arg="" - # Check for help first for arg in "$@"; do if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]; then cat << 'EOF' Aztec Init - Create a new Aztec Noir project in the current directory -Usage: aztec init [OPTIONS] +Usage: aztec init Options: - --name Name of the package [default: current directory name] -h, --help Print help This command creates a new Aztec Noir project in the current directory with @@ -28,21 +25,7 @@ EOF fi done -# Parse arguments -while [[ $# -gt 0 ]]; do - case $1 in - --name) - name_arg="$2" - shift 2 - ;; - *) - shift - ;; - esac -done - -# Derive package name: use --name if provided, otherwise use current directory name -package_name="${name_arg:-$(basename $(pwd))}" +package_name="$(basename $(pwd))" echo "Initializing Aztec contract project..." $script_path/setup_workspace.sh "$package_name" diff --git a/yarn-project/aztec/scripts/new.sh b/yarn-project/aztec/scripts/new.sh index 340f0ca00c89..e897ed123b33 100755 --- a/yarn-project/aztec/scripts/new.sh +++ b/yarn-project/aztec/scripts/new.sh @@ -3,7 +3,6 @@ set -euo pipefail script_path=$(realpath $(dirname "$0")) -name_arg="" project_path="" while [[ $# -gt 0 ]]; do @@ -12,14 +11,13 @@ while [[ $# -gt 0 ]]; do cat << 'EOF' Aztec New - Create a new Aztec Noir project or add a contract to an existing workspace -Usage: aztec new [OPTIONS] +Usage: aztec new Arguments: The name for the new contract (also used as the directory name when creating a new workspace) Options: - --name Name of the package [default: derived from argument] -h, --help Print help When run outside an existing workspace: @@ -31,10 +29,6 @@ When run inside an existing workspace (Nargo.toml with [workspace] exists): EOF exit 0 ;; - --name) - name_arg="$2" - shift 2 - ;; *) project_path=$1 shift @@ -45,13 +39,12 @@ done if [ -z "$project_path" ]; then echo "Error: NAME argument is required" - echo "Usage: aztec new [OPTIONS] " + echo "Usage: aztec new " echo "Run 'aztec new --help' for more information" exit 1 fi -# Derive package name: use --name if provided, otherwise use the argument -package_name="${name_arg:-$(basename $project_path)}" +package_name="$(basename $project_path)" # Check if we're inside an existing workspace if [ -f "Nargo.toml" ] && grep -q '\[workspace\]' Nargo.toml; then diff --git a/yarn-project/aztec/src/cli/cli.ts b/yarn-project/aztec/src/cli/cli.ts index fdb364ce6ff4..f1c8269ef0e3 100644 --- a/yarn-project/aztec/src/cli/cli.ts +++ b/yarn-project/aztec/src/cli/cli.ts @@ -37,9 +37,9 @@ export function injectAztecCommands(program: Command, userLog: LogFn, debugLogge ` Additional commands: - init [options] creates a new Aztec Noir workspace in the current directory. - new [options] creates a new Aztec Noir workspace in its own directory (or creates a new contract-test crates pair and adds it to the current workspace if run in workspace). - test [options] starts a TXE and runs "nargo test" using it as the oracle resolver. + init creates a new Aztec Noir workspace in the current directory. + new creates a new Aztec Noir workspace in its own directory (or creates a new contract-test crates pair and adds it to the current workspace if run in workspace). + test [options] starts a TXE and runs "nargo test" using it as the oracle resolver. `, ); } From 5afe980e6b17442e02dab93d81dce7713a6c9990 Mon Sep 17 00:00:00 2001 From: benesjan Date: Wed, 4 Mar 2026 09:57:06 +0000 Subject: [PATCH 6/6] addressing PR feedback --- .../docs/resources/migration_notes.md | 18 +++++++++++++++++ yarn-project/aztec/scripts/init.sh | 20 +++++++++++++------ yarn-project/aztec/scripts/new.sh | 20 ++++++++++++++++++- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/docs/docs-developers/docs/resources/migration_notes.md b/docs/docs-developers/docs/resources/migration_notes.md index 8fd143a0b446..cc1524e30ccc 100644 --- a/docs/docs-developers/docs/resources/migration_notes.md +++ b/docs/docs-developers/docs/resources/migration_notes.md @@ -32,6 +32,24 @@ This enables adding multiple contracts to a single workspace. Running `aztec new - Contract dependencies go in `_contract/Nargo.toml` instead of `contract/Nargo.toml`. - Tests import the contract by its new crate name (e.g., `use counter_contract::Main;` instead of `use counter::Main;`). +### [CLI] `--name` flag removed from `aztec new` and `aztec init` + +The `--name` flag has been removed from both `aztec new` and `aztec init`. For `aztec new`, the positional argument now serves as both the contract name and the directory name. For `aztec init`, the directory name is always used as the contract name. + +**Migration:** + +```diff +- aztec new my_project --name counter ++ aztec new counter +``` + +```diff +- aztec init --name counter ++ aztec init +``` + +**Impact**: If you were using `--name` to set a contract name different from the directory name, rename your directory or use `aztec new` with the desired contract name directly. + ### [Aztec.js] Removed `SingleKeyAccountContract` The `SchnorrSingleKeyAccount` contract and its TypeScript wrapper `SingleKeyAccountContract` have been removed. This contract was insecure: it used `ivpk_m` (incoming viewing public key) as its Schnorr signing key, meaning anyone who received a user's viewing key could sign transactions on their behalf. diff --git a/yarn-project/aztec/scripts/init.sh b/yarn-project/aztec/scripts/init.sh index 60c88edc666c..e0641a9c17fa 100755 --- a/yarn-project/aztec/scripts/init.sh +++ b/yarn-project/aztec/scripts/init.sh @@ -3,10 +3,11 @@ set -euo pipefail script_path=$(realpath $(dirname "$0")) -# Check for help first -for arg in "$@"; do - if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]; then - cat << 'EOF' +# Parse arguments +while [[ $# -gt 0 ]]; do + case $1 in + --help|-h) + cat << 'EOF' Aztec Init - Create a new Aztec Noir project in the current directory Usage: aztec init @@ -21,8 +22,15 @@ adds the Aztec.nr dependency to both. If a workspace already exists in the current directory, use 'aztec new ' instead to add another contract. EOF - exit 0 - fi + exit 0 + ;; + *) + echo "Error: unexpected argument '$1'" + echo "Usage: aztec init" + echo "Run 'aztec init --help' for more information" + exit 1 + ;; + esac done package_name="$(basename $(pwd))" diff --git a/yarn-project/aztec/scripts/new.sh b/yarn-project/aztec/scripts/new.sh index e897ed123b33..9fb73277811a 100755 --- a/yarn-project/aztec/scripts/new.sh +++ b/yarn-project/aztec/scripts/new.sh @@ -29,10 +29,21 @@ When run inside an existing workspace (Nargo.toml with [workspace] exists): EOF exit 0 ;; + -*) + echo "Error: unknown option '$1'" + echo "Usage: aztec new " + echo "Run 'aztec new --help' for more information" + exit 1 + ;; *) + if [ -n "$project_path" ]; then + echo "Error: unexpected argument '$1'" + echo "Usage: aztec new " + echo "Run 'aztec new --help' for more information" + exit 1 + fi project_path=$1 shift - break ;; esac done @@ -46,6 +57,13 @@ fi package_name="$(basename $project_path)" +# Validate that the name contains only valid Noir identifier characters +if ! [[ "$package_name" =~ ^[a-zA-Z][a-zA-Z0-9_]*$ ]]; then + echo "Error: '$package_name' is not a valid contract name" + echo "Name must start with a letter and contain only letters, digits, and underscores" + exit 1 +fi + # Check if we're inside an existing workspace if [ -f "Nargo.toml" ] && grep -q '\[workspace\]' Nargo.toml; then # Add crate pair to existing workspace