Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions noir-projects/aztec-nr/aztec/src/macros/functions/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ pub comptime fn private(f: FunctionDefinition) -> Quoted {
let fn_stub = stub_fn(f);
register_stub(f.module(), fn_stub);

// If a function is further modified as unconstrained, we throw an error
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not using a function to marry these as the error message is different and its simple enough

if f.is_unconstrained() {
let name = f.name();
panic(
f"Function {name} is annotated with #[private] but marked as unconstrained, remove unconstrained keyword",
);
}

let module_has_initializer = module_has_initializer(f.module());
let module_has_storage = module_has_storage(f.module());

Expand Down Expand Up @@ -244,6 +252,14 @@ comptime fn transform_public(f: FunctionDefinition) -> Quoted {
let fn_stub = stub_fn(f);
register_stub(f.module(), fn_stub);

// If a function is further modified as unconstrained, we throw an error
if f.is_unconstrained() {
let name = f.name();
panic(
f"Function {name} is annotated with #[public] but marked as unconstrained, remove unconstrained keyword",
);
}

let module_has_initializer = module_has_initializer(f.module());
let module_has_storage = module_has_storage(f.module());

Expand Down
6 changes: 6 additions & 0 deletions noir-projects/aztec-nr/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ function test {
while ! nc -z 127.0.0.1 45730 &>/dev/null; do sleep 1; done

test_cmds | (cd $root; NARGO_FOREIGN_CALL_TIMEOUT=300000 parallel --bar --halt now,fail=1 'dump_fail {} >/dev/null')

# Run the macro compilation failure tests
./macro_compilation_failure_tests/assert_macro_compilation_failure.sh
}

case "$cmd" in
Expand All @@ -33,6 +36,9 @@ case "$cmd" in
"test-cmds")
test_cmds
;;
"test-macro-compilation-failure")
./macro_compilation_failure_tests/assert_macro_compilation_failure.sh
;;
*)
echo_stderr "Unknown command: $cmd"
exit 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
# Within failure_contracts, we have contracts that should fail compilation due to code in the macros
# This script will test that compilation fails for each of the contracts in failure_contracts

REPO=$(git rev-parse --show-toplevel)
NARGO=${NARGO:-"$REPO/noir/noir-repo/target/release/nargo"}

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Initialize counters
total_tests=0
passed_tests=0

# Function to test compilation failure
test_compilation_failure() {
local contract_dir=$1
((total_tests++))

echo "Testing compilation failure for: $contract_dir"

# Try to compile the contract
if cd "$contract_dir" && $NARGO compile 2>/dev/null; then
echo -e "${RED}❌ Test failed: Compilation succeeded when it should have failed for $contract_dir${NC}"
cd - > /dev/null
return 1
else
echo -e "${GREEN}✓ Test passed: Compilation failed as expected for $contract_dir${NC}"
cd - > /dev/null
((passed_tests++))
return 0
fi
}

# Get the directory where the script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
FAILURE_CONTRACTS_DIR="$SCRIPT_DIR/failure_contracts"

# Test each contract in the failure_contracts directory
for contract in "$FAILURE_CONTRACTS_DIR"/*; do
if [ -d "$contract" ]; then
test_compilation_failure "$contract"
fi
done

# Print summary
echo -e "\nTest Summary:"
echo -e "Total tests: $total_tests"
echo -e "Passed tests: $passed_tests"
echo -e "Failed tests: $((total_tests - passed_tests))"

# Exit with failure if any test didn't pass
[ "$total_tests" -eq "$passed_tests" ] || exit 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "marked_private_unconstrained"
type = "contract"
authors = [""]

[dependencies]
aztec = { path = "../../../aztec" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// Private functions that are also marked as unconstrained are not allowed.
///
use aztec::macros::aztec;


#[aztec]
contract MarkedPrivateUnconstrained {
use aztec::macros::functions::private;


#[private]
unconstrained fn unconstrained_private_function() {}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "marked_public_unconstrained"
type = "contract"
authors = [""]

[dependencies]
aztec = { path = "../../../aztec" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// Public functions that are also marked as unconstrained are not allowed.
///
use aztec::macros::aztec;


#[aztec]
contract MarkedPublicUnconstrained {
use aztec::macros::functions::public;


#[public]
unconstrained fn unconstrained_public_function() {}
}

Loading