Skip to content

Commit

Permalink
feat!: storage_layout and #[aztec(storage)] (AztecProtocol/aztec-pa…
Browse files Browse the repository at this point in the history
…ckages#5387)

Requires AztecProtocol/aztec-packages#5386

Closes AztecProtocol/aztec-packages#5079

Leveraging the new `#[abi(tag)]` export attribute, the
`#[aztec(storage]` and `#[aztec(note)]` decorators are now used by the
aztec macros to generate exportable global structs that include storage
and notes info. These are then interpreted by `noir-compiler` in the ts
codegen and exposed through the contract classes.

```typescript

MyContractClass.storage.my_storage_variable.slot: Fr;
MyContractClass.notes.MyNote.id: Fr;

```

In the process I realized we didn't really need the
`process_def_collector` pass, which has been removed (one less thing to
worry about before moving to metaprogramming!) in favor of using
`#[aztec(note)]` to identify notes that need to get included in the
autogenerated `compute_note_hash_and_nullifier` implementation.

---------

Co-authored-by: esau <[email protected]>
  • Loading branch information
AztecBot and sklppy88 committed Apr 8, 2024
1 parent a0f7474 commit 09df836
Show file tree
Hide file tree
Showing 145 changed files with 2,685 additions and 1,922 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bb719200034e3bc6db09fb56538dadca4203abf4
2c1d795fc4c8b94e48184fa7aa75f97633aa3173
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ if [[ -z "${SKIP_NIX:-}" ]] && has nix; then
use nix
fi

fi
fi
2 changes: 0 additions & 2 deletions .github/Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
passthrough = [
"HOME",
"RUST_BACKTRACE",
"BARRETENBERG_BIN_DIR",
"BLNS_JSON_PATH"
]
volumes = [
"HOME",
Expand Down
1 change: 1 addition & 0 deletions .github/scripts/acvm_js-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
set -eu

.github/scripts/wasm-bindgen-install.sh
.github/scripts/wasm-opt-install.sh
yarn workspace @noir-lang/acvm_js build
1 change: 1 addition & 0 deletions .github/scripts/noir-wasm-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
set -eu

.github/scripts/wasm-pack-install.sh
.github/scripts/wasm-opt-install.sh
yarn workspace @noir-lang/types build
yarn workspace @noir-lang/noir_wasm build
1 change: 1 addition & 0 deletions .github/scripts/noirc-abi-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
set -eu

.github/scripts/wasm-bindgen-install.sh
.github/scripts/wasm-opt-install.sh
yarn workspace @noir-lang/noirc_abi build
2 changes: 1 addition & 1 deletion .github/scripts/wasm-opt-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cd $(dirname "$0")

./cargo-binstall-install.sh

cargo-binstall wasm-opt --version 0.116.0 -y
cargo-binstall wasm-opt --version 0.116.0 -y --force
17 changes: 6 additions & 11 deletions .github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,16 @@ jobs:
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Install wasm-opt
run: ./.github/scripts/wasm-opt-install.sh

- name: Build noirc_abi
run: ./.github/scripts/noirc-abi-build.sh

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: noirc_abi_wasm
path: ./tooling/noirc_abi_wasm/outputs/out/noirc_abi_wasm
path: |
./tooling/noirc_abi_wasm/nodejs
./tooling/noirc_abi_wasm/web
retention-days: 10


Expand All @@ -100,9 +99,6 @@ jobs:
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Install wasm-opt
run: ./.github/scripts/wasm-opt-install.sh

- name: Build noir_js_types
run: yarn workspace @noir-lang/types build

Expand Down Expand Up @@ -138,17 +134,16 @@ jobs:
- name: Install Yarn dependencies
uses: ./.github/actions/setup

- name: Install wasm-opt
run: ./.github/scripts/wasm-opt-install.sh

- name: Build acvm_js
run: ./.github/scripts/acvm_js-build.sh

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: acvm-js
path: ./acvm-repo/acvm_js/outputs/out/acvm_js
path: |
./acvm-repo/acvm_js/nodejs
./acvm-repo/acvm_js/web
retention-days: 3

test-acvm_js-node:
Expand Down
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ pkg/
# Noir.js
tooling/noir_js/lib

# Nix stuff
**/outputs
result
.envrc.local
.direnv/

# Nargo output
*.proof
*.acir
Expand Down
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"mkhl.direnv",
"jnoortheen.nix-ide",
"rust-lang.rust-analyzer",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
Expand Down
11 changes: 0 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@
"direnv.restart.automatic": true,
"redhat.telemetry.enabled": false,
"yaml.recommendations.show": false,
"nix.serverPath": "nil",
"nix.enableLanguageServer": true,
"nix.serverSettings": {
"nil": {
"formatting": {
"command": [
"nixpkgs-fmt"
]
}
}
},
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": "${workspaceRoot}/.github/workflows/*.yml"
},
Expand Down
48 changes: 16 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ Concretely the following items are on the road map:

This crate's minimum supported rustc version is 1.73.0.

## Working on this project

This project uses [Nix](https://nixos.org/) and [direnv](https://direnv.net/) to streamline the development experience. Please follow [our guidelines](https://noir-lang.org/docs/getting_started/installation/other_install_methods#option-3-compile-from-source) to setup your environment for working on the project.

### Building against a different local/remote version of Barretenberg

If you are working on this project and want a different version of Barretenberg (instead of the version this project is pinned against), you'll want to replace the lockfile version with your version. This can be done by running:

```sh
nix flake lock --override-input barretenberg /absolute/path/to/your/barretenberg
```

You can also point at a fork and/or branch on GitHub using:

```sh
nix flake lock --override-input barretenberg github:username/barretenberg/branch_name
```

__Note:__ You don't want to commit the updated lockfile, as it will fail in CI!

## License

Noir is free and open source. It is distributed under a dual license. (MIT/APACHE)
Expand Down
4 changes: 4 additions & 0 deletions acvm-repo/acir/codegen/acir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ namespace Program {
uint32_t id;
std::vector<Program::Witness> inputs;
std::vector<Program::Witness> outputs;
std::optional<Program::Expression> predicate;

friend bool operator==(const Call&, const Call&);
std::vector<uint8_t> bincodeSerialize() const;
Expand Down Expand Up @@ -6173,6 +6174,7 @@ namespace Program {
if (!(lhs.id == rhs.id)) { return false; }
if (!(lhs.inputs == rhs.inputs)) { return false; }
if (!(lhs.outputs == rhs.outputs)) { return false; }
if (!(lhs.predicate == rhs.predicate)) { return false; }
return true;
}

Expand All @@ -6199,6 +6201,7 @@ void serde::Serializable<Program::Opcode::Call>::serialize(const Program::Opcode
serde::Serializable<decltype(obj.id)>::serialize(obj.id, serializer);
serde::Serializable<decltype(obj.inputs)>::serialize(obj.inputs, serializer);
serde::Serializable<decltype(obj.outputs)>::serialize(obj.outputs, serializer);
serde::Serializable<decltype(obj.predicate)>::serialize(obj.predicate, serializer);
}

template <>
Expand All @@ -6208,6 +6211,7 @@ Program::Opcode::Call serde::Deserializable<Program::Opcode::Call>::deserialize(
obj.id = serde::Deserializable<decltype(obj.id)>::deserialize(deserializer);
obj.inputs = serde::Deserializable<decltype(obj.inputs)>::deserialize(deserializer);
obj.outputs = serde::Deserializable<decltype(obj.outputs)>::deserialize(deserializer);
obj.predicate = serde::Deserializable<decltype(obj.predicate)>::deserialize(deserializer);
return obj;
}

Expand Down
36 changes: 22 additions & 14 deletions acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,25 +216,33 @@ impl std::fmt::Display for Circuit {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "current witness index : {}", self.current_witness_index)?;

let write_public_inputs = |f: &mut std::fmt::Formatter<'_>,
public_inputs: &PublicInputs|
-> Result<(), std::fmt::Error> {
write!(f, "[")?;
let public_input_indices = public_inputs.indices();
for (index, public_input) in public_input_indices.iter().enumerate() {
write!(f, "{public_input}")?;
if index != public_input_indices.len() - 1 {
write!(f, ", ")?;
let write_witness_indices =
|f: &mut std::fmt::Formatter<'_>, indices: &[u32]| -> Result<(), std::fmt::Error> {
write!(f, "[")?;
for (index, witness_index) in indices.iter().enumerate() {
write!(f, "{witness_index}")?;
if index != indices.len() - 1 {
write!(f, ", ")?;
}
}
}
writeln!(f, "]")
};
writeln!(f, "]")
};

write!(f, "private parameters indices : ")?;
write_witness_indices(
f,
&self
.private_parameters
.iter()
.map(|witness| witness.witness_index())
.collect::<Vec<_>>(),
)?;

write!(f, "public parameters indices : ")?;
write_public_inputs(f, &self.public_parameters)?;
write_witness_indices(f, &self.public_parameters.indices())?;

write!(f, "return value indices : ")?;
write_public_inputs(f, &self.return_values)?;
write_witness_indices(f, &self.return_values.indices())?;

for opcode in &self.opcodes {
writeln!(f, "{opcode}")?;
Expand Down
Loading

0 comments on commit 09df836

Please sign in to comment.