Skip to content

Commit

Permalink
refactor(bitwise.unit-test.ts): change bit size from 254 to 240 in xo…
Browse files Browse the repository at this point in the history
…r, notUnchecked, notChecked methods and error message

The bit size was reduced from 254 to 240 in multiple places within the Bitwise ZkProgram and the corresponding test case. This change was likely made to optimize performance or to align with some specific requirements of the application. By using a smaller bit size, the computations and proofs involving bitwise operations will be more efficient in terms of time and space complexity.
  • Loading branch information
MartinMinkov committed Jul 16, 2024
1 parent e62a501 commit 8fe7149
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/lib/provable/test/bitwise.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ let Bitwise = ZkProgram({
xor: {
privateInputs: [Field, Field],
async method(a: Field, b: Field) {
return Gadgets.xor(a, b, 254);
return Gadgets.xor(a, b, 240);
},
},
notUnchecked: {
privateInputs: [Field],
async method(a: Field) {
return Gadgets.not(a, 254, false);
return Gadgets.not(a, 240, false);
},
},
notChecked: {
privateInputs: [Field],
async method(a: Field) {
return Gadgets.not(a, 254, true);
return Gadgets.not(a, 240, true);
},
},
and: {
Expand Down Expand Up @@ -153,7 +153,7 @@ await equivalentAsync({ from: [uint(64), uint(64)], to: field }, { runs })(

await equivalentAsync({ from: [maybeField], to: field }, { runs })(
(x) => {
return Fp.not(x, 254);
return Fp.not(x, 240);
},
async (x) => {
let proof = await Bitwise.notUnchecked(x);
Expand All @@ -162,8 +162,8 @@ await equivalentAsync({ from: [maybeField], to: field }, { runs })(
);
await equivalentAsync({ from: [maybeField], to: field }, { runs })(
(x) => {
if (x > 2n ** 254n) throw Error('Does not fit into 254 bit');
return Fp.not(x, 254);
if (x > 2n ** 240n) throw Error('Does not fit into 240 bit');
return Fp.not(x, 240);
},
async (x) => {
let proof = await Bitwise.notChecked(x);
Expand Down Expand Up @@ -246,13 +246,13 @@ function xorChain(bits: number) {
constraintSystem.fromZkProgram(
Bitwise,
'xor',
ifNotAllConstant(contains(xorChain(254)))
ifNotAllConstant(contains(xorChain(240)))
);

constraintSystem.fromZkProgram(
Bitwise,
'notChecked',
ifNotAllConstant(contains(xorChain(254)))
ifNotAllConstant(contains(xorChain(240)))
);

constraintSystem.fromZkProgram(
Expand Down

0 comments on commit 8fe7149

Please sign in to comment.