|
| 1 | +# Golden Test Assets |
| 2 | + |
| 3 | +## Purpose |
| 4 | + |
| 5 | +`halo2_ivc` golden tests rely on a small committed asset set so normal test runs |
| 6 | +can validate recursive behavior without regenerating the full proving flow. |
| 7 | + |
| 8 | +The expensive proofs are generated manually through ignored tests in |
| 9 | +`mithril-stm/src/circuits/halo2_ivc/tests/golden/generators/tests.rs`. |
| 10 | +The positive golden tests load those stored outputs at compile time via |
| 11 | +`include_bytes!`, while regeneration keeps using the file-based readers/writers. |
| 12 | + |
| 13 | +## Asset Set |
| 14 | + |
| 15 | +The committed asset files live under: |
| 16 | + |
| 17 | +`mithril-stm/src/circuits/halo2_ivc/tests/golden/assets` |
| 18 | + |
| 19 | +Reader helpers live in: |
| 20 | + |
| 21 | +`mithril-stm/src/circuits/halo2_ivc/tests/golden/asset_readers.rs` |
| 22 | + |
| 23 | +The positive golden tests assume these committed asset files are present in the |
| 24 | +worktree at compile time. If they were removed locally, restore them from git |
| 25 | +before rebuilding or regenerating: |
| 26 | + |
| 27 | +```bash |
| 28 | +git restore mithril-stm/src/circuits/halo2_ivc/tests/golden/assets |
| 29 | +``` |
| 30 | + |
| 31 | +The current asset set is: |
| 32 | + |
| 33 | +- `verification_context.bin` |
| 34 | + - static verifier-side context |
| 35 | + - contains the global public inputs, recursive verifying key, combined fixed |
| 36 | + bases, and shared verifier-side SRS data |
| 37 | + |
| 38 | +- `recursive_chain_state.bin` |
| 39 | + - stored recursive chain checkpoint |
| 40 | + - contains the global public inputs, current recursive state, previous |
| 41 | + recursive proof, and current accumulator |
| 42 | + |
| 43 | +- `recursive_step_output.bin` |
| 44 | + - output of extending the stored chain checkpoint by one more recursive step |
| 45 | + - contains the final recursive proof, next accumulator, next state, and the |
| 46 | + exact certificate proof artifact folded into that stored step |
| 47 | + |
| 48 | +## Dependency Order |
| 49 | + |
| 50 | +The assets have a simple dependency chain: |
| 51 | + |
| 52 | +1. `verification_context.bin` |
| 53 | +2. `recursive_chain_state.bin` |
| 54 | +3. `recursive_step_output.bin` |
| 55 | + |
| 56 | +The chained-flow golden test replays the stored recursive step exactly, and the |
| 57 | +stored `next_accumulator` depends on the exact certificate proof bytes embedded |
| 58 | +inside `recursive_step_output.bin`. |
| 59 | + |
| 60 | +## Generation Model |
| 61 | + |
| 62 | +Asset generation uses: |
| 63 | + |
| 64 | +- deterministic shared setup |
| 65 | +- deterministic universal KZG parameters built with `ParamsKZG::unsafe_setup(...)` |
| 66 | +- OS randomness for signatures and proof generation, aligned with the current |
| 67 | + generator flow |
| 68 | + |
| 69 | +The public-state evolution is reproducible at the semantic level. Proof-bearing |
| 70 | +assets are not expected to be byte-identical across regenerations. |
| 71 | + |
| 72 | +In practice: |
| 73 | + |
| 74 | +- `verification_context.bin` should stay stable unless verifier-side setup changes |
| 75 | +- `recursive_chain_state.bin` may change bytewise because it contains a proof |
| 76 | +- `recursive_step_output.bin` may change bytewise because it contains both the |
| 77 | + final recursive proof and the exact certificate proof used for that step |
| 78 | + |
| 79 | +## How To Regenerate Everything |
| 80 | + |
| 81 | +Run these commands from the repository root: |
| 82 | + |
| 83 | +```bash |
| 84 | +cargo test -p mithril-stm --features future_snark --release generate_verification_context_only -- --ignored --nocapture |
| 85 | +cargo test -p mithril-stm --features future_snark --release generate_recursive_chain_state_only -- --ignored --nocapture |
| 86 | +cargo test -p mithril-stm --features future_snark --release generate_recursive_step_output_only -- --ignored --nocapture |
| 87 | +``` |
| 88 | + |
| 89 | +These commands intentionally use `--release` because asset generation is a |
| 90 | +manual workflow dominated by real proof generation. |
| 91 | + |
| 92 | +These commands correspond to the ignored generator entrypoints in |
| 93 | +`mithril-stm/src/circuits/halo2_ivc/tests/golden/generators/tests.rs`: |
| 94 | + |
| 95 | +- `generate_verification_context_only` |
| 96 | +- `generate_recursive_chain_state_only` |
| 97 | +- `generate_recursive_step_output_only` |
| 98 | + |
| 99 | +Recommended order: |
| 100 | + |
| 101 | +1. regenerate `verification_context.bin` |
| 102 | +2. regenerate `recursive_chain_state.bin` |
| 103 | +3. regenerate `recursive_step_output.bin` |
| 104 | + |
| 105 | +## Partial Regeneration |
| 106 | + |
| 107 | +If only the representative recursive step output changed, it is sufficient to rerun: |
| 108 | + |
| 109 | +```bash |
| 110 | +cargo test -p mithril-stm --features future_snark --release generate_recursive_step_output_only -- --ignored --nocapture |
| 111 | +``` |
| 112 | + |
| 113 | +That command regenerates: |
| 114 | + |
| 115 | +- `recursive_step_output.bin` |
| 116 | + |
| 117 | +It does not require regenerating `verification_context.bin` or |
| 118 | +`recursive_chain_state.bin` unless their inputs changed. |
| 119 | + |
| 120 | +## When Regeneration Is Needed |
| 121 | + |
| 122 | +Regenerate the assets when one of these changes: |
| 123 | + |
| 124 | +- recursive circuit logic |
| 125 | +- recursive public input or state layout |
| 126 | +- accumulator encoding |
| 127 | +- recursive or certificate verifying key inputs |
| 128 | +- verifier-side SRS data format |
| 129 | +- generation setup or proving randomness model |
| 130 | +- chained-flow replay contract for the recursive step assets |
| 131 | + |
| 132 | +## Temporary Certificate Dependency |
| 133 | + |
| 134 | +The current asset generation depends on the temporary local certificate relation |
| 135 | +in |
| 136 | +`mithril-stm/src/circuits/halo2_ivc/tests/test_certificate.rs`. |
| 137 | + |
| 138 | +This is a temporary compatibility step. It keeps recursive asset generation |
| 139 | +close to the original prototype flow while the STM non-recursive Halo2 |
| 140 | +certificate circuit continues to evolve. |
| 141 | + |
| 142 | +The intended follow-up is to remove this temporary local relation and generate |
| 143 | +the assets directly from the current STM Halo2 certificate circuit. |
0 commit comments