rewrite Bigger constraint as a dataclass

This commit is contained in:
David Rusu 2024-05-17 18:36:30 +04:00
parent 25c52d81b0
commit 211a543513
1 changed files with 14 additions and 6 deletions

View File

@ -1,13 +1,21 @@
from dataclasses import dataclass
from noir_constraint import NoirConstraint, NoirProof from noir_constraint import NoirConstraint, NoirProof
@dataclass
class Bigger: class Bigger:
def __init__(self, y: int): """
self.y = y The statement "I know an `x` that is bigger than `y`".
self.noir = NoirConstraint("bigger") - `y` is a public parameter provided when the constraint is initialized
- `x` is a secret parameter provided at proving time
"""
y: int
_noir = NoirConstraint("bigger")
def prove(self, x: int) -> NoirProof: def prove(self, x: int) -> NoirProof:
return self.noir.prove({"x": str(x), "y": str(self.y)}) return self._noir.prove({"x": str(x), "y": str(self.y)})
def verify(self, proof): def verify(self, proof: NoirProof):
return self.noir.verify({"y": str(self.y)}, proof) return self._noir.verify({"y": str(self.y)}, proof)