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

Padding point gen using Try-And-Increment #32

Merged
merged 8 commits into from
Sep 20, 2024

Conversation

davxy
Copy link
Collaborator

@davxy davxy commented Sep 18, 2024

TAI success is expected - on average - after two iterations.
For Bandersnatch and the given message it succeeded on the first iteration.

Generated padding point (SW form):

(25353312785503880631115876544961443547556511355876709037985429927235015446936, 48034916494481689813223622984827694955476028581467743482028403440447916980403)

With blake2 we can generate an X for a field with at most 512 bits. I guess this is acceptable (at least for all the curves provided by arkworks). Well, for our usage here, we can probably reduce it to 32 bytes....

@swasilyev
Copy link
Collaborator

What is TAI btw?

@davxy
Copy link
Collaborator Author

davxy commented Sep 18, 2024

Try and Increment

@swasilyev
Copy link
Collaborator

swasilyev commented Sep 18, 2024

Can we just hash the seed once, and then increment the field element? The code will be just a bit simpler, but may take longer to find a point.

let hash: [u8; 64] = blake2::Blake2b::digest(&seed[..]).into();
let x = F::from_le_bytes_mod_order(&hash);
if let Some(point) = Affine::<Curve>::get_point_from_x_unchecked(x, false) {
let point = point.clear_cofactor();
Copy link
Collaborator

@swasilyev swasilyev Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@burdges do we care if it is in the subgroup? Just curious.

Copy link
Collaborator Author

@davxy davxy Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

he asked the same question here: #31 (review)

But I guess yes? As the SEED is not in the prime order subgroup, if you add a padding point not in the prime order subgroup you may end-up with the point at infinity right? Which is not managed in the constraints (and primarily that is why the SEED is chosen to be out of the prime subgroup).

Copy link
Collaborator

@burdges burdges Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. We cannot compute x+x in the SNARK, only x+y with x != y. As our snark never checks that x != y, we need all our additions to be x != y implicitly.

We have two padding points, the start point hs and the empty point he, maybe equal. We compute (..((hs + x[0]) + x[1]) + .. + x[n]) - hs where the x[i] are either a public key if in the bitfield, or zero=infinity if not in the bitfield, or he no public key exists there.

We need -2 hs to not be a combination of x[i], but n << group_order, so either hs should be outside the prime order subgroup, or else we should've proofs of possession for the public keys.

We should presumably just do proofs of possession, because that'll work for prime order curves by bn254, but if skipped the proofs of possession then he != hs matters, but hs = he + coset_element works.

@davxy davxy changed the title Padding point gen using TAI Padding point gen using Try-And-Increment Sep 18, 2024
@davxy
Copy link
Collaborator Author

davxy commented Sep 18, 2024

Can we just hash the seed once, and then increment the field element? The code will be just a bit simpler, but may take longer to find a point.

Although in the Bandersnatch case, with the provided input, it identifies the point on the first iteration (that is primarily why I modified the input string, as otherwise, it was taking 2), my gut feeling is that in general case, by not re-hashing in the loop it may require more time.

What can I say for sure is that, given $x$-coordinate, the curve equation $y^2=x^3+ax+b$ may or may not have a solution in the field. Half of the elements in a finite field are quadratic residues, so half of the x-coordinates will correspond to valid points. Thus iterations are on average 2 with a uniformly distributed x.

Copy link
Collaborator

@burdges burdges left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

We should've proof of possession somewhere, or else deform the padding points, and commit to non-prime order curves.

@davxy davxy merged commit 1472ce9 into w3f:master Sep 20, 2024
4 checks passed
@davxy davxy deleted the padding-point-gen2 branch September 20, 2024 14:22
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

Successfully merging this pull request may close these issues.

3 participants