Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poseidon2 constraints do not determine outputs #1305

Open
matthiasgoergens opened this issue Feb 28, 2024 · 1 comment
Open

Poseidon2 constraints do not determine outputs #1305

matthiasgoergens opened this issue Feb 28, 2024 · 1 comment

Comments

@matthiasgoergens
Copy link
Collaborator

matthiasgoergens commented Feb 28, 2024

See the code in #1304 and run this test:

cargo test --package mozak-circuits --lib -- poseidon2::stark::tests::poseidon2_constraints --exact --nocapture

Our Poseidon2 constraints can't tell whether the prover gave you the canonical byte representation of the digest or not. I'm not sure whether that's a problem.

To elaborate:

  1. hash(a) == hash(b) implies a == b.
  2. but a == b does not imply hash(a) == hash(b).

In our system so far we are only relying on property (1). But property (2) not holding is very counterintuitive and might catch unaware users off guard.

@codeblooded1729
Copy link
Contributor

codeblooded1729 commented Mar 8, 2024

Here is one way we can go about ensuring canonical representation. Let $(l_{low}, l_{high})$ be representation of $l$ with $32$ bit limbs.
let $p = 2^{64} - 2^{32} + 1$ be goldilocks prime.
Idea is that if $2^{32} l_{high} + l_{low} \ge p \iff l_{high} = 2^{32} - 1 \land l_{low} > 0$
So $l$ is in canonical form means that either $l_{high} < 2^{32} - 1$ or $l_{low} = 0$.
To ensure the first constraint, we can have additional column to store the inverse of gap, say $gap_{inv}$
The final constraint would be
$$(1 - (2^{32} - 1 - l_{high})gap_{inv})l_{low} = 0$$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants