Skip to content

Commit

Permalink
Merge branch 'master' into tf/organise-parser
Browse files Browse the repository at this point in the history
* master:
  chore!: reserve `unchecked` keyword (#4432)
  chore: address code review comments of PR4398 (#4435)
  feat: Sync from aztec-packages (#4439)
  feat: Sync from aztec-packages (#4438)
  chore(docs): correct 'Edit this page' URL for dev docs (#4433)
  feat: Sync from aztec-packages (#4390)
  chore(docs): fix external contributor force push workflow (#4437)
  chore!: Remove empty value from bounded vec (#4431)
  chore: nargo fmt (#4434)
  feat: add poseidon2 opcode implementation for acvm/brillig, and Noir (#4398)
  fix: remove panic when generic array length is not resolvable (#4408)
  chore(ci): enforce formatting of noir code in CI (#4422)
  fix: correct formatting for databus visibility types (#4423)
  chore: remove duplicate `parse_all` function in wasm compiler (#4411)
  chore(ci): prevent msrv checks from blocking PRs (#4414)
  feat: expose separate functions to compile programs vs contracts in `noir_wasm` (#4413)
  chore: do not panic when dividing by zero (#4424)
  • Loading branch information
TomAFrench committed Feb 27, 2024
2 parents def29f3 + 9544813 commit f26342e
Show file tree
Hide file tree
Showing 122 changed files with 3,203 additions and 931 deletions.
1 change: 1 addition & 0 deletions .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
e69b58660ff843350e1e098d8f1a84f4ce3d3c34
13 changes: 13 additions & 0 deletions .github/ACVM_NOT_PUBLISHABLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: "ACVM crates are not publishable"
assignees: TomAFrench kevaundray savio-sou
---


The ACVM crates are currently unpublishable, making a release will NOT push our crates to crates.io.

This is likely due to a crate we depend on bumping its MSRV above our own. Our lockfile is not taken into account when publishing to crates.io (as people downloading our crate don't use it) so we need to be able to use the most up to date versions of our dependencies (including transient dependencies) specified.

Check the [MSRV check]({{env.WORKFLOW_URL}}) workflow for details.

This issue was raised by the workflow `{{env.WORKFLOW_NAME}}`
5 changes: 0 additions & 5 deletions .github/EXTERNAL_CONTRIBUTOR_PR_COMMENT.md

This file was deleted.

65 changes: 65 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,68 @@ jobs:

- name: Run `yarn lint`
run: yarn lint

build-nargo:
runs-on: ubuntu-22.04
timeout-minutes: 30

steps:
- name: Checkout Noir repo
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/[email protected]

- uses: Swatinem/rust-cache@v2
with:
key: x86_64-unknown-linux-gnu
cache-on-failure: true
save-if: ${{ github.event_name != 'merge_group' }}

- name: Build Nargo
run: cargo build --package nargo_cli --release

- name: Package artifacts
run: |
mkdir dist
cp ./target/release/nargo ./dist/nargo
7z a -ttar -so -an ./dist/* | 7z a -si ./nargo-x86_64-unknown-linux-gnu.tar.gz
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nargo
path: ./dist/*
retention-days: 3

nargo_fmt:
needs: [build-nargo]
name: Nargo fmt
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download nargo binary
uses: actions/download-artifact@v4
with:
name: nargo
path: ./nargo

- name: Set nargo on PATH
run: |
nargo_binary="${{ github.workspace }}/nargo/nargo"
chmod +x $nargo_binary
echo "$(dirname $nargo_binary)" >> $GITHUB_PATH
export PATH="$PATH:$(dirname $nargo_binary)"
nargo -V
- name: Format stdlib
working-directory: ./noir_stdlib
run: nargo fmt --check

- name: Format test suite
working-directory: ./test_programs
run: ./format.sh check
6 changes: 5 additions & 1 deletion .github/workflows/pull-request-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
- name: Post comment on force pushes
uses: marocchino/sticky-pull-request-comment@v2
with:
path: ./.github/EXTERNAL_CONTRIBUTOR_PR_COMMENT.md
message: |
Thank you for your contribution to the Noir language.
Please **do not force push to this branch** after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch.
Thanks for your understanding.
37 changes: 25 additions & 12 deletions .github/workflows/test-rust-workspace-msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ name: Test (MSRV check)
# We must then always be able to build the workspace using the latest versions of all of our dependencies, so we explicitly update them and build in this workflow.

on:
pull_request:
merge_group:
schedule:
# Run a nightly check at 2 AM UTC
- cron: "0 2 * * *"
push:
branches:
- master
Expand Down Expand Up @@ -100,13 +101,25 @@ jobs:
- run-tests

steps:
- name: Report overall success
run: |
if [[ $FAIL == true ]]; then
exit 1
else
exit 0
fi
env:
# We treat any cancelled, skipped or failing jobs as a failure for the workflow as a whole.
FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}
- name: Report overall success
run: |
if [[ $FAIL == true ]]; then
exit 1
else
exit 0
fi
env:
# We treat any cancelled, skipped or failing jobs as a failure for the workflow as a whole.
FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}

# Raise an issue if the tests failed
- name: Alert on failed publish
uses: JasonEtco/create-an-issue@v2
if: ${{ failure() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WORKFLOW_NAME: ${{ github.workflow }}
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
update_existing: true
filename: .github/JS_PUBLISH_FAILED.md
20 changes: 10 additions & 10 deletions .github/workflows/test-rust-workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ jobs:
- run-tests

steps:
- name: Report overall success
run: |
if [[ $FAIL == true ]]; then
exit 1
else
exit 0
fi
env:
# We treat any cancelled, skipped or failing jobs as a failure for the workflow as a whole.
FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}
- name: Report overall success
run: |
if [[ $FAIL == true ]]; then
exit 1
else
exit 0
fi
env:
# We treat any cancelled, skipped or failing jobs as a failure for the workflow as a whole.
FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}
3 changes: 3 additions & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM rust:bookworm
FROM rust:bullseye
WORKDIR /usr/src/noir
COPY . .
RUN ./scripts/bootstrap_native.sh

# When running the container, mount the users home directory to same location.
FROM ubuntu:lunar
FROM ubuntu:focal
# Install Tini as nargo doesn't handle signals properly.
# Install git as nargo needs it to clone.
RUN apt-get update && apt-get install -y git tini && rm -rf /var/lib/apt/lists/* && apt-get clean
COPY --from=0 /usr/src/noir/target/release/nargo /usr/src/noir/target/release/nargo
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/src/noir/target/release/nargo"]
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/src/noir/target/release/nargo"]
46 changes: 45 additions & 1 deletion acvm-repo/acvm/src/pwg/blackbox/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use acir::{
native_types::{Witness, WitnessMap},
BlackBoxFunc, FieldElement,
};
use acvm_blackbox_solver::{sha256compression, BlackBoxResolutionError};
use acvm_blackbox_solver::{sha256compression, BlackBoxFunctionSolver, BlackBoxResolutionError};

use crate::pwg::{insert_value, witness_to_value};
use crate::OpcodeResolutionError;
Expand Down Expand Up @@ -131,3 +131,47 @@ pub(crate) fn solve_sha_256_permutation_opcode(

Ok(())
}

pub(crate) fn solve_poseidon2_permutation_opcode(
backend: &impl BlackBoxFunctionSolver,
initial_witness: &mut WitnessMap,
inputs: &[FunctionInput],
outputs: &[Witness],
len: u32,
) -> Result<(), OpcodeResolutionError> {
if len as usize != inputs.len() {
return Err(OpcodeResolutionError::BlackBoxFunctionFailed(
acir::BlackBoxFunc::Poseidon2Permutation,
format!(
"the number of inputs does not match specified length. {} != {}",
inputs.len(),
len
),
));
}
if len as usize != outputs.len() {
return Err(OpcodeResolutionError::BlackBoxFunctionFailed(
acir::BlackBoxFunc::Poseidon2Permutation,
format!(
"the number of outputs does not match specified length. {} != {}",
outputs.len(),
len
),
));
}

// Read witness assignments
let mut state = Vec::new();
for input in inputs.iter() {
let witness_assignment = witness_to_value(initial_witness, input.witness)?;
state.push(*witness_assignment);
}

let state = backend.poseidon2_permutation(&state, len)?;

// Write witness assignments
for (output_witness, value) in outputs.iter().zip(state.into_iter()) {
insert_value(output_witness, value, initial_witness)?;
}
Ok(())
}
8 changes: 6 additions & 2 deletions acvm-repo/acvm/src/pwg/blackbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use acir::{
};
use acvm_blackbox_solver::{blake2s, blake3, keccak256, keccakf1600, sha256};

use self::{bigint::BigIntSolver, pedersen::pedersen_hash};
use self::{
bigint::BigIntSolver, hash::solve_poseidon2_permutation_opcode, pedersen::pedersen_hash,
};

use super::{insert_value, OpcodeNotSolvable, OpcodeResolutionError};
use crate::{pwg::witness_to_value, BlackBoxFunctionSolver};
Expand Down Expand Up @@ -204,7 +206,6 @@ pub(crate) fn solve(
BlackBoxFuncCall::BigIntToLeBytes { input, outputs } => {
bigint_solver.bigint_to_bytes(*input, outputs, initial_witness)
}
BlackBoxFuncCall::Poseidon2Permutation { .. } => todo!(),
BlackBoxFuncCall::Sha256Compression { inputs, hash_values, outputs } => {
solve_sha_256_permutation_opcode(
initial_witness,
Expand All @@ -214,5 +215,8 @@ pub(crate) fn solve(
bb_func.get_black_box_func(),
)
}
BlackBoxFuncCall::Poseidon2Permutation { inputs, outputs, len } => {
solve_poseidon2_permutation_opcode(backend, initial_witness, inputs, outputs, *len)
}
}
}
12 changes: 12 additions & 0 deletions acvm-repo/blackbox_solver/src/curve_specific_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub trait BlackBoxFunctionSolver {
input2_x: &FieldElement,
input2_y: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError>;
fn poseidon2_permutation(
&self,
_inputs: &[FieldElement],
_len: u32,
) -> Result<Vec<FieldElement>, BlackBoxResolutionError>;
}

pub struct StubbedBlackBoxSolver;
Expand Down Expand Up @@ -89,4 +94,11 @@ impl BlackBoxFunctionSolver for StubbedBlackBoxSolver {
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Err(Self::fail(BlackBoxFunc::EmbeddedCurveAdd))
}
fn poseidon2_permutation(
&self,
_inputs: &[FieldElement],
_len: u32,
) -> Result<Vec<FieldElement>, BlackBoxResolutionError> {
Err(Self::fail(BlackBoxFunc::Poseidon2Permutation))
}
}
1 change: 1 addition & 0 deletions acvm-repo/bn254_blackbox_solver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repository.workspace = true
acir.workspace = true
acvm_blackbox_solver.workspace = true
thiserror.workspace = true
num-traits.workspace = true

rust-embed = { version = "6.6.0", features = [
"debug-embed",
Expand Down
11 changes: 11 additions & 0 deletions acvm-repo/bn254_blackbox_solver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use acir::{BlackBoxFunc, FieldElement};
use acvm_blackbox_solver::{BlackBoxFunctionSolver, BlackBoxResolutionError};

mod fixed_base_scalar_mul;
mod poseidon2;
mod wasm;

pub use fixed_base_scalar_mul::{embedded_curve_add, fixed_base_scalar_mul};
use poseidon2::Poseidon2;
use wasm::Barretenberg;

use self::wasm::{Pedersen, SchnorrSig};
Expand Down Expand Up @@ -97,4 +99,13 @@ impl BlackBoxFunctionSolver for Bn254BlackBoxSolver {
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
embedded_curve_add(*input1_x, *input1_y, *input2_x, *input2_y)
}

fn poseidon2_permutation(
&self,
inputs: &[FieldElement],
len: u32,
) -> Result<Vec<FieldElement>, BlackBoxResolutionError> {
let poseidon = Poseidon2::new();
poseidon.permutation(inputs, len)
}
}
Loading

0 comments on commit f26342e

Please sign in to comment.