From c1e14dcc5840231d2ce64b7c238de04d5fe68ccb Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 21 Dec 2023 09:27:50 +0100 Subject: [PATCH 1/4] remove redundant keccak-only circuit from ecdsa example --- src/examples/crypto/ecdsa/ecdsa.ts | 8 -------- src/examples/crypto/ecdsa/run.ts | 13 ++++--------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/examples/crypto/ecdsa/ecdsa.ts b/src/examples/crypto/ecdsa/ecdsa.ts index 45639c41cb..bebe6484fb 100644 --- a/src/examples/crypto/ecdsa/ecdsa.ts +++ b/src/examples/crypto/ecdsa/ecdsa.ts @@ -27,14 +27,6 @@ const keccakAndEcdsa = ZkProgram({ return signature.verify(message, publicKey); }, }, - - sha3: { - privateInputs: [], - method(message: Bytes32) { - Keccak.nistSha3(256, message); - return Bool(true); - }, - }, }, }); diff --git a/src/examples/crypto/ecdsa/run.ts b/src/examples/crypto/ecdsa/run.ts index 2a497de373..c3acaa19c2 100644 --- a/src/examples/crypto/ecdsa/run.ts +++ b/src/examples/crypto/ecdsa/run.ts @@ -13,19 +13,14 @@ let signature = Ecdsa.sign(message.toBytes(), privateKey.toBigInt()); // investigate the constraint system generated by ECDSA verify console.time('ecdsa verify only (build constraint system)'); -let csEcdsa = ecdsa.analyzeMethods().verifySignedHash; +let csEcdsa = ecdsa.analyzeMethods(); console.timeEnd('ecdsa verify only (build constraint system)'); -console.log(csEcdsa.summary()); - -console.time('keccak only (build constraint system)'); -let csKeccak = keccakAndEcdsa.analyzeMethods().sha3; -console.timeEnd('keccak only (build constraint system)'); -console.log(csKeccak.summary()); +console.log(csEcdsa.verifySignedHash.summary()); console.time('keccak + ecdsa verify (build constraint system)'); -let cs = keccakAndEcdsa.analyzeMethods().verifyEcdsa; +let cs = keccakAndEcdsa.analyzeMethods(); console.timeEnd('keccak + ecdsa verify (build constraint system)'); -console.log(cs.summary()); +console.log(cs.verifyEcdsa.summary()); // compile and prove From 86930e8a9c9a150922e43d869a5cfb7997b26ec8 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 21 Dec 2023 12:14:37 +0100 Subject: [PATCH 2/4] bindings and rename parse hex --- src/bindings | 2 +- src/lib/provable-context.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bindings b/src/bindings index 84483cd12a..5f650144e1 160000 --- a/src/bindings +++ b/src/bindings @@ -1 +1 @@ -Subproject commit 84483cd12abca5a8d2b16c03083976cecced721f +Subproject commit 5f650144e14dd937c0038cf30b0923958282f453 diff --git a/src/lib/provable-context.ts b/src/lib/provable-context.ts index 3b79562889..c285ee81f8 100644 --- a/src/lib/provable-context.ts +++ b/src/lib/provable-context.ts @@ -1,6 +1,6 @@ import { Context } from './global-context.js'; import { Gate, GateType, JsonGate, Snarky } from '../snarky.js'; -import { parseHexString } from '../bindings/crypto/bigint-helpers.js'; +import { parseHexString32 } from '../bindings/crypto/bigint-helpers.js'; import { prettifyStacktrace } from './errors.js'; import { Fp } from '../bindings/crypto/finite_field.js'; @@ -126,7 +126,7 @@ function constraintSystem(f: () => T) { function gatesFromJson(cs: { gates: JsonGate[]; public_input_size: number }) { let gates: Gate[] = cs.gates.map(({ typ, wires, coeffs: hexCoeffs }) => { - let coeffs = hexCoeffs.map((hex) => parseHexString(hex).toString()); + let coeffs = hexCoeffs.map((hex) => parseHexString32(hex).toString()); return { type: typ, wires, coeffs }; }); return { publicInputSize: cs.public_input_size, gates }; From a3d1c81beea2383856488d5a3de8b7e29c8a8572 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 21 Dec 2023 14:09:06 +0100 Subject: [PATCH 3/4] bindings --- src/bindings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings b/src/bindings index 5f650144e1..7fcd4cd6f5 160000 --- a/src/bindings +++ b/src/bindings @@ -1 +1 @@ -Subproject commit 5f650144e14dd937c0038cf30b0923958282f453 +Subproject commit 7fcd4cd6f5b90c7c5c50b15377777528d8b35e41 From 5655928d38341290d73e5860435195fa44b61ad4 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 21 Dec 2023 14:28:18 +0100 Subject: [PATCH 4/4] dump vks --- tests/vk-regression/vk-regression.json | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/vk-regression/vk-regression.json b/tests/vk-regression/vk-regression.json index 9a183bc35e..2f69465d55 100644 --- a/tests/vk-regression/vk-regression.json +++ b/tests/vk-regression/vk-regression.json @@ -249,20 +249,16 @@ } }, "ecdsa": { - "digest": "334c2efc6a82e87319cadb7f3e6f9edb55f8f2eab71e0bcf2451f3d5536de5fe", + "digest": "3e80a93d93a93f6152d70a9c21a2979ff0094c2d648a67c6d2daa4b2b0d18309", "methods": { - "sha3": { - "rows": 14494, - "digest": "949539824d56622702d9ac048e8111e9" - }, "verifyEcdsa": { "rows": 45178, "digest": "0b6ce4cc658bcca79b1b1373569aa9b9" } }, "verificationKey": { - "data": "AAB/ZjMH6HxnifKVGWGw41mrmDWq4R7eG+tJRvszclriFqNFKZXi3LD9Z+2F/VSHlQD8mq3JCoD6tm3rlEQXheATALIHoglupcYB4X43h14qFKloG2kuKwLeDl6mRpeVwSmwE/Tv+P3K8KkyB9zmoT1eEt/ayPRm4EzrJb0EHzyrE0VhKfn6Xh48tBUpGk3JahLhsK+yOTjDBvwcZ/vsiNkGCtFbQv9rM7YZlpBk6NmFYzcnsfJOHyYyr6Xab+6UYjVt6aJGVLMgCv+qLekdsCsmVBwOWhEWwASVZ5WW5qWyOL613+zKXyQvqBcWWvg68CZk2rEjZvH64dPlVXV0hxYLb7p43WNgY+e8MR+RHA0/aGnvB4cwCKQw23n2B9bg+wxDwS7fK9/va/0HspgUvwGv8fNpdsYW1OgLnY1deUHhJc1+UaUFwHJVdB7Nx/WmQ0eq0s2wtLQGy0tpkDAkL5I9yd+qOSIbRoqSxBA7l/HWht0xGvVgNUOarOAeoqwfuBre8d3L5s5RR0HSmbjjP26/82rqxhQxiO7/O9lkCJ3GEe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rYYN0chiDKIhFAa+PtylRK2fGeVnOZQSMcy04VIC5T+e0KR3pIt9PdJ72SHEYjmdNL+W9JL/fjz+co5Vxpz6p6RCwE1pL+kw4B0v1/BhJJB+NIv+GXTxOYeGx8K/P/3B9KUsbBykBQOvjcM8kJFIx5yry9idrtEGh5Ejw7UZ1W2sWIpFdKIAGUm54ir07a5Txkhy7PBIiyp5PRacp6V6S9aI8liE5LRC1qguXcKnbBg3QudnY/wUFwB6rJf7EBA2otA8PgEG8ICOg86XltPUqpVKUMBiu30jIa0VFS3O8BtuJvzdmVa8xK4K3ZP3/T4s4SAMOtyi6L4pxTJB9NHI0WnvQQeVAxlizlIu6VMwDdZuVtRJa0wbKTIDmc7lF+d2pD5uYOSLakc5h5jKRz386Dt9pYA577NKP+ioED2m+iv9bLPDIhDo6X589HxFZX4oxrzDI7m85rUvWBgNWqjZ9MpQSuui9yr2F5P8xtBsHDEIRi+wqX7Sui56cRuLZYaWvMVOIwkplHDIz0afncgI5BcA8KM4mJfpKosF42cWAMhijdDVAG234RIP6ogJCAcQu3q+q8uG2sYf655WE3+70zh0aiLvgQa1odo9FdEXV5HWs6Gh4hUDhA0ULlZVbJ+Mxg/XacBb+AnBxBpuSrIjfHaEtCkFKlDdF48Ny+HFVojxE4ZYuoNlXDDVkBi58aj2oMFDfaPB+bEJjxF7wpqjbts703mEckhLhQWpnnhNVbEyBGED8N4gIiA=", - "hash": "18381574995221799963215366500837755447342811019610547066832598459350935665488" + "data": "AACzYt9qtBkn6y40KDH0lkzRSMBh3W41urWE6j0PSP2KB9GxsBAHAI3uzay1Vqyc+LMXeANSzNcoYSYnZts9Pk0nFNjCZ84EnGkie609NhFB8tU9k5Vkoqw3jihdsoJEUy6GK0H30dl/7H1rGxsx6Ec05aaFhiPw6t0jLxF1kj4uIeipqOScf8snKuzywk02FqvRxSHlk9pkEsUOvpNIwywxzhvHjWgXEQzROQF8v6q5R/1aJk3swpM1iRct9URLIjdin4GWyDB9279EZ6D6avFW2l7WuM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rVSq5K99wUJ01O93Kn8LQlrAbjHWo5Za+tW0a/+Qlbr5E2eSEge+ldnbMbA9rcJwZf4bT457dBXMdlD7mECIDZtD8M/KLeyzMEinDzPfqnwZjU2ifxs6gaJPXOQAWPzbCm/z2vGlRbXDGZF6yTbLTdjzviuPhVtb7bzsZW2AYC+TlZqb4qm9MAVsH5rX3OZmvvmw5oRKeSj+FFD7uSRwfutDGC99i93uptU8syL/8Tr8xU3atxITlSqHqG+rVGWdLO9i3iq38zXgXbvZacrc3CMF5QBIM8yZXNslXH5k39D5SqubSHBWTqAJ1I0heOjaIHQGLROBYLn178tckBxfKQ2UpyfkvMw1Waw+fp5f64Ce+5bmYyZr6Dhmw/xcoAihjUsEqoecrLuGPp6qI4hQt9qOnVrAxHzwwtJGxcqoiCbe1mgz0fxMCt/i0z3ygdqAn20DKPHuBdqgVUFwx2T7Ac9fUCf3RHMq34onrr2nLHc038GYedmlFjoUZStujGwA8tSwLWyuWZTDVV+ZaW92qkhmrACog6NwhR6SEjQgsMRCVBQZzYirZxyulYmcNWH6BUmnLLFsn3GbS40xUr70gujEPnjZUK/ExGRfUPOfrYYb8mAciE9nP8OeK/UI+zjJy6Qp8mMroFw7gVHCfDtKTeQFt4JV3zubGsD7jypquHKCqPewhgn9tZ1UIsKIQB7+hBwDHzhlOZ2FfR4eLwQkO8sz275tpjHDAqX/TBWWRVg/yBDii0CWN4bP8UuX36jZKZboJUxIkM1xThiGZM2/oMbe5cZyjgrBR3P21wiDHAAlsHkaMfJgkVLqvZOw8hflKRIMa2dEYo5voD6aV30sATHQLoV0o+MlV3WA38RA+23Jqt1g+UZ7ReAuDP88jXhqWFcIvWHrJG0oy+rpAPQU/38vhIxbl//lirsirdVK2LrU47CC1f9/pRi07vTnvAm+n02dhwriqpwOmI2o2OU4mO0q96pCueKjAttkXgz+NSIJzcwprvNyE9UtKWswmIQg=", + "hash": "25447212082831819715054236631079960883754611880602728284997977929479384060913" } } } \ No newline at end of file