Skip to content

Commit

Permalink
fix: make assertions to deal with warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjei committed Jul 8, 2024
1 parent e6eb2a4 commit c9e288b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/poseidon-cipher/src/poseidon-cipher.circom
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/poseidon-proof/src/poseidon-proof.circom
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ template PoseidonProof(NUMBER_OF_INPUTS) {

// Dummy constraint to prevent compiler from optimizing it.
signal dummySquare <== scope * scope;

dummySquare === scope * scope;
}
3 changes: 3 additions & 0 deletions packages/utils/src/float.circom
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
12 changes: 2 additions & 10 deletions packages/utils/src/safe-comparators.circom
Original file line number Diff line number Diff line change
Expand Up @@ -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<<n) - in[1]);
var n2b[254];
n2b = Num2Bits_strict()(in[0] + (1<<n) - in[1]);

// Determine if in[0] is less than in[1] based on the most significant bit.
out <== 1 - n2b[n];
Expand Down

0 comments on commit c9e288b

Please sign in to comment.