From 7fe2a56da1cd9a408e04eddbcfd6d70ac3025f41 Mon Sep 17 00:00:00 2001 From: Gregor Date: Tue, 26 Mar 2024 22:02:02 +0100 Subject: [PATCH] new constraint system so we have something to compare against --- .../vk-regression/plain-constraint-system.ts | 54 ++++++++++++++++++- tests/vk-regression/vk-regression.json | 37 +++++++++++++ tests/vk-regression/vk-regression.ts | 8 ++- 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/tests/vk-regression/plain-constraint-system.ts b/tests/vk-regression/plain-constraint-system.ts index 809c3742f8..17414694e6 100644 --- a/tests/vk-regression/plain-constraint-system.ts +++ b/tests/vk-regression/plain-constraint-system.ts @@ -1,6 +1,16 @@ -import { Field, Group, Gadgets, Provable, Scalar, Hash, Bytes } from 'o1js'; +import { + Field, + Group, + Gadgets, + Provable, + Scalar, + Hash, + Bytes, + Bool, + UInt64, +} from 'o1js'; -export { GroupCS, BitwiseCS, HashCS }; +export { GroupCS, BitwiseCS, HashCS, BasicCS }; const GroupCS = constraintSystem('Group Primitive', { add() { @@ -123,6 +133,46 @@ const HashCS = constraintSystem('Hashes', { }, }); +const witness = () => Provable.witness(Field, () => Field(0)); + +const BasicCS = constraintSystem('Basic', { + equals() { + let [x, y, z] = [witness(), witness(), witness()]; + x.equals(y); + z.equals(1); + }, + if() { + let b = Provable.witness(Bool, () => Bool(false)); + let [x, y, z] = [witness(), witness(), witness()]; + Provable.if(b, x, y); + Provable.if(b, z, Field(1)); + }, + toBits() { + let x = witness(); + x.toBits(); + }, + + // comparisons + assertLessThan() { + let [x, y] = [witness(), witness()]; + x.assertLessThan(y); + }, + lessThan() { + let [x, y] = [witness(), witness()]; + x.lessThan(y); + }, + assertLessThanUInt64() { + let x = Provable.witness(UInt64, () => new UInt64(0)); + let y = Provable.witness(UInt64, () => new UInt64(0)); + x.assertLessThan(y); + }, + lessThanUInt64() { + let x = Provable.witness(UInt64, () => new UInt64(0)); + let y = Provable.witness(UInt64, () => new UInt64(0)); + x.lessThan(y); + }, +}); + // mock ZkProgram API for testing function constraintSystem( diff --git a/tests/vk-regression/vk-regression.json b/tests/vk-regression/vk-regression.json index 580bcd6294..4421a8c73d 100644 --- a/tests/vk-regression/vk-regression.json +++ b/tests/vk-regression/vk-regression.json @@ -211,6 +211,43 @@ "hash": "" } }, + "Basic": { + "digest": "Basic", + "methods": { + "equals": { + "rows": 4, + "digest": "941bc7a3f1bc61dd9a031a90eda35257" + }, + "if": { + "rows": 4, + "digest": "8bb444eb77c99f065f108e1dd124bdc0" + }, + "toBits": { + "rows": 254, + "digest": "49e0fdd67c13bd800f641f2375301322" + }, + "assertLessThan": { + "rows": 510, + "digest": "4d72e2e7b6073ac9279accec2bc3889b" + }, + "lessThan": { + "rows": 509, + "digest": "163f60bf937f5a5961f08be58009d06a" + }, + "assertLessThanUInt64": { + "rows": 27, + "digest": "4c2e6066727ece164bd9f1609bd564ef" + }, + "lessThanUInt64": { + "rows": 27, + "digest": "6d139dfc61137449010049ee51dd1de6" + } + }, + "verificationKey": { + "data": "", + "hash": "" + } + }, "ecdsa-only": { "digest": "39205ab5c3c80677719cb409d9b798a8f07dd71fde09cef6d59719bd37ecc739", "methods": { diff --git a/tests/vk-regression/vk-regression.ts b/tests/vk-regression/vk-regression.ts index 9360bcbbe4..5952de5a53 100644 --- a/tests/vk-regression/vk-regression.ts +++ b/tests/vk-regression/vk-regression.ts @@ -8,7 +8,12 @@ import { keccakAndEcdsa, } from '../../src/examples/crypto/ecdsa/ecdsa.js'; import { SHA256Program } from '../../src/examples/crypto/sha256/sha256.js'; -import { GroupCS, BitwiseCS, HashCS } from './plain-constraint-system.js'; +import { + GroupCS, + BitwiseCS, + HashCS, + BasicCS, +} from './plain-constraint-system.js'; import { diverse } from './diverse-zk-program.js'; // toggle this for quick iteration when debugging vk regressions @@ -47,6 +52,7 @@ const ConstraintSystems: MinimumConstraintSystem[] = [ GroupCS, BitwiseCS, HashCS, + BasicCS, ecdsa, keccakAndEcdsa, SHA256Program,