Overview
Aztec.nr is a Noir framework used to develop and test Aztec smart contracts. It contains both high-level abstractions (state variables, messages) and low-level protocol primitives, providing granular control to developers if they want custom contracts.
If you are already familiar with writing Aztec smart contracts and Aztec.nr, visit the API reference.
Motivation
Noir can be used to write circuits, but Aztec contracts are more complex than this. They include multiple external functions, each of a different type: circuits for private functions, AVM bytecode for public functions, and brillig bytecode for utility functions. The circuits for private functions are also need to interact with the protocol's kernel circuits in specific ways, so manually writing them, and then combining everything into a contract artifact is involved work. Aztec.nr takes care of all of this heavy lifting and makes writing contracts as simple as marking functions with the corresponding attributes e.g. #[external(private)].
It allows safe and easy implementation of well understood design patterns, such as the multiple kinds of private state variables, meaning developers don't need to understand the low-levels of how the protocol works. These features are optional, however, advanced developers are not prevented from building their own custom solutions.
Design principles
- Make it hard to shoot yourself in the foot by making it clear when something is unsafe.
- Dangerous actions should be easy to spot. e.g. ignoring return values or calling functions with the
_unsafeprefix. - This is achieved by having rails that intentionally trigger a developer's "WTF?" response, to ensure they understand what they're doing.
A good example of this is writing to private state variables. These functions return a NoteMessage struct, which results in a compiler error unless used. This is because writing to private state also requires sending an encrypted message with the new state to the people that need to access it - otherwise, because it is private, they will not even know the state changed.
storage.votes.insert(new_vote); // compiler error - unused NoteMessagePendingDelivery return value
storage.votes.insert(new_vote).deliver(vote_counter); // the vote counter account will now be notified of the new vote
Contract Development
Prerequisites
- Install Aztec Local Network and Tooling
- Install the Noir VSCode Extension for syntax highlighting and error detection.
Flow
- Write your contract and specify your contract dependencies. Every contract written for Aztec will have
aztec-nr as a dependency. Add it to your
Nargo.tomlwith
# Nargo.toml
[dependencies]
aztec = { git="https://github.com/AztecProtocol/aztec-nr/", tag="#include_aztec_version", directory="aztec" }
Update your 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
and import dependencies from the Aztec.nr library.
#include_code imports /docs/examples/contracts/counter_contract/src/main.nr rust
You can see a complete example of a simple counter contract written with Aztec.nr here.
- Profile the private functions in your contract to get a sense of how long generating client side proofs will take
- Write unit tests directly in Noir and end-to-end tests with TypeScript
- Compile your contract
- Deploy your contract with Aztec.js
Section Contents
📄️ Noir VSCode Extension
Learn how to install and configure the Noir Language Server for a better development experience.
📄️ Contract Deployment Quick Reference
A practical guide to determine which deployment steps your Aztec contract needs and when functions become callable.
📄️ Compiling Contracts
Compile your Aztec smart contracts into deployable artifacts using aztec command.
📄️ Debugging Aztec Code
This guide shows you how to debug issues in your Aztec contracts.
🗃️ Framework Description
15 items
📄️ Testing Contracts
Write and run tests for your Aztec smart contracts using Noir's TestEnvironment.
📄️ Aztec.nr API Reference
Auto-generated API reference documentation for the Aztec.nr smart contract framework.