zk-block
zk-block copied to clipboard
Potential Under-Constrained Problem within `AgeLimit` Template
Hi! I noticed that the AgeLimit
template is under-constrained due to the lack of necessary checks and constraints. Below are the specific issues and suggested fixes:
- Constraint Creation with
<--
Operator
The <--
operator does not create a constraint, allowing a malicious prover to replace the right-hand side with arbitrary values without detection by the verifier.
For example:
22 out <-- greaterThan.out;
23 out === 1;
This can be bypassed by replacing out <-- greaterThan.out
with out <-- 1
. To prevent this, the code should be updated to enforce constraints explicitly:
out <== greaterThan.out;
out === 1;
- Input Range Checking for
GreaterThan(N)
The GreaterThan(N)
component assumes that inputs are constrained to fit within N
bits. However, without range checks, excessively large inputs can cause incorrect outputs due to overflow.
For instance, consider:
ageLimit = 21888242871839275222246405745257275088548364400416034343698204186575808495592
age = 8
Here, GreaterThan(8)
produces 1, which is incorrect.
Suggested Fix:
Use Num2Bits
from CircomLib to constrain the inputs' bit lengths before passing them to GreaterThan(N)
:
component ageBits = Num2Bits(8);
ageBits.in <== age;
component ageLimitBits = Num2Bits(8);
ageLimitBits.in <== ageLimit;
This ensures that the inputs are correctly constrained to 8 bits, avoiding overflow issues.