Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions circuits/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,67 @@ From this directory:
```

Options and secure-only **config** circuit behavior are documented in the script and `config.json`.

## Refresh after parameter changes

If you change circuit/config parameter sets, rerun the full benchmark + gas extraction flow.

From repository root:

```bash
# Build CRISP SDK artifacts used by verifier tests
pnpm -C examples/CRISP/packages/crisp-sdk build

# Recompute benchmark raw JSON and base report (insecure mode)
./circuits/benchmarks/run_benchmarks.sh --mode insecure

# Extract on-chain verify gas from simulated verifier tests
./circuits/benchmarks/scripts/extract_crisp_verify_gas.sh \
--output "./circuits/benchmarks/results_insecure/crisp_verify_gas.json"

# Regenerate report with gas values
./circuits/benchmarks/scripts/generate_report.sh \
--input-dir "./circuits/benchmarks/results_insecure/raw" \
--output "./circuits/benchmarks/results_insecure/report.md" \
--gas-json "./circuits/benchmarks/results_insecure/crisp_verify_gas.json"
```

For secure mode, use `--mode secure` and replace `results_insecure` with `results_secure`.

## Reported protocol tables

`results_*/report.md` now includes protocol-oriented sections in addition to raw category tables:

- `Circuit Benchmarks` with rows in fixed order: `C0`, `C1`, `C2a`, `C2b`, `C3a`, `C3b`, `C4a`,
`C4b`, `C5`, `user-data-encryption`, `C6`, `C7`.
- `Artifacts` for `Π_DKG`, `Π_user`, `Π_dec` with proof/public-input sizes and gas columns.
- `Role / Phase / Activity` for P1..P4 operational cost summaries.

## Derivation rules

- `Constraints`: `gates.total_gates`
- `Prove time (s)`: `proof_generation.time_seconds`
- `Verify time (ms)`: `verification.time_seconds * 1000`
- `Proof size (KB)`: `proof_generation.proof_size_bytes / 1024`
- `Public input size`: `verification.public_inputs_size_bytes / 1024`

Split rows are deterministic:

- `C3a` and `C3b` both map to `dkg/share_encryption` benchmark output.
- `C4a` and `C4b` both map to `dkg/share_decryption` benchmark output.

## Gas measurement source

`Verify gas` is sourced from the existing CRISP verification test path:

- Test: `examples/CRISP/packages/crisp-contracts/tests/crisp.contracts.test.ts`
- Command path: `circuits/benchmarks/scripts/extract_crisp_verify_gas.sh`
- Benchmark integration: `run_benchmarks.sh` runs that script and passes the JSON to report
generation.

For `Π_DKG` and `Π_dec`, verifier gas is sourced from folded recursive-aggregation proofs exported
by `cargo test -p e3-tests test_trbfv_actor` (via `BENCHMARK_FOLDED_OUTPUT`) and then replayed into
EVM verifier `estimateGas` in `packages/enclave-contracts/scripts/benchmarkGasFromRaw.ts`.

`Calldata gas` is computed from benchmark proof/public-input bytes with EVM calldata costs
(`0x00 -> 4`, non-zero byte -> 16) and stored in raw benchmark JSON.
13 changes: 13 additions & 0 deletions circuits/benchmarks/results_insecure/crisp_verify_gas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"verify_gas": {
"dkg": 3037849,
"user": 2972953,
"dec": 3549211
},
"source": "crisp_verify_test",
"test_exit_code": {
"crisp": 0,
"folded_export": 0,
"enclave_contracts": 0
}
}
283 changes: 38 additions & 245 deletions circuits/benchmarks/results_insecure/report.md
Original file line number Diff line number Diff line change
@@ -1,255 +1,48 @@
# Enclave ZK Circuit Benchmarks

**Generated:** 2026-04-07 13:56:44 UTC
**Generated:** 2026-04-27 10:35:23 UTC

**Git Branch:** `main`
**Git Commit:** `bae26bfb4e0d6673bff4783c4942384dfbef5a08`
**Git Commit:** `e651f30205117e83a9cc48ac44664d434466724d`

---

## Summary

### DKG

#### Timing Metrics

| Circuit | Compile | Execute | Prove | Verify |
| ---------------------- | ------- | ------- | ------ | ------ |
| e_sm_share_computation | 0.34 s | 0.49 s | 0.89 s | 0.02 s |
| pk | 0.30 s | 0.31 s | 0.12 s | 0.02 s |
| share_decryption | 0.32 s | 0.39 s | 0.51 s | 0.02 s |
| share_encryption | 0.33 s | 0.48 s | 0.60 s | 0.03 s |
| sk_share_computation | 0.33 s | 0.45 s | 0.81 s | 0.02 s |

#### Size & Circuit Metrics

| Circuit | Opcodes | Gates | Circuit Size | Witness | VK Size | Proof Size |
| ---------------------- | ------- | ------- | ------------ | --------- | ------- | ---------- |
| e_sm_share_computation | 75649 | 198.35K | 1.16 MB | 222.06 KB | 3.59 KB | 15.88 KB |
| pk | 344 | 6.85K | 90.54 KB | 29.07 KB | 3.59 KB | 15.88 KB |
| share_decryption | 28577 | 92.52K | 538.83 KB | 151.95 KB | 3.59 KB | 15.88 KB |
| share_encryption | 47758 | 127.05K | 802.98 KB | 512.11 KB | 3.59 KB | 15.88 KB |
| sk_share_computation | 56018 | 142.62K | 936.72 KB | 165.20 KB | 3.59 KB | 15.88 KB |

### Threshold

#### Timing Metrics

| Circuit | Compile | Execute | Prove | Verify |
| ---------------------------- | ------- | ------- | ------ | ------ |
| decrypted_shares_aggregation | 0.33 s | 0.58 s | 0.51 s | 0.02 s |
| pk_aggregation | 0.34 s | 0.45 s | 0.83 s | 0.02 s |
| pk_generation | 0.32 s | 0.40 s | 0.35 s | 0.02 s |
| share_decryption | 0.32 s | 0.43 s | 0.52 s | 0.03 s |
| user_data_encryption_ct0 | 0.32 s | 0.41 s | 0.33 s | 0.03 s |
| user_data_encryption_ct1 | 0.32 s | 0.39 s | 0.32 s | 0.03 s |

#### Size & Circuit Metrics

| Circuit | Opcodes | Gates | Circuit Size | Witness | VK Size | Proof Size |
| ---------------------------- | ------- | ------- | ------------ | --------- | ------- | ---------- |
| decrypted_shares_aggregation | 41673 | 104.27K | 1.12 MB | 111.14 KB | 3.59 KB | 15.88 KB |
| pk_aggregation | 48950 | 151.72K | 837.49 KB | 259.79 KB | 3.59 KB | 15.88 KB |
| pk_generation | 27737 | 57.82K | 501.25 KB | 348.73 KB | 3.59 KB | 15.88 KB |
| share_decryption | 22486 | 75.12K | 466.54 KB | 498.22 KB | 3.59 KB | 15.88 KB |
| user_data_encryption_ct0 | 27573 | 53.73K | 500.84 KB | 358.40 KB | 3.59 KB | 15.88 KB |
| user_data_encryption_ct1 | 21399 | 46.27K | 421.51 KB | 325.19 KB | 3.59 KB | 15.88 KB |

### Config

#### Timing Metrics

| Circuit | Compile | Execute | Prove | Verify |
| ------- | ------- | ------- | ----- | ------ |

#### Size & Circuit Metrics

| Circuit | Opcodes | Gates | Circuit Size | Witness | VK Size | Proof Size |
| ------- | ------- | ----- | ------------ | ------- | ------- | ---------- |

## Circuit Details

### DKG

#### e_sm_share_computation

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.34 s |
| **Execution** | 0.49 s |
| **VK Generation** | 0.38 s |
| **Proof Generation** | 0.89 s |
| **Verification** | 0.02 s |
| **ACIR Opcodes** | "75649" |
| **Total Gates** | "198355" |
| **Circuit Size** | 1.16 MB |
| **Witness Size** | 222.06 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

#### pk

| Metric | Value |
| -------------------- | -------- |
| **Compilation** | 0.30 s |
| **Execution** | 0.31 s |
| **VK Generation** | 0.05 s |
| **Proof Generation** | 0.12 s |
| **Verification** | 0.02 s |
| **ACIR Opcodes** | "344" |
| **Total Gates** | "6847" |
| **Circuit Size** | 90.54 KB |
| **Witness Size** | 29.07 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

#### share_decryption

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.32 s |
| **Execution** | 0.39 s |
| **VK Generation** | 0.20 s |
| **Proof Generation** | 0.51 s |
| **Verification** | 0.02 s |
| **ACIR Opcodes** | "28577" |
| **Total Gates** | "92515" |
| **Circuit Size** | 538.83 KB |
| **Witness Size** | 151.95 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

#### share_encryption

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.33 s |
| **Execution** | 0.48 s |
| **VK Generation** | 0.25 s |
| **Proof Generation** | 0.60 s |
| **Verification** | 0.03 s |
| **ACIR Opcodes** | "47758" |
| **Total Gates** | "127047" |
| **Circuit Size** | 802.98 KB |
| **Witness Size** | 512.11 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

#### sk_share_computation

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.33 s |
| **Execution** | 0.45 s |
| **VK Generation** | 0.28 s |
| **Proof Generation** | 0.81 s |
| **Verification** | 0.02 s |
| **ACIR Opcodes** | "56018" |
| **Total Gates** | "142625" |
| **Circuit Size** | 936.72 KB |
| **Witness Size** | 165.20 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

### Threshold

#### decrypted_shares_aggregation

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.33 s |
| **Execution** | 0.58 s |
| **VK Generation** | 0.23 s |
| **Proof Generation** | 0.51 s |
| **Verification** | 0.02 s |
| **ACIR Opcodes** | "41673" |
| **Total Gates** | "104273" |
| **Circuit Size** | 1.12 MB |
| **Witness Size** | 111.14 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

#### pk_aggregation

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.34 s |
| **Execution** | 0.45 s |
| **VK Generation** | 0.30 s |
| **Proof Generation** | 0.83 s |
| **Verification** | 0.02 s |
| **ACIR Opcodes** | "48950" |
| **Total Gates** | "151717" |
| **Circuit Size** | 837.49 KB |
| **Witness Size** | 259.79 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

#### pk_generation

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.32 s |
| **Execution** | 0.40 s |
| **VK Generation** | 0.14 s |
| **Proof Generation** | 0.35 s |
| **Verification** | 0.02 s |
| **ACIR Opcodes** | "27737" |
| **Total Gates** | "57818" |
| **Circuit Size** | 501.25 KB |
| **Witness Size** | 348.73 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

#### share_decryption

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.32 s |
| **Execution** | 0.43 s |
| **VK Generation** | 0.17 s |
| **Proof Generation** | 0.52 s |
| **Verification** | 0.03 s |
| **ACIR Opcodes** | "22486" |
| **Total Gates** | "75125" |
| **Circuit Size** | 466.54 KB |
| **Witness Size** | 498.22 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

#### user_data_encryption_ct0

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.32 s |
| **Execution** | 0.41 s |
| **VK Generation** | 0.13 s |
| **Proof Generation** | 0.33 s |
| **Verification** | 0.03 s |
| **ACIR Opcodes** | "27573" |
| **Total Gates** | "53732" |
| **Circuit Size** | 500.84 KB |
| **Witness Size** | 358.40 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

#### user_data_encryption_ct1

| Metric | Value |
| -------------------- | --------- |
| **Compilation** | 0.32 s |
| **Execution** | 0.39 s |
| **VK Generation** | 0.12 s |
| **Proof Generation** | 0.32 s |
| **Verification** | 0.03 s |
| **ACIR Opcodes** | "21399" |
| **Total Gates** | "46270" |
| **Circuit Size** | 421.51 KB |
| **Witness Size** | 325.19 KB |
| **VK Size** | 3.59 KB |
| **Proof Size** | 15.88 KB |

### Config
## Protocol Summary

### Circuit Benchmarks

| Circuit | Constraints | Prove time (s) | Verify time (ms) | Proof size (KB) |
| -------------------- | ----------- | -------------- | ---------------- | --------------- |
| C0 | 6847 | 0.12 | 25.76 | 15.88 |
| C1 | 57818 | 0.33 | 26.00 | 15.88 |
| C2a | 142625 | 0.77 | 26.58 | 15.88 |
| C2b | 198355 | 0.86 | 26.30 | 15.88 |
| C3a | 132633 | 0.79 | 25.93 | 15.88 |
| C3b | 132633 | 0.79 | 25.93 | 15.88 |
| C4a | 92515 | 0.49 | 25.95 | 15.88 |
| C4b | 92515 | 0.49 | 25.95 | 15.88 |
| C5 | 151717 | 0.79 | 25.87 | 15.88 |
| user_data_encryption | 53732 | 0.32 | 25.68 | 15.88 |
| C6 | 86927 | 0.52 | 26.68 | 15.88 |
| C7 | 104273 | 0.49 | 26.20 | 15.88 |

### Artifacts

| Artifact | Proof size | Public input size | Verify gas | Calldata gas | Total gas |
| -------- | ---------- | ----------------- | ---------- | ------------ | --------- |
| Π_DKG | 15.88 KB | 0.12 KB | 3037849 | 179452 | 3217301 |
| Π_user | 31.75 KB | 0.22 KB | 2972953 | 340140 | 3313093 |
| Π_dec | 15.88 KB | 3.25 KB | 3549211 | 188232 | 3737443 |

### Role / Phase / Activity

| Role | Phase | Activity | Prove time | Proof size | Bandwidth |
| --------------- | ----- | -------------------------------- | ---------- | ---------- | --------- |
| Each ciphernode | P1 | one-time DKG participation | 3.37 s | 95.25 KB | 96.12 KB |
| Aggregator | P2 | combine folds + C5 | 0.79 s | 15.88 KB | 16.00 KB |
| User | P3 | per user input | 0.64 s | 31.75 KB | 31.97 KB |
| Each ciphernode | P4 | per computation output (C6) | 0.52 s | 15.88 KB | 16.00 KB |
| Aggregator | P4 | per computation output (C7+fold) | 0.49 s | 15.88 KB | 19.12 KB |

## System Information

Expand Down
13 changes: 13 additions & 0 deletions circuits/benchmarks/results_secure/crisp_verify_gas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"verify_gas": {
"dkg": 3037824,
"user": 2972929,
"dec": 3549028
},
"source": "crisp_verify_test",
"test_exit_code": {
"crisp": 0,
"folded_export": 0,
"enclave_contracts": 0
}
}
Loading
Loading