bring back the SafeLessThan

This commit is contained in:
thomaslavaur 2025-08-26 15:36:55 +02:00
parent fa940b1ed2
commit d2c15d96c1

View File

@ -57,4 +57,24 @@ template SafeFullLessThan() {
intermediate_results[3] <== B.out * (intermediate_results[0] + intermediate_results[2]);
out <== (1 - A.out) * ((1 - B.out) + intermediate_results[3]);
}
// Safely compare two n-bit numbers
// Performs range checks on the inputs to avoid overflow. Range is n <= 252
template SafeLessThan(n) {
assert(n <= 252);
signal input in[2];
signal output out;
component aInRange = Num2Bits(n);
aInRange.in <== in[0];
component bInRange = Num2Bits(n);
bInRange.in <== in[1];
component lt = LessThan(n);
lt.in[0] <== in[0];
lt.in[1] <== in[1];
out <== lt.out;
}