From c9e288b52ab944a52f652bf3860d94866f7739f3 Mon Sep 17 00:00:00 2001 From: Giacomo Date: Mon, 8 Jul 2024 17:35:25 +0200 Subject: [PATCH] fix: make assertions to deal with warnings --- packages/poseidon-cipher/src/poseidon-cipher.circom | 3 ++- packages/poseidon-proof/src/poseidon-proof.circom | 2 ++ packages/utils/src/float.circom | 3 +++ packages/utils/src/safe-comparators.circom | 12 ++---------- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/poseidon-cipher/src/poseidon-cipher.circom b/packages/poseidon-cipher/src/poseidon-cipher.circom index 34b9952..c76737d 100644 --- a/packages/poseidon-cipher/src/poseidon-cipher.circom +++ b/packages/poseidon-cipher/src/poseidon-cipher.circom @@ -109,12 +109,13 @@ template PoseidonDecryptIterations(length) { var two128 = 2 ** 128; + assert(nonce >= 0 && nonce < (2 ** 128) && two128 >= 0); + // nonce must be < 2^128 component lt = LessThan(252); lt.in[0] <== nonce; lt.in[1] <== two128; lt.out === 1; - // calculate the number of iterations // needed for the decryption // process diff --git a/packages/poseidon-proof/src/poseidon-proof.circom b/packages/poseidon-proof/src/poseidon-proof.circom index 6e82ecf..47b778b 100644 --- a/packages/poseidon-proof/src/poseidon-proof.circom +++ b/packages/poseidon-proof/src/poseidon-proof.circom @@ -24,4 +24,6 @@ template PoseidonProof(NUMBER_OF_INPUTS) { // Dummy constraint to prevent compiler from optimizing it. signal dummySquare <== scope * scope; + + dummySquare === scope * scope; } diff --git a/packages/utils/src/float.circom b/packages/utils/src/float.circom index e56c2a0..4e190c8 100644 --- a/packages/utils/src/float.circom +++ b/packages/utils/src/float.circom @@ -8,6 +8,9 @@ include "mux1.circom"; template MSB(n) { signal input in; signal output out; + + // Ensure the input is less than 2^254 within the finite field for BN254. + assert(in < (2 ** 254)); // Convert the number to its bit representation. var n2b[n]; diff --git a/packages/utils/src/safe-comparators.circom b/packages/utils/src/safe-comparators.circom index 5b63669..91ec62b 100644 --- a/packages/utils/src/safe-comparators.circom +++ b/packages/utils/src/safe-comparators.circom @@ -11,17 +11,9 @@ template SafeLessThan(n) { signal input in[2]; signal output out; - // Convert both inputs to their bit representations to ensure - // they fit within 'n' bits. - var n2b1[n]; - n2b1 = Num2Bits(n)(in[0]); - - var n2b2[n]; - n2b2 = Num2Bits(n)(in[1]); - // Additional conversion to handle arithmetic operation and capture the comparison result. - var n2b[n+1]; - n2b = Num2Bits(n + 1)(in[0] + (1<