From 497dde290ecbf271b71fb428fcef19120353a993 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 1 Feb 2024 05:02:15 +0100 Subject: [PATCH] Adjust keccak size (#5) --- README.md | 36 +++++++++++++++++----------------- circuits/keccak/src/main.nr | 6 +++--- circuits/keccak_2x/src/main.nr | 10 +++++----- src/recursive.ts | 3 +-- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 0c6fb5e..971959f 100644 --- a/README.md +++ b/README.md @@ -20,22 +20,22 @@ Or regenerate profiling info: | Package | Tool | Action | Elapsed Time | User Time | System Time | CPU Usage | Max Memory | | --------- | ------- | ------ | ------------ | --------- | ----------- | --------- | ---------- | -| poseidon | nargo | prove | 0:00.67 | 1.16 | 0.17 | 198% | 149.46MB | -| | | verify | 0:00.64 | 0.89 | 0.12 | 159% | 143.59MB | -| | noir_js | prove | 0:01.62 | 3.67 | 0.66 | 266% | 2.18GB | -| | | verify | 0:01.28 | 3.30 | 0.55 | 299% | 2.13GB | -| rlp | nargo | prove | 0:01.28 | 3.74 | 0.25 | 310% | 313.48MB | -| | | verify | 0:01.27 | 3.70 | 0.15 | 303% | 244.93MB | -| | noir_js | prove | 0:02.61 | 9.90 | 0.72 | 406% | 2.24GB | -| | | verify | 0:02.48 | 9.25 | 0.59 | 396% | 2.36GB | -| keccak | nargo | prove | 0:07.41 | 40.26 | 0.96 | 555% | 2.29GB | -| | | verify | 0:06.62 | 39.98 | 0.62 | 613% | 1.79GB | -| | noir_js | prove | 0:21.50 | 107.59 | 2.00 | 509% | 4.07GB | -| | | verify | 0:18.11 | 95.84 | 1.04 | 534% | 3.65GB | -| keccak_2x | nargo | prove | 0:14.52 | 79.77 | 1.83 | 561% | 4.31GB | -| | | verify | 0:12.44 | 76.64 | 1.24 | 626% | 3.57GB | -| | noir_js | prove | 0:42.05 | 213.33 | 3.54 | 515% | 6.06GB | -| | | verify | 0:32.77 | 184.67 | 1.52 | 568% | 5.11GB | +| poseidon | nargo | prove | 0:00.65 | 1.13 | 0.19 | 201% | 148.89MB | +| | | verify | 0:00.59 | 0.85 | 0.14 | 167% | 143.26MB | +| | noir_js | prove | 0:01.40 | 3.61 | 0.67 | 304% | 2.14GB | +| | | verify | 0:01.30 | 3.37 | 0.59 | 303% | 2.04GB | +| rlp | nargo | prove | 0:01.28 | 3.65 | 0.28 | 307% | 308.08MB | +| | | verify | 0:01.17 | 3.56 | 0.16 | 317% | 245.10MB | +| | noir_js | prove | 0:02.51 | 9.74 | 0.76 | 417% | 2.37GB | +| | | verify | 0:02.28 | 9.09 | 0.62 | 426% | 2.20GB | +| keccak | nargo | prove | 0:04.11 | 20.72 | 0.66 | 519% | 1.18GB | +| | | verify | 0:04.36 | 21.54 | 0.50 | 505% | 983.63MB | +| | noir_js | prove | 0:11.49 | 55.73 | 1.33 | 496% | 3.04GB | +| | | verify | 0:09.69 | 51.34 | 0.80 | 537% | 2.74GB | +| keccak_2x | nargo | prove | 0:07.84 | 40.64 | 1.05 | 531% | 2.21GB | +| | | verify | 0:06.79 | 40.07 | 0.75 | 601% | 1.82GB | +| | noir_js | prove | 0:21.25 | 106.92 | 1.92 | 512% | 4.03GB | +| | | verify | 0:17.76 | 95.39 | 1.07 | 543% | 3.71GB | ### Recursive proofs (WASM, local M1 Max) @@ -72,9 +72,9 @@ recursive2x.bb.verifyFinalProof: 14.451s +--------------+----------------------+--------------+----------------------+ | rlp | Bounded { width: 3 } | 4188 | 11704 | +--------------+----------------------+--------------+----------------------+ -| keccak | Bounded { width: 3 } | 4 | 155014 | +| keccak | Bounded { width: 3 } | 4 | 97766 | +--------------+----------------------+--------------+----------------------+ -| keccak_2x | Bounded { width: 3 } | 7 | 300406 | +| keccak_2x | Bounded { width: 3 } | 7 | 154910 | +--------------+----------------------+--------------+----------------------+ | recursive | Bounded { width: 3 } | 1 | 247869 | +--------------+----------------------+--------------+----------------------+ diff --git a/circuits/keccak/src/main.nr b/circuits/keccak/src/main.nr index 23b2bcd..20ccf4f 100644 --- a/circuits/keccak/src/main.nr +++ b/circuits/keccak/src/main.nr @@ -1,7 +1,7 @@ use dep::std; fn main(x: pub u8) { - let array: [u8; 1000] = [x; 1000]; - let hash = std::hash::keccak256(array, 1000); - assert(hash[0] == 174); + let array: [u8; 532] = [x; 532]; + let hash = std::hash::keccak256(array, 532); + assert(hash[0] == 148); } diff --git a/circuits/keccak_2x/src/main.nr b/circuits/keccak_2x/src/main.nr index e9bf81c..2e796d5 100644 --- a/circuits/keccak_2x/src/main.nr +++ b/circuits/keccak_2x/src/main.nr @@ -1,9 +1,9 @@ use dep::std; fn main(x: pub u8) { - let array: [u8; 1000] = [x; 1000]; - let hash = std::hash::keccak256(array, 1000); - let hash2 = std::hash::keccak256(array, 999); - assert(hash[0] == 174); - assert(hash2[0] == 10); + let array: [u8; 532] = [x; 532]; + let hash = std::hash::keccak256(array, 532); + let hash2 = std::hash::keccak256(array, 531); + assert(hash[0] == 148); + assert(hash2[0] == 135); } diff --git a/src/recursive.ts b/src/recursive.ts index 481315a..2ba0cd9 100644 --- a/src/recursive.ts +++ b/src/recursive.ts @@ -1,6 +1,5 @@ import { initCircuit, readInputMap } from "./utils.js"; -import { InputMap } from "@noir-lang/noir_js"; -import { Field } from "@noir-lang/noirc_abi"; +import { Field, type InputMap } from "@noir-lang/noirc_abi"; import assert from "assert"; import { prepareIntermediateProofArtefacts } from "./recursive_utils.js";