Skip to content
This repository was archived by the owner on Aug 4, 2026. It is now read-only.
This repository was archived by the owner on Aug 4, 2026. It is now read-only.

Optimized arithmetic and comparisons for UInt gadgets #150

Description

@95DDB

Depends on #149 .

Actually, for our applications, in which we compare only small numbers (usually max 64 bits in length), we can do better by defining the comparison directly for the UInt gadgets: to prove an inequality of the from x >= y, where x and y are UInt gadgets, we can follow an approach similar to what we did for the ThresholdSignatureCircuit (enforcing number_of_valid_signatures >= threshold) https://github.com/HorizenOfficial/zendoo-sc-cryptolib/blob/development/doc/GenericThresholdCircuit.pdf, e.g. enforcing that pack(x_bits) - pack(y_bits) == pack(alloc(x_val-y_val).to_bits_with_length_restriction[..64])
(We can do this with 1 LC of the form 2^0(x_b0 - y_b0) + ... + 2^n-1(x_bn-1 - y_bn-1) = 2^0 diff_0 + ... + 2^n-1 * diff_n-1.
We can also integrate Add and Mul gadgets for UInt (we already have AddMany), and let them return an "overflow" bit that, if desired, we can enforce it to be 0. This will make operations and comparison doable without using any Field gadget, thus completely controllable and secure.

Metadata

Metadata

Labels

enhancementNew feature or requestnew featureoptimizationPerformance improvement for the current codebase

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions