Skip to content

Commit

Permalink
chore: pull out more sync stuff (#11617)
Browse files Browse the repository at this point in the history
Please read [contributing guidelines](CONTRIBUTING.md) and remove this
line.
  • Loading branch information
TomAFrench authored Jan 30, 2025
1 parent 15f3cf0 commit 30dc56c
Show file tree
Hide file tree
Showing 28 changed files with 3,653 additions and 494 deletions.
515 changes: 260 additions & 255 deletions noir/noir-repo/Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion noir/noir-repo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ members = [
"tooling/nargo_cli",
"tooling/nargo_toml",
"tooling/noirc_artifacts",
"tooling/noirc_artifacts_info",
"tooling/noirc_abi",
"tooling/noirc_abi_wasm",
"tooling/acvm_cli",
Expand All @@ -35,7 +36,11 @@ members = [
# Utility crates
"utils/iter-extended",
]
default-members = ["tooling/nargo_cli", "tooling/acvm_cli", "tooling/profiler"]
default-members = [
"tooling/nargo_cli",
"tooling/acvm_cli",
"tooling/profiler",
]
resolver = "2"

[workspace.package]
Expand Down Expand Up @@ -83,6 +88,7 @@ noir_lsp = { path = "tooling/lsp" }
noir_debugger = { path = "tooling/debugger" }
noirc_abi = { path = "tooling/noirc_abi" }
noirc_artifacts = { path = "tooling/noirc_artifacts" }
noirc_artifacts_info = { path = "tooling/noirc_artifacts_info" }

# Arkworks
ark-bn254 = { version = "^0.5.0", default-features = false, features = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl CallStackHelper {
result.push(self.locations[call_stack.index()].value);
call_stack = parent;
}
result.reverse();
result
}

Expand Down
2 changes: 1 addition & 1 deletion noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct CfgNode {
pub(crate) successors: BTreeSet<BasicBlockId>,
}

#[derive(Clone)]
#[derive(Clone, Default)]
/// The Control Flow Graph maintains a mapping of blocks to their predecessors
/// and successors where predecessors are basic blocks and successors are
/// basic blocks.
Expand Down
1 change: 1 addition & 0 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa/ir/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl DominatorTreeNode {
}

/// The dominator tree for a single function.
#[derive(Default)]
pub(crate) struct DominatorTree {
/// The nodes of the dominator tree
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum Visit {
Last,
}

#[derive(Default)]
pub(crate) struct PostOrder(Vec<BasicBlockId>);

impl PostOrder {
Expand Down
3 changes: 2 additions & 1 deletion noir/noir-repo/docs/docs/getting_started/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ We can now use `nargo` to generate a _Prover.toml_ file, where our input values
```sh
cd hello_world
nargo check
```

Let's feed some valid values into this file:

Expand Down Expand Up @@ -113,7 +114,7 @@ bb verify -k ./target/vk -p ./target/proof

Notice that in order to verify a proof, the verifier knows nothing but the circuit, which is compiled and used to generate the verification key. This is obviously quite important: private inputs remain private.

As for the public inputs, you may have noticed they haven't been specified. This behavior varies with each particular backend, but barretenberg typically attaches them to the proof. You can see them by parsing and splitting it. For example for if your public inputs are 32 bytes:
As for the public inputs, you may have noticed they haven't been specified. This behavior varies with each particular backend, but barretenberg typically attaches them to the proof. You can see them by parsing and splitting it. For example if your public inputs are 32 bytes:

```bash
head -c 32 ./target/proof | od -An -v -t x1 | tr -d $' \n'
Expand Down
27 changes: 23 additions & 4 deletions noir/noir-repo/docs/docs/noir/concepts/control_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ if a == 0 {
assert(x == 2);
```

## Loops
## For loops

Noir has one kind of loop: the `for` loop. `for` loops allow you to repeat a block of code multiple
times.
`for` loops allow you to repeat a block of code multiple times.

The following block of code between the braces is run 10 times.

Expand All @@ -48,7 +47,7 @@ The index for loops is of type `u64`.

### Break and Continue

In unconstrained code, `break` and `continue` are also allowed in `for` loops. These are only allowed
In unconstrained code, `break` and `continue` are also allowed in `for` and `loop` loops. These are only allowed
in unconstrained code since normal constrained code requires that Noir knows exactly how many iterations
a loop may have. `break` and `continue` can be used like so:

Expand Down Expand Up @@ -77,3 +76,23 @@ above, `continue` will jump to `println("Iteration start")` when used. Note that
The iteration variable `i` is still increased by one as normal when `continue` is used.

`break` and `continue` cannot currently be used to jump out of more than a single loop at a time.

## Loops

In unconstrained code, `loop` is allowed for loops that end with a `break`.
A `loop` must have at least one `break` in it.
This is only allowed in unconstrained code since normal constrained code requires that Noir knows exactly how many iterations
a loop may have.

```rust
let mut i = 10
loop {
println(i);
i -= 1;

if i == 0 {
break;
}
}
```

6 changes: 3 additions & 3 deletions noir/noir-repo/docs/docs/noir/concepts/data_types/slices.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ View the corresponding test file [here][test-file].

### push_front

Returns a new array with the specified element inserted at index 0. The existing elements indexes are incremented by 1.
Returns a new slice with the specified element inserted at index 0. The existing elements indexes are incremented by 1.

```rust
fn push_front(_self: Self, _elem: T) -> Self
Expand All @@ -75,7 +75,7 @@ View the corresponding test file [here][test-file].

### pop_front

Returns a tuple of two items, the first element of the array and the rest of the array.
Returns a tuple of two items, the first element of the slice and the rest of the slice.

```rust
fn pop_front(_self: Self) -> (T, Self)
Expand All @@ -91,7 +91,7 @@ View the corresponding test file [here][test-file].

### pop_back

Returns a tuple of two items, the beginning of the array with the last element omitted and the last element.
Returns a tuple of two items, the beginning of the slice with the last element omitted and the last element.

```rust
fn pop_back(_self: Self) -> (Self, T)
Expand Down
17 changes: 14 additions & 3 deletions noir/noir-repo/docs/docs/noir/concepts/generics.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl<let N: u32> BigInt<N> {
fn first(first: BigInt<N>, second: BigInt<N>) -> Self {
assert(first.limbs != second.limbs);
first
}

fn second(first: BigInt<N>, second: Self) -> Self {
assert(first.limbs != second.limbs);
Expand Down Expand Up @@ -96,7 +97,17 @@ fn main() {
// We can use first_element_is_equal for arrays of any type
// as long as we have an Eq impl for the types we pass in
let array = [MyStruct::new(), MyStruct::new()];
assert(array_eq(array, array, MyStruct::eq));
assert(first_element_is_equal(array, array));
}

struct MyStruct {
foo: Field
}

impl MyStruct {
fn new() -> Self {
MyStruct { foo: 0 }
}
}

impl Eq for MyStruct {
Expand Down Expand Up @@ -152,9 +163,9 @@ fn example() {
// there is no matching impl for `u32: MyTrait`.
//
// Substituting the `10` on the left hand side of this assert
// with `10 as u32` would also fail with a type mismatch as we
// with `10 as u32` would fail with a type mismatch as we
// are expecting a `Field` from the right hand side.
assert(10 as u32 == foo.generic_method::<Field>());
assert(10 == foo.generic_method::<Field>());
}
```

Expand Down
1 change: 1 addition & 0 deletions noir/noir-repo/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"version": "yarn version::stables && ./scripts/cut_version.sh"
},
"dependencies": {
"@cookbookdev/docsbot": "^4.24.9",
"@docusaurus/core": "^3.5.2",
"@docusaurus/preset-classic": "^3.5.2",
"@easyops-cn/docusaurus-search-local": "^0.35.0",
Expand Down
14 changes: 14 additions & 0 deletions noir/noir-repo/docs/src/theme/SearchBar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import SearchBar from '@theme-original/SearchBar';
import AskCookbook from '@cookbookdev/docsbot/react'
import BrowserOnly from '@docusaurus/BrowserOnly';
/** It's a public API key, so it's safe to expose it here */
const COOKBOOK_PUBLIC_API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NzVhMGVkODQ4MGI5OThmNzlhNjNhOTciLCJpYXQiOjE3MzM5NTUyODgsImV4cCI6MjA0OTUzMTI4OH0.NzQlH2sfhJkjvnYxoaRgSY6nRyNClxHg57n3-JueN9Q";
export default function SearchBarWrapper(props) {
return (
<>
<SearchBar {...props} />
<BrowserOnly>{() => <AskCookbook apiKey={COOKBOOK_PUBLIC_API_KEY} /> }</BrowserOnly>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ curve you want to use, which would be specified using any one of the methods
`std::ec::{tecurve,montcurve,swcurve}::{affine,curvegroup}::new` which take the coefficients in the
defining equation together with a generator point as parameters. You can find more detail in the
comments in
[`noir_stdlib/src/ec/mod.nr`](https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/ec/mod.nr), but
[`noir_stdlib/src/ec/mod.nr`](https://github.com/noir-lang/ec/blob/master/src/lib.nr), but
the gist of it is that the elliptic curves of interest are usually expressed in one of the standard
forms implemented here (Twisted Edwards, Montgomery and Short Weierstraß), and in addition to that,
you could choose to use `affine` coordinates (Cartesian coordinates - the usual (x,y) - possibly
Expand Down Expand Up @@ -67,12 +67,12 @@ does indeed lie on `c` by calling `c.contains(p1)`.
the curve configurations, the SWU map-to-curve method may be called as `c.swu_map(z,n)`, where
`z: Field` depends on `Field` and `c` and must be chosen by the user (the conditions it needs to
satisfy are specified in the comments
[here](https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/ec/mod.nr)).
[here](https://github.com/noir-lang/ec/blob/master/src/lib.nr)).

## Examples

The
[ec_baby_jubjub test](https://github.com/noir-lang/noir/blob/master/test_programs/compile_success_empty/ec_baby_jubjub/src/main.nr)
[ec_baby_jubjub test](https://github.com/noir-lang/ec/blob/460dff3cc6a1c0c5d9449f99a0a158bde21c19a8/src/lib.nr#L210)
illustrates all of the above primitives on various forms of the Baby Jubjub curve. A couple of more
interesting examples in Noir would be:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ curve you want to use, which would be specified using any one of the methods
`std::ec::{tecurve,montcurve,swcurve}::{affine,curvegroup}::new` which take the coefficients in the
defining equation together with a generator point as parameters. You can find more detail in the
comments in
[`noir_stdlib/src/ec/mod.nr`](https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/ec/mod.nr), but
[`noir_stdlib/src/ec/mod.nr`](https://github.com/noir-lang/ec/blob/master/src/lib.nr), but
the gist of it is that the elliptic curves of interest are usually expressed in one of the standard
forms implemented here (Twisted Edwards, Montgomery and Short Weierstraß), and in addition to that,
you could choose to use `affine` coordinates (Cartesian coordinates - the usual (x,y) - possibly
Expand Down Expand Up @@ -67,12 +67,12 @@ does indeed lie on `c` by calling `c.contains(p1)`.
the curve configurations, the SWU map-to-curve method may be called as `c.swu_map(z,n)`, where
`z: Field` depends on `Field` and `c` and must be chosen by the user (the conditions it needs to
satisfy are specified in the comments
[here](https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/ec/mod.nr)).
[here](https://github.com/noir-lang/ec/blob/master/src/lib.nr)).

## Examples

The
[ec_baby_jubjub test](https://github.com/noir-lang/noir/blob/master/test_programs/compile_success_empty/ec_baby_jubjub/src/main.nr)
[ec_baby_jubjub test](https://github.com/noir-lang/ec/blob/460dff3cc6a1c0c5d9449f99a0a158bde21c19a8/src/lib.nr#L210)
illustrates all of the above primitives on various forms of the Baby Jubjub curve. A couple of more
interesting examples in Noir would be:

Expand Down
5 changes: 4 additions & 1 deletion noir/noir-repo/test_programs/memory_report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e
sudo apt-get install heaptrack

NARGO="nargo"
PARSE_MEMORY=$(realpath "$(dirname "$0")/parse_memory.sh")


# Tests to be profiled for memory report
tests_to_profile=("keccak256" "workspace" "regression_4709" "ram_blowup_regression")
Expand Down Expand Up @@ -54,7 +56,8 @@ for test_name in ${tests_to_profile[@]}; do
len=${#consumption}-30
peak=${consumption:30:len}
rm $current_dir/$test_name"_heap_analysis.txt"
echo -e " {\n \"artifact_name\":\"$test_name\",\n \"peak_memory\":\"$peak\"\n }" >> $current_dir"/memory_report.json"
peak_memory=$($PARSE_MEMORY $peak)
echo -e " {\n \"artifact_name\":\"$test_name\",\n \"peak_memory\":\"$peak_memory\"\n }" >> $current_dir"/memory_report.json"
done

echo "]}" >> $current_dir"/memory_report.json"
Expand Down
21 changes: 21 additions & 0 deletions noir/noir-repo/test_programs/parse_memory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
set -e

# This script accepts a string representing the amount of memory allocated as outputted by `heaptrack`
# and standardizes it to be in terms of megabytes as `heaptrack` will report different units depending on the duration.

DIGITS='([0-9]+(\.[0-9]+)?)'
KILOBYTES_REGEX=^${DIGITS}K$
MEGABYTES_REGEX=^${DIGITS}M$
GIGABYTES_REGEX=^${DIGITS}G$

if [[ $1 =~ $KILOBYTES_REGEX ]]; then
echo ${BASH_REMATCH[1]} 1000 | awk '{printf "%.3f\n", $1/$2}'
elif [[ $1 =~ $MEGABYTES_REGEX ]]; then
echo ${BASH_REMATCH[1]} | awk '{printf "%.3f\n", $1}'
elif [[ $1 =~ $GIGABYTES_REGEX ]]; then
echo ${BASH_REMATCH[1]} 1000 | awk '{printf "%.3f\n", $1*$2}'
else
echo "Could not parse memory: unrecognized format" 1>&2
exit 1
fi
1 change: 1 addition & 0 deletions noir/noir-repo/tooling/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ noirc_frontend = { workspace = true, features = ["bn254"] }
noirc_abi.workspace = true
noirc_errors.workspace = true
noirc_artifacts.workspace = true
noirc_artifacts_info.workspace = true
acvm = { workspace = true, features = ["bn254"] }
bn254_blackbox_solver.workspace = true
toml.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions noir/noir-repo/tooling/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ pub(crate) struct CheckCommand {

/// Force overwrite of existing files
#[clap(long = "overwrite")]
allow_overwrite: bool,

/// Show the program hash.
#[clap(long)]
show_program_hash: bool,
pub(super) allow_overwrite: bool,

#[clap(flatten)]
compile_options: CompileOptions,

/// Just show the hash of each paackages, without actually performing the check.
#[clap(long)]
show_program_hash: bool,
}

pub(crate) fn run(args: CheckCommand, config: NargoConfig) -> Result<(), CliError> {
Expand Down
8 changes: 7 additions & 1 deletion noir/noir-repo/tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ mod tests {
use noirc_driver::{CompileOptions, CrateName};

use crate::cli::compile_cmd::{get_target_width, parse_workspace, read_workspace};
use crate::cli::test_cmd::formatters::diagnostic_to_string;

/// Try to find the directory that Cargo sets when it is running;
/// otherwise fallback to assuming the CWD is the root of the repository
Expand Down Expand Up @@ -414,7 +415,12 @@ mod tests {
&CompileOptions::default(),
None,
)
.expect("failed to compile");
.unwrap_or_else(|err| {
for diagnostic in err {
println!("{}", diagnostic_to_string(&diagnostic, &file_manager));
}
panic!("Failed to compile")
});

let width = get_target_width(package.expression_width, None);

Expand Down
Loading

0 comments on commit 30dc56c

Please sign in to comment.