Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some basic gadgets to VK regression #1522

Merged
merged 1 commit into from
Mar 28, 2024
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
54 changes: 52 additions & 2 deletions tests/vk-regression/plain-constraint-system.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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(
Expand Down
37 changes: 37 additions & 0 deletions tests/vk-regression/vk-regression.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 7 additions & 1 deletion tests/vk-regression/vk-regression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,6 +52,7 @@ const ConstraintSystems: MinimumConstraintSystem[] = [
GroupCS,
BitwiseCS,
HashCS,
BasicCS,
ecdsa,
keccakAndEcdsa,
SHA256Program,
Expand Down
Loading