Skip to content

Commit eb05ee8

Browse files
authored
chore: Accumulated backports to v4-next (#22763)
BEGIN_COMMIT_OVERRIDE feat(aztec)!: add counter template for aztec init (#22751) cherry-pick: fix(pxe): restrict setSenderForTags override to current call (F-564) (#22672) (with conflicts) fix: backport restrict setSenderForTags override to current call (#22672) (#22767) fix(pxe): backport anchor header threading from #22679 to v4-next (#22705) END_COMMIT_OVERRIDE
2 parents 3095fff + 76c72f8 commit eb05ee8

184 files changed

Lines changed: 1742 additions & 477 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aztec-up/test/default_scaffold.sh

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# Tests that the default scaffold generated by `aztec new` compiles and passes its tests without any modifications.
5-
# Also tests that a second contract can be added to the workspace with `aztec new`.
4+
# Tests that `aztec init` scaffolds a Counter contract that compiles and passes tests,
5+
# and that `aztec new` can add a blank contract to the same workspace.
66

77
export LOG_LEVEL=silent
88

9-
aztec new my_workspace
9+
mkdir my_workspace && cd my_workspace
10+
aztec init
1011

1112
# Verify workspace structure with named crate directories.
12-
if [ ! -f my_workspace/Nargo.toml ]; then
13+
if [ ! -f Nargo.toml ]; then
1314
echo "Failed to create workspace Nargo.toml."
1415
exit 1
1516
fi
16-
if [ ! -f my_workspace/my_workspace_contract/Nargo.toml ] || [ ! -f my_workspace/my_workspace_contract/src/main.nr ]; then
17+
if [ ! -f my_workspace_contract/Nargo.toml ] || [ ! -f my_workspace_contract/src/main.nr ]; then
1718
echo "Failed to create contract crate."
1819
exit 1
1920
fi
20-
if [ ! -f my_workspace/my_workspace_test/Nargo.toml ] || [ ! -f my_workspace/my_workspace_test/src/lib.nr ]; then
21+
if [ ! -f my_workspace_test/Nargo.toml ] || [ ! -f my_workspace_test/src/lib.nr ]; then
2122
echo "Failed to create test crate."
2223
exit 1
2324
fi
2425

25-
cd my_workspace
26+
# Verify the Counter template was used.
27+
if ! grep -q 'pub contract Counter' my_workspace_contract/src/main.nr; then
28+
echo "Expected Counter contract from aztec init."
29+
exit 1
30+
fi
2631

2732
# 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
2833
# a remote git tag, so we need to rewrite dependencies to use local aztec-nr.
29-
sed -i 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' \
34+
sed -i \
35+
-e 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' \
36+
-e 's|balance_set = .*git.*AztecProtocol/aztec-nr.*|balance_set = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/balance-set" }|' \
3037
my_workspace_contract/Nargo.toml my_workspace_test/Nargo.toml
3138

32-
# Compile the default scaffold contract.
39+
# Compile the Counter contract.
3340
aztec compile
3441

35-
# Run the default scaffold tests.
42+
# Run the Counter tests.
3643
aztec test
3744

38-
# --- Test adding a second contract to the workspace ---
45+
# --- Test adding a blank contract to the workspace with `aztec new` ---
3946
aztec new token
4047

4148
# Verify token crates were created.
@@ -57,8 +64,15 @@ if ! grep -q '"my_workspace_contract"' Nargo.toml || \
5764
exit 1
5865
fi
5966

67+
# Verify the blank template was used for the new contract.
68+
if ! grep -q 'pub contract Main' token_contract/src/main.nr; then
69+
echo "Expected blank contract from aztec new."
70+
exit 1
71+
fi
72+
6073
# Rewrite aztec deps for token crates too.
61-
sed -i 's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' \
74+
sed -i \
75+
's|aztec = .*git.*AztecProtocol/aztec-nr.*|aztec = { path="/home/ubuntu/aztec-packages/noir-projects/aztec-nr/aztec" }|' \
6276
token_contract/Nargo.toml token_test/Nargo.toml
6377

6478
# Compile and test the full workspace (both contracts).

docs/developer_versioned_docs/version-v4.1.0-rc.2/docs/aztec-js/how_to_use_authwit.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Therefore it is recommended to read the `aztec-nr` [guide on authwitnesses](../a
3333

3434
The authwit system supports different intent types depending on your use case:
3535

36-
- **`CallIntent`**: Use when authorizing a specific contract function call. Contains `{ caller, action }` where `action` is a `ContractFunctionInteraction`.
36+
- **`CallIntent`**: Use when authorizing a specific contract function call. Contains `{ caller, call }` where `call` is a `FunctionCall`, typically obtained with `await interaction.getFunctionCall()`.
37+
- **`ContractFunctionInteractionCallIntent`**: Convenience form that takes the interaction directly. Contains `{ caller, action }` where `action` is a `ContractFunctionInteraction`; internally resolved to a `FunctionCall` before signing.
3738
- **`IntentInnerHash`**: Use when authorizing arbitrary data. Contains `{ consumer, innerHash }` where `consumer` is the contract that will verify the authwit.
3839

3940
## Create private authwits

docs/developer_versioned_docs/version-v4.1.0-rc.2/docs/aztec-nr/debugging.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Log values from your contract using `debug_log`:
3333

3434
```rust
3535
// Import debug logging
36-
use dep::aztec::oracle::debug_log::{ debug_log, debug_log_format };
36+
use aztec::oracle::logging::{ debug_log, debug_log_format };
3737

3838
// Log simple messages
3939
debug_log("checkpoint reached");
@@ -65,23 +65,20 @@ LOG_LEVEL="info;debug:simulator:client_execution_context;debug:simulator:client_
6565
```
6666

6767
:::info Log filter format
68-
`LOG_LEVEL` accepts a semicolon-delimited list of filters. Each filter can be:
69-
70-
- `level` - Sets default level for all modules
71-
- `level:module` - Sets level for a specific module
72-
- `level:module:submodule` - Sets level for a specific submodule
68+
`LOG_LEVEL` is a semicolon-delimited list. The **first segment must be a bare log level** — it sets the default level for all modules. Subsequent segments are `level:module` (or `level:module:submodule`) overrides.
7369

7470
```bash
7571
# Default level only
7672
LOG_LEVEL="debug"
7773

78-
# Default level + specific module overrides
74+
# Default level + module overrides
7975
LOG_LEVEL="info;debug:simulator;debug:execution"
8076

81-
# Default level + specific submodule overrides
77+
# Default level + submodule overrides
8278
LOG_LEVEL="info;debug:simulator:client_execution_context;debug:simulator:client_view_context"
8379
```
8480

81+
A bare `level:module` (e.g. `LOG_LEVEL="warn:simulator"`) is **not valid** — the parser reads the first segment as the default level and rejects it with `Invalid log level: warn:simulator`.
8582
:::
8683

8784
## Debugging common errors
@@ -113,9 +110,12 @@ LOG_LEVEL="info;debug:simulator:client_execution_context;debug:simulator:client_
113110
### Quick Fixes for Common Issues
114111

115112
```bash
116-
# Archiver sync issues - force progress with dummy transactions
117-
aztec-wallet send transfer --from test0 --to test0 --amount 0
118-
aztec-wallet send transfer --from test0 --to test0 --amount 0
113+
# Archiver sync issues - force progress with dummy transactions.
114+
# Assumes you have imported the local network test accounts
115+
# (aztec-wallet import-test-accounts) and have a deployed token
116+
# aliased as `testtoken`.
117+
aztec-wallet send transfer --from test0 --contract-address testtoken --args accounts:test0 0
118+
aztec-wallet send transfer --from test0 --contract-address testtoken --args accounts:test0 0
119119

120120
# L1 to L2 message pending - wait for inclusion
121121
# Messages need 2 blocks to be processed
@@ -207,7 +207,7 @@ LOG_LEVEL=verbose aztec start --local-network
207207
### Common debug imports
208208

209209
```rust
210-
use dep::aztec::oracle::debug_log::{ debug_log, debug_log_format };
210+
use aztec::oracle::logging::{ debug_log, debug_log_format };
211211
```
212212

213213
### Check contract registration

docs/developer_versioned_docs/version-v4.1.0-rc.2/docs/aztec-nr/framework-description/contract_structure.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ High-level structure of how Aztec smart contracts including the different compon
1010

1111
## Directory structure
1212

13-
Here's a common layout for a basic Aztec.nr Contract project:
13+
When you create a new project with `aztec new my_project`, it generates a single-crate Noir contract project:
1414

1515
```text title="layout of an aztec contract project"
16-
─── my_aztec_contract_project
17-
├── src
18-
└── main.nr <-- your contract
19-
└── Nargo.toml <-- package and dependency management
16+
─── my_project
17+
├── Nargo.toml <-- contract package and dependencies
18+
└── src
19+
└── main.nr <-- your contract
2020
```
2121

22+
`Nargo.toml` declares the contract package (with `type = "contract"`) and its dependencies. Your contract code lives in `src/main.nr`. Noir tests using `#[test]` live alongside the contract in the same crate — see [Testing Contracts](../testing_contracts.md).
23+
24+
To add another contract as a sibling of an existing one, run `aztec new <name>` from the parent directory (each contract is its own crate). To initialize a contract project inside an existing empty directory instead, `cd` into it and run `aztec init` (it takes no positional argument; pass `--name <name>` if you want the package name to differ from the directory name).
25+
2226
See the vanilla Noir docs for [more info on packages](https://noir-lang.org/docs/noir/modules_packages_crates/crates_and_packages).
2327

2428
## Contract block
@@ -44,7 +48,7 @@ The `#[aztec]` macro performs a lot of the low-level operations required to take
4448

4549
## Imports
4650

47-
Aside from the [`#[aztec]`](pathname:///aztec-nr-api/testnet/noir_aztec/macros/aztec/fn.aztec) macro import, all other imports need to go _inside_ the `contract` block - this is because `contract` acts like `mod`, creating a new [module](https://noir-lang.org/docs/noir/modules_packages_crates/modules).
51+
Aside from the [`#[aztec]`](pathname:///aztec-nr-api/mainnet/noir_aztec/macros/fn.aztec) macro import, all other imports need to go _inside_ the `contract` block - this is because `contract` acts like `mod`, creating a new [module](https://noir-lang.org/docs/noir/modules_packages_crates/modules).
4852

4953
```rust
5054
use aztec::macros::aztec;

docs/developer_versioned_docs/version-v4.1.0-rc.2/docs/aztec-nr/framework-description/functions/how_to_define_functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ Create constructor-like functions using the `#[initializer]` annotation:
121121
#[initializer]
122122
#[external("private")]
123123
// We can name our initializer anything we want as long as it's marked as aztec(initializer)
124-
fn initialize(headstart: u64, owner: AztecAddress) {
125-
self.storage.counters.at(owner).add(headstart as u128).deliver(
124+
fn initialize(headstart: u128, owner: AztecAddress) {
125+
self.storage.counters.at(owner).add(headstart).deliver(
126126
MessageDelivery.ONCHAIN_CONSTRAINED,
127127
);
128128
}

docs/developer_versioned_docs/version-v4.1.0-rc.2/docs/aztec-nr/index.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,15 @@ storage.votes.insert(new_vote).deliver(vote_counter); // the vote counter accoun
4242

4343
### Flow
4444

45-
1. Write your contract and specify your contract dependencies. Every contract written for Aztec will have
46-
aztec-nr as a dependency. Add it to your `Nargo.toml` with
45+
1. Write your contract and specify your contract dependencies. Create a new project with `aztec new my_project`, which creates a single-crate Noir contract project (`Nargo.toml` + `src/main.nr`) with the `aztec` dependency already configured. If you need additional dependencies, add them to `my_project/Nargo.toml`:
4746

4847
```toml
49-
# Nargo.toml
48+
# my_project/Nargo.toml
5049
[dependencies]
5150
aztec = { git="https://github.com/AztecProtocol/aztec-nr/", tag="v4.1.0-rc.2", directory="aztec" }
5251
```
5352

54-
Update your `main.nr` contract file to use the Aztec.nr macros for writing contracts.
53+
Update your `my_project/src/main.nr` contract file to use the Aztec.nr macros for writing contracts.
5554

5655
```rust title="setup" showLineNumbers
5756
use aztec::macros::aztec;

docs/developer_versioned_docs/version-v4.1.0-rc.2/docs/aztec-nr/testing_contracts.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,28 @@ Always use `aztec test` instead of `nargo test`. The `TestEnvironment` requires
4646

4747
## Basic test structure
4848

49+
Tests live in the same crate as your contract. `aztec new` creates a single-crate project, and the convention is to place `#[test]` functions in a `mod tests` block alongside the contract (or in submodules of the crate):
50+
4951
```rust
50-
use crate::MyContract;
51-
use aztec::{
52-
protocol::address::AztecAddress,
53-
test::helpers::test_environment::TestEnvironment,
54-
};
52+
use aztec::macros::aztec;
5553

56-
#[test]
57-
unconstrained fn test_basic_flow() {
58-
// 1. Create test environment
59-
let mut env = TestEnvironment::new();
54+
#[aztec]
55+
pub contract MyContract {
56+
// ...contract functions...
57+
}
6058

61-
// 2. Create accounts
62-
let owner = env.create_light_account();
59+
mod tests {
60+
use super::MyContract;
61+
use aztec::test::helpers::test_environment::TestEnvironment;
62+
63+
#[test]
64+
unconstrained fn test_basic_flow() {
65+
// 1. Create test environment
66+
let mut env = TestEnvironment::new();
67+
68+
// 2. Create accounts
69+
let _owner = env.create_light_account();
70+
}
6371
}
6472
```
6573

@@ -72,13 +80,14 @@ unconstrained fn test_basic_flow() {
7280
:::
7381

7482
:::tip Organizing test files
75-
You can organize tests in separate files:
83+
For larger test suites, split tests into submodules of your crate rather than keeping them all inside `main.nr`:
7684

77-
- Create `src/test.nr` with `mod utils;` to import helper functions
78-
- Split tests into modules like `src/test/transfer_tests.nr`, `src/test/auth_tests.nr`
79-
- Import the test module in `src/main.nr` with `mod test;`
80-
- Share setup functions in `src/test/utils.nr`
81-
:::
85+
- Create modules like `src/transfer_tests.nr`, `src/auth_tests.nr`
86+
- Declare them from `src/main.nr` with `mod transfer_tests;`, `mod auth_tests;`
87+
- Share setup functions in `src/test_utils.nr`
88+
89+
See the [aztec-standards token contract](https://github.com/defi-wonderland/aztec-standards/tree/dev/src/token_contract) for a worked example of this layout.
90+
:::
8291

8392
## Deploying contracts
8493

docs/developer_versioned_docs/version-v4.1.0-rc.2/docs/tutorials/contract_tutorials/counter_contract.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ Let’s create a constructor method to run on deployment that assigns an initial
125125
#[initializer]
126126
#[external("private")]
127127
// We can name our initializer anything we want as long as it's marked as aztec(initializer)
128-
fn initialize(headstart: u64, owner: AztecAddress) {
129-
self.storage.counters.at(owner).add(headstart as u128).deliver(
128+
fn initialize(headstart: u128, owner: AztecAddress) {
129+
self.storage.counters.at(owner).add(headstart).deliver(
130130
MessageDelivery.ONCHAIN_CONSTRAINED,
131131
);
132132
}

docs/developer_versioned_docs/version-v4.1.0-rc.2/docs/tutorials/contract_tutorials/recursive_verification.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ nargo test
202202
Expected output:
203203

204204
```text
205-
[hello_circuit] Running 1 test functions
206-
[hello_circuit] Testing test_main... ok
207-
[hello_circuit] All tests passed
205+
[hello_circuit] Running 1 test function
206+
[hello_circuit] Testing test_main ... ok
207+
[hello_circuit] 1 test passed
208208
```
209209

210210
**Tip**: Circuit tests run without generating proofs, making them fast for development. Use them to verify your circuit logic before the more expensive proof generation step.
@@ -228,9 +228,11 @@ The contract demonstrates several important patterns:
228228
Use `aztec new` to generate the contract project structure:
229229

230230
```bash
231-
aztec new contract --name ValueNotEqual
231+
aztec new --name ValueNotEqual contract
232232
```
233233

234+
The `aztec new` wrapper stops parsing arguments at the first positional, so `--name` must come **before** the `contract` path — otherwise the flag is silently dropped and the Nargo package ends up named `contract`. The Nargo package name (`--name`) is independent of the Noir contract name declared inside `main.nr`; the artifact filename downstream is driven by the contract name.
235+
234236
This creates:
235237

236238
```tree
@@ -701,7 +703,7 @@ Expected output:
701703
Proof verification: SUCCESS
702704
Using deflattenFields to convert proof...
703705
VK size: 115
704-
Proof size: 508
706+
Proof size: 500
705707
Public inputs: 1
706708
Done
707709
```

0 commit comments

Comments
 (0)