From 8fe714930f2e4c5cfa7fe4850df5edbcc6c00364 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 16 Jul 2024 10:20:39 -0700 Subject: [PATCH] refactor(bitwise.unit-test.ts): change bit size from 254 to 240 in xor, 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. --- src/lib/provable/test/bitwise.unit-test.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/provable/test/bitwise.unit-test.ts b/src/lib/provable/test/bitwise.unit-test.ts index 1c3bbc8240..23b3c38bc7 100644 --- a/src/lib/provable/test/bitwise.unit-test.ts +++ b/src/lib/provable/test/bitwise.unit-test.ts @@ -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: { @@ -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); @@ -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); @@ -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(