-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aztec-nr): do not compile functions with a private public macro …
…and unconstrained (#11815) fixes: AztecProtocol/aztec-packages#11725
- Loading branch information
Showing
8 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
55 changes: 55 additions & 0 deletions
55
macro_compilation_failure_tests/assert_macro_compilation_failure.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
7 changes: 7 additions & 0 deletions
7
macro_compilation_failure_tests/failure_contracts/marked_private_unconstrained/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
14 changes: 14 additions & 0 deletions
14
macro_compilation_failure_tests/failure_contracts/marked_private_unconstrained/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
macro_compilation_failure_tests/failure_contracts/marked_public_unconstrained/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
14 changes: 14 additions & 0 deletions
14
macro_compilation_failure_tests/failure_contracts/marked_public_unconstrained/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} | ||
} | ||
|