Skip to content

Commit

Permalink
use full boolean comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Mar 27, 2024
1 parent 87be871 commit 1b80114
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
19 changes: 4 additions & 15 deletions src/lib/provable/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ import { setFieldConstructor } from './core/field-constructor.js';
import {
assertLessThanFull,
assertLessThanOrEqualFull,
checkRangesAsProver,
lessThanGeneric,
lessThanOrEqualGeneric,
lessThanFull,
lessThanOrEqualFull,
} from './gadgets/comparison.js';

// external API
Expand Down Expand Up @@ -587,11 +586,7 @@ class Field {
if (this.isConstant() && isConstant(y)) {
return new Bool(this.toBigInt() < toFp(y));
}
y = Field.from(y);
let maxBits = Fp.sizeInBits - 2;
let upperBound = 1n << BigInt(maxBits);
checkRangesAsProver(this, y, upperBound);
return lessThanGeneric(this, y, upperBound, (v) => v.toBits(maxBits));
return lessThanFull(this, Field.from(y));
}

/**
Expand Down Expand Up @@ -621,13 +616,7 @@ class Field {
if (this.isConstant() && isConstant(y)) {
return new Bool(this.toBigInt() <= toFp(y));
}
y = Field.from(y);
let maxBits = Fp.sizeInBits - 2;
let upperBound = 1n << BigInt(maxBits);
checkRangesAsProver(this, y, upperBound);
return lessThanOrEqualGeneric(this, y, upperBound, (v) =>
v.toBits(maxBits)
);
return lessThanOrEqualFull(this, Field.from(y));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/vk-regression/vk-regression.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@
"digest": "f7979c1aef4fb5672c7bd77ea927c10f"
},
"lessThan": {
"rows": 254,
"digest": "886cbd114436d757e58a24ac7241ea4c"
"rows": 38,
"digest": "eed5490ecb8d1d6a8e9d3699cf5e175a"
},
"assertLessThanUInt64": {
"rows": 14,
Expand Down

0 comments on commit 1b80114

Please sign in to comment.