|
1 | 1 | # Test suite for zk-regex + Noir |
2 | 2 |
|
| 3 | +This test-suite is a tool for testing and benchmarking the zk-regex library module that generates Noir code to check if certain regex is matched. |
| 4 | + |
3 | 5 | ## Requirements |
4 | 6 |
|
5 | 7 | - Install zk-regex command following the instructions in the documentation. |
6 | 8 | - Install Noir. |
| 9 | +- Install the `hyperfine` tool. |
7 | 10 |
|
8 | 11 | ## How to run |
9 | 12 |
|
10 | | -### Database |
| 13 | +To execute the testing and/or the benchmarking, you need to fill a JSON database that will be used for the testing and/or benchmarking. The testing and the benchmarking are two separate processes. This means that you may execute the testing without the benchmarking, or the benchmarking without the testing, or execute both the testing and the benchmarking. However, both processes will use the same database for their ends. It is important to add that if you want to execute just the testing or just the benchmarking, some of the fields are not mandatory as we will explain next. The basic structure for the database is as follows: |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "database": [ |
| 18 | + <sample>, |
| 19 | + <sample>, |
| 20 | + <sample>, |
| 21 | + ] |
| 22 | +} |
| 23 | + |
| 24 | +``` |
| 25 | + |
| 26 | +where `<sample>` is a JSON object with certain required fields. The instructions to fill the database are presented below. |
| 27 | + |
| 28 | +## Instructions for testing |
| 29 | + |
| 30 | +Each sample for testing can be one of two types: raw, or decomposed. "Raw" means that the regex is specified as just one string, while "decomposed" means that the regex is specified in fragments according to the zk-regex specification. Below you will find an example of how to specify a database with both types of specification. It is important to notice that the database can have samples with a mixture of both types: some samples may be "raw", and other samples may be "decomposed". |
11 | 31 |
|
12 | 32 | ```json |
13 | 33 | { |
|
51 | 71 | ] |
52 | 72 | } |
53 | 73 | ``` |
54 | | -### Execute tests |
55 | 74 |
|
| 75 | +To execute the tests, you simply run. |
| 76 | + |
| 77 | +```bash |
| 78 | +RUST_LOG=info cargo run -- -t |
| 79 | +``` |
| 80 | + |
| 81 | +## Instructions for benchmarking |
| 82 | + |
| 83 | +This tool allows you to benchmark the source code to evaluate the performance. The benchmarking requires to add additional flags and information to the database presented in the previous section. It is important to make clear that if you just want to execute the test, the modifications to the database associated with the benchmark **are not mandatory**. |
| 84 | + |
| 85 | +The benchmarking tool supports the following features: |
| 86 | + |
| 87 | +- If you want to benchmark all the samples, you can add the `"bench_all": true` to the database as follows: |
| 88 | + |
| 89 | + ```json |
| 90 | + { |
| 91 | + "bench_all": true, |
| 92 | + "database": [ |
| 93 | + <sample>, |
| 94 | + <sample>, |
| 95 | + <sample>, |
| 96 | + ] |
| 97 | + } |
| 98 | + ``` |
| 99 | + |
| 100 | + This flag is optional. |
| 101 | +- You may want to execute benchmarks not for all the samples but for some of them. If you want to execute the benchmark for some of the samples but not for all, you can add the flag `"with_bench": true` to benchmark that sample. This flag is considered optional, and if you do not add it, the default value will be considered as `false`. |
| 102 | +- There are two types of benchmarking: |
| 103 | + - *without time*: this mode of benchmarking means that the report will include just the gate-count of the circuit generated by the zk-regex library, but this mode does not measure the proving time. To execute the benchmarking in this mode you must execute the following command: |
| 104 | + |
| 105 | + ```bash |
| 106 | + RUST_LOG=info cargo run -- [OPTIONS] no-time |
| 107 | + ``` |
| 108 | + |
| 109 | + - *with time*: this mode of benchmarking measures the gate-count as in the previous mode, and also measures the proving time of 5 executions of the Noir project. To execute this you need to add the field `"benchmark_str"` with a string that must successfully match the regex. This string will be used as the witness for the prove. If you **do not** want to benchmark the proving time, you can omit this field in the database. To run the benchmarking *with time*, you must execute the following command: |
| 110 | + |
| 111 | + ```bash |
| 112 | + RUST_LOG=info cargo run -- [OPTIONS] with-time |
| 113 | + ``` |
| 114 | + |
| 115 | +If you want to execute the benchmarking **without** the testing, you can omit the `-t` flag in the execution command as shown below: |
| 116 | + |
| 117 | +```bash |
| 118 | +RUST_LOG=info cargo run -- <no-time | with-time> |
56 | 119 | ``` |
57 | | -$ RUST_LOG=info cargo run |
| 120 | + |
| 121 | +## Execution of testing and benchmarking simultaneously |
| 122 | + |
| 123 | +If you want to execute both the testing and the benchmarking you need to follow the instructions presented above for the benchmarking and the testing independently. Then you can execute the following command: |
| 124 | + |
| 125 | +```bash |
| 126 | +RUST_LOG=info cargo run -- -t <no-time | with-time> |
58 | 127 | ``` |
59 | 128 |
|
60 | 129 | ## Limitations |
61 | 130 |
|
62 | | -For some regexes the random sampling is not possible, because the sampling library is limited. For example the end anchor (`$`) is not supported. |
| 131 | +For some regexes the random sampling is not possible, because the sampling library is limited. For example the end anchor (`$`) is not supported. |
63 | 132 |
|
64 | | -Random sample testing for the `gen_substrs` setting is only support for `decomposed`. In the `raw` setting, the substrings are determined via a json file that contains the transition information. Determining what the substring parts are, would be quite involved since it requires building the DFA. |
| 133 | +Random sample testing for the `gen_substrs` setting is only support for `decomposed`. In the `raw` setting, the substrings are determined via a json file that contains the transition information. Determining what the substring parts are, would be quite involved since it requires building the DFA. |
0 commit comments