Skip to content

Commit

Permalink
unit tests for comparison assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Mar 27, 2024
1 parent e274fcd commit ffae661
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/lib/provable/test/foreign-field-gadgets.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,20 @@ let ffProgram = ZkProgram({
return ForeignField.div(x, y, F.modulus);
},
},
assertLessThan: {
privateInputs: [Field3.provable, Field3.provable],
async method(x, y) {
ForeignField.assertLessThan(x, y);
return x;
},
},
assertLessThanOrEqual: {
privateInputs: [Field3.provable, Field3.provable],
async method(x, y) {
ForeignField.assertLessThanOrEqual(x, y);
return x;
},
},
},
});

Expand Down Expand Up @@ -274,6 +288,24 @@ await equivalentAsync({ from: [f, f], to: f }, { runs })(
'prove div'
);

await equivalentAsync({ from: [f, f], to: unit }, { runs })(
(x, y) => assert(x < y, 'not less than'),
async (x, y) => {
let proof = await ffProgram.assertLessThan(x, y);
assert(await ffProgram.verify(proof), 'verifies');
},
'prove less than'
);

await equivalentAsync({ from: [f, f], to: unit }, { runs })(
(x, y) => assert(x <= y, 'not less than or equal'),
async (x, y) => {
let proof = await ffProgram.assertLessThanOrEqual(x, y);
assert(await ffProgram.verify(proof), 'verifies');
},
'prove less than or equal'
);

// assert mul example
// (x - y) * (x + y) = x^2 - y^2

Expand Down

0 comments on commit ffae661

Please sign in to comment.