Consensys / corset

4 stars 10 forks source link

If with binary condition #91

Closed OlivierBBB closed 1 month ago

OlivierBBB commented 1 month ago

Currently Corset doesn't take advantage of binary-ness of the condition when compiling constraints à la

corset debug "
(defcolumns
  (BIN :binary@prove)
  N
  Z)

(defconstraint example () (if-zero BIN
                                   (vanishes! Z)        ;; zero case
                                   (vanishes! N)))      ;; nonzero case" -xcNeeeeC

produces

=== Constraints ===

example :=
{
 (1 - BIN * C/INV[BIN]) * Z
 BIN * N
}

NORM[BIN] :=
|BIN| == BIN × C/INV[BIN]
BIN×(1 - BIN×C/INV[BIN]) = 0
C/INV[BIN]×(1 - BIN×C/INV[BIN]) = 0

=== Columns ===
  ID                                                                            Name  Type   ×                                              Reg.
   0                                                                             BIN     𝟙   1                                          r0/BINι1
   1                                                                               N     𝔽   1                                            r1/Nι1
   2                                                                               Z     𝔽   1                                            r2/Zι1
   3                                                                      C/INV[BIN]     𝔽   1                                   r3/C/INV[BIN]ι1

=== Computations ===
C/INV[BIN] = (inv BIN)

There are several issues here:


Franklin suggested this fix

image

DavePearce commented 1 month ago

but there should be a binary constraint for BIN

Because it is marked binary@prove ... right?

DavePearce commented 1 month ago

With Franklin's patch we get the following constraints from the example above:

 (1 - BIN) * Z
 BIN * N

But, as I understand it, we should also have a binary constraint as well.

DavePearce commented 1 month ago

See #92 for further discussion around the binary@prove issue.