Skip to content

Commit

Permalink
Dockerfile, standardise test names
Browse files Browse the repository at this point in the history
Signed-off-by: muraca <[email protected]>
  • Loading branch information
muraca committed Dec 29, 2023
1 parent cd2f527 commit 739eda3
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM rust:1.75

WORKDIR /usr/src/halo2-playground
COPY . .
RUN cargo test --release --no-run

ENTRYPOINT ["cargo", "test", "--release"]
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@ We wrote this crate to get a first-hand feeling of the user friendlyness
of the [Halo2](https://github.com/zcash/halo2) proving system.

## Running the tests
To run the tests, run the command `cargo test --release`.
To run the tests, run the command `cargo test --release`.
The command `cargo test` works too, but in that case you may want
to give your computer a couple of minutes to compute the test results.
The flag `-- --nocapture` can be used to print the execution times for proof generation and verification.
to give your computer a couple of minutes to compute the test results.
The flag `-- --nocapture` can be used to print the execution times for proof generation and verification.

The single circuits can be tested by matching the test name with `sudoku`, `permutation` or `factorial`.
The tests that match the `mock` pattern are written using the `MockProver` struct, while the others use the custom real-world provers.

### Running via docker
To run the tests via docker, the simplest way is to build the docker image:
```bash
docker build -t halo2-playground .
```
and then run the tests:
```bash
docker run --rm halo2-playground
```

It will run `cargo test --release` inside the docker container, so you can append any other flag, including a match for the tests you want to run.
For example, to run only the tests in the `sudoku` module, you can run:
```bash
docker run --rm halo2-playground sudoku
```
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod sudoku_circuit;
pub use sudoku_circuit::SudokuCircuit;

mod truncated_factorial_circuit;
pub use truncated_factorial_circuit::TruncatedFactorialCircuit;

/// This chip implements a gate that enforces two
/// sets of values to be a permutation of each other.
Expand Down
4 changes: 2 additions & 2 deletions src/permutation_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mod tests {
use crate::utilities::{inverse_permutation, PermutationsIter};

#[test]
fn permutation_circuit_comprehensive_7_length_test() {
fn mock_permutation() {
use halo2_proofs::{dev::MockProver, pasta::Fp};

let objects: [Value<Fp>; 7] = core::array::from_fn(|n| Value::known(Fp::from(n as u64)));
Expand All @@ -190,7 +190,7 @@ mod tests {
}

#[test]
fn permutation_circuit_test_with_actual_prover() {
fn permutation() {
use halo2_proofs::pasta::Fp;

use crate::utilities::{ProverWrapper, VerifierWrapper};
Expand Down
4 changes: 2 additions & 2 deletions src/sudoku_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ mod tests {
}

#[test]
fn sudoku_circuit_test() {
fn mock_sudoku() {
use halo2_proofs::{dev::MockProver, pasta::Fp};

const POW_OF_2_MAX_ROWS: u32 = 10;
Expand Down Expand Up @@ -487,7 +487,7 @@ mod tests {
}

#[test]
fn sudoku_test_with_actual_prover() {
fn sudoku() {
use crate::utilities::{ProverWrapper, VerifierWrapper};

const POW_OF_2_MAX_ROWS: u32 = 9;
Expand Down
30 changes: 23 additions & 7 deletions src/truncated_factorial_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod tests {
}

#[test]
fn factorial_up_to_20() {
fn mock_factorial_1_to_20() {
const POW_OF_2_MAX_ROWS: u32 = 6;

/// Further information compression,
Expand Down Expand Up @@ -211,15 +211,31 @@ mod tests {
// of `N_FACTORS` does not wrap around in the field,
// should fail.
batch_test_with_params_fail!(
{1, three}{2, three}{3, three}{4, three}{5, three}
{6, three}{7, three}{8, three}{9, three}{10, three}
{11, three}{12, three}{13, three}{14, three}{15, three}
{16, three}{17, three}{18, three}{19, three}{20, three}
{1, three}
{2, three}
{3, three}
{4, three}
{5, three}
{6, three}
{7, three}
{8, three}
{9, three}
{10, three}
{11, three}
{12, three}
{13, three}
{14, three}
{15, three}
{16, three}
{17, three}
{18, three}
{19, three}
{20, three}
);
}

#[test]
fn product_1000_consecutive_numbers() {
fn mock_factorial_1000() {
/// This macro exists because [`iter_apply_macro`] requires
/// a macro argument. It mostly behaves like a generic function,
/// with `mul_batch_size` and `n_columns` as generic parameters
Expand Down Expand Up @@ -269,7 +285,7 @@ mod tests {
}

#[test]
fn test_with_actual_prover() {
fn factorial() {
const MAX_NR_ROWS_POW_2_EXPONENT: u32 = 4;
const N_FACTORS: usize = 1000;

Expand Down

0 comments on commit 739eda3

Please sign in to comment.