Skip to content

Commit

Permalink
chore: fix up nits (#1)
Browse files Browse the repository at this point in the history
* chore: Update CI and fix warnings

* chore: noir-lang author

* chore: remove unnecessary fuzz test

* .

* .

* .

* .

* .

* .

* .
  • Loading branch information
TomAFrench authored Jan 14, 2025
1 parent 712a5a8 commit 71cbebf
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 41 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
- name: Install Nargo
uses: noir-lang/[email protected]
with:
toolchain: 0.34.0
toolchain: 0.36.0

- name: Install bb
run: |
npm install -g bbup
bbup -nv 0.34.0
bbup -nv 0.36.0
- name: Build Noir benchmark programs
run: nargo export
Expand All @@ -34,7 +34,7 @@ jobs:

- name: Compare gates reports
id: gates_diff
uses: noir-lang/noir-gates-diff@1931aaaa848a1a009363d6115293f7b7fc72bb87
uses: noir-lang/noir-gates-diff@7e4ddaa91c69380f15ccba514eac17bc7432a8cc
with:
report: gates_report.json
summaryQuantile: 0.9 # only display the 10% most significant circuit size diffs in the summary (defaults to 20%)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:

jobs:
test:
name: Test on Nargo ${{matrix.toolchain}}
name: Test on Nargo Nightly
runs-on: ubuntu-latest
steps:
- name: Checkout sources
Expand Down
20 changes: 18 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ jobs:
with:
toolchain: ${{ matrix.toolchain }}

- name: Run Noir tests
run: nargo test

rust-equivalence-tests:
name: Test for equivalence against Rust impl
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install Nargo
uses: noir-lang/[email protected]
with:
toolchain: ${{ env.MINIMUM_NOIR_VERSION }}

- name: Install Cargo
uses: dtolnay/[email protected]
with:
Expand All @@ -58,8 +73,8 @@ jobs:
key: x86_64-unknown-linux-gnu
cache-on-failure: true

- name: Run Noir tests
run: nargo test
- name: Generate fuzz test programs
run: nargo export

- name: Run Cargo tests
run: cargo test
Expand Down Expand Up @@ -87,6 +102,7 @@ jobs:
if: ${{ always() }}
needs:
- test
- rust-equivalence-tests
- format

steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
export
4 changes: 2 additions & 2 deletions Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "sha256"
type = "lib"
authors = ["jtriley-eth"]
authors = ["noir-lang"]
compiler_version = ">=0.36.0"

[dependencies]
[dependencies]
1 change: 0 additions & 1 deletion export/test_sha256_0.json

This file was deleted.

1 change: 0 additions & 1 deletion export/test_sha256_1.json

This file was deleted.

1 change: 0 additions & 1 deletion export/test_sha256_200.json

This file was deleted.

1 change: 0 additions & 1 deletion export/test_sha256_511.json

This file was deleted.

1 change: 0 additions & 1 deletion export/test_sha256_512.json

This file was deleted.

1 change: 0 additions & 1 deletion src/lib.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod sha256;
mod tests;

pub use sha256::digest;
pub use sha256::sha256_var;
3 changes: 3 additions & 0 deletions src/sha256.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::hash::sha256_compression;
use std::runtime::is_unconstrained;

mod tests;

// Implementation of SHA-256 mapping a byte array of variable length to
// 32 bytes.

Expand Down Expand Up @@ -514,3 +516,4 @@ fn hash_final_block(msg_block: MSG_BLOCK, mut state: STATE) -> HASH {

out_h
}

22 changes: 14 additions & 8 deletions src/tests.nr → src/sha256/tests.nr
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use crate::sha256::{
attach_len_to_msg_block, build_msg_block, byte_into_item, get_item_byte, make_item,
set_item_byte_then_zeros, sha256_var, sha256, set_item_zeros, INT_BLOCK,
use super::{
attach_len_to_msg_block, build_msg_block, byte_into_item, get_item_byte, INT_BLOCK, make_item,
set_item_byte_then_zeros, set_item_zeros, sha256, sha256_var,
};

#[export]
fn test_sha256_0() -> [u8; 32] {
sha256_var([], 0)
}

#[export]
fn test_sha256_1(input: [u8; 1], len: u64) -> [u8; 32] {
sha256_var(input, len)
Expand All @@ -28,6 +23,17 @@ fn test_sha256_512(input: [u8; 512], len: u64) -> [u8; 32] {
sha256_var(input, len)
}

#[test]
fn empty_sha() {
let input = [];
let result = [
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9,
0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52,
0xb8, 0x55,
];
assert_eq(sha256_var(input, input.len() as u64), result);
}

#[test]
fn smoke_test() {
let input = [0xbd];
Expand Down
24 changes: 5 additions & 19 deletions tests/differential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@ use noir_runner::{NoirRunner, ToNoir};
use proptest::{prelude::prop, test_runner::TestRunner};
use sha2::{Digest, Sha256};

#[test]
fn test_vibe_check() {
let runner = NoirRunner::try_new(PathBuf::new()).unwrap();

let result = runner
.run("test_sha256_0", BTreeMap::new())
.unwrap()
.unwrap();

let expected: [u8; 32] = Sha256::digest([]).try_into().unwrap();

assert_eq!(result, expected.to_noir());
}

#[test]
fn test_prop_sha256_1() {
let runner = NoirRunner::try_new(PathBuf::new()).unwrap();
Expand All @@ -30,13 +16,13 @@ fn test_prop_sha256_1() {
test_runner
.run(&strategy, |vector| {
let input = BTreeMap::from([
("input".to_string(), vector.clone().to_noir()),
("input".to_string(), vector.to_noir()),
("len".to_string(), vector.len().to_noir()),
]);

let result = runner.run("test_sha256_1", input).unwrap().unwrap();

let expected: [u8; 32] = Sha256::digest(&vector).try_into().unwrap();
let expected: [u8; 32] = Sha256::digest(vector).into();

assert_eq!(result, expected.to_noir());

Expand All @@ -62,7 +48,7 @@ fn test_prop_sha256_200() {

let result = runner.run("test_sha256_200", input).unwrap().unwrap();

let expected: [u8; 32] = Sha256::digest(&vector).try_into().unwrap();
let expected: [u8; 32] = Sha256::digest(vector).into();

assert_eq!(result, expected.to_noir());

Expand All @@ -88,7 +74,7 @@ fn test_prop_sha256_511() {

let result = runner.run("test_sha256_511", input).unwrap().unwrap();

let expected: [u8; 32] = Sha256::digest(&vector).try_into().unwrap();
let expected: [u8; 32] = Sha256::digest(vector).into();

assert_eq!(result, expected.to_noir());

Expand All @@ -114,7 +100,7 @@ fn test_prop_sha256_512() {

let result = runner.run("test_sha256_512", input).unwrap().unwrap();

let expected: [u8; 32] = Sha256::digest(&vector).try_into().unwrap();
let expected: [u8; 32] = Sha256::digest(vector).into();

assert_eq!(result, expected.to_noir());

Expand Down

0 comments on commit 71cbebf

Please sign in to comment.