Skip to content

Conversation

@Oghma
Copy link

@Oghma Oghma commented Nov 28, 2025

Implement Neg trait for G1Affine. This is useful for verifying Groth16 proofs.

What

  • Introduce an Fq newtype wrapping BytesN<FP_SERIALIZED_SIZE> as the BN254 base field element
  • Implement Neg for Fq
  • Implement Neg for G1Affine by:

Why

  • We need this operation to make cheaper groth16 verification on the bn254 curve. BLS has implemented this feature as well.

Known limitations

  • Negation is implemented only for G1Affine; G2Affine and other types (e.g. projective representations) do not yet have Neg implementations.

@anupsdf anupsdf requested review from jayz22 and sisuresh and removed request for jayz22 December 1, 2025 04:56

impl_bytesn_repr!(G1Affine, G1_SERIALIZED_SIZE);
impl_bytesn_repr!(G2Affine, G2_SERIALIZED_SIZE);
impl_bytesn_repr!(Fq, FP_SERIALIZED_SIZE);
Copy link
Member

Choose a reason for hiding this comment

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

If Fq and FP the same things or do we need a size var for Fq?

Copy link
Author

Choose a reason for hiding this comment

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

It's just a naming convention. Technically, in bn254 they are called Fq and not Fp. I forgot to change FP_SERIALIZED_SIZE in FQ_SERIALIZED_SIZE

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not too familiar with outside conventions, but I think we should use Fp just for consistency. (honestly I found the switching really confusing and never understood why)
Anyways we haven't introduced Fq anywhere (in the CAP or in the env), and the Fp here is just an internal type to facilitate negation. I don't feel it's worth to switch the naming (to match some outside convention).

Copy link
Author

Choose a reason for hiding this comment

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

Ok. Let's use Fp

@sisuresh sisuresh requested a review from jayz22 December 4, 2025 01:16
#[cfg(not(target_family = "wasm"))]
use crate::xdr::ScVal;
use crate::{
crypto::bls12_381::BigInt,
Copy link
Contributor

Choose a reason for hiding this comment

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

We should move this to a shared util file. I made the change here that you can cherry-pick, or if you'd like, I can pick up this PR. Please let me know.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

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.

4 participants