Skip to content

chore: Native curve audit - pairing#21104

Merged
federicobarbacovi merged 16 commits into
merge-train/barretenbergfrom
fb/native_curve_audit_pairing
Mar 11, 2026
Merged

chore: Native curve audit - pairing#21104
federicobarbacovi merged 16 commits into
merge-train/barretenbergfrom
fb/native_curve_audit_pairing

Conversation

@federicobarbacovi

@federicobarbacovi federicobarbacovi commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

🧾 Audit Context

ecc/curve audit: pairing. In this PR we add documentation and testing for pairings. We also rewrite the implementation of the Miller loop to follow standard references.

🛠️ Changes Made

  • Add testing for pairings
  • Add benchmarks for pairings
  • Add documentation + md file
  • Rewrite Miller loop implementation to follow standard reference (linked in code) --> No change in performance

Note: I tried implementing cyclotomic squaring but the result was not faster than the current implementation (it was slower). The problem is the inversion that is required to decompress the squaring (which were computed in compressed form). Even using a batch inversion trick didn't help. The paper I tried to implement is: https://eprint.iacr.org/2010/542.pdf

✅ Checklist

  • Audited all methods of the relevant module/class
  • Audited the interface of the module/class with other (relevant) components
  • Documented existing functionality and any changes made (as per Doxygen requirements)
  • Resolved and/or closed all issues/TODOs pertaining to the audited files
  • Confirmed and documented any security or other issues found (if applicable)
  • Verified that tests cover all critical paths (and added tests if necessary)
  • Updated audit tracking for the files audited (check the start of each file you audited)

📌 Notes for Reviewers

(Optional) Call out anything that reviewers should pay close attention to — like logic changes, performance implications, or potential regressions.

@@ -239,12 +197,7 @@ template <typename quadratic_field, typename base_field, typename Fq12Params> cl
};
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried implementing cyclotomic squaring as explained in https://eprint.iacr.org/2010/542.pdf (and use the squaring to compute powers). It wasn't faster than the current implementation. While squaring in compressed form uses fewer operations, decompression requires an inversion. During an exponentation, we need to decompress many times. I tried to use a batch inversion trick, but that stil didn't make the calculation faster. For this reason, I removed the implementation (which is present in the history of this branch) in favour of simpler code.

@federicobarbacovi federicobarbacovi marked this pull request as ready for review March 4, 2026 16:15
file(GLOB_RECURSE TEST_SOURCE_FILES *.test.cpp)
file(GLOB_RECURSE BENCH_SOURCE_FILES *.bench.cpp)
file(GLOB_RECURSE FUZZERS_SOURCE_FILES *.fuzzer.cpp)
file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS *.cpp)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Auto re-discover some files. Discussed with @ludamad and he's ok with it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks, this is helpful!

Comment thread barretenberg/cpp/src/barretenberg/ecc/curves/bn254/PAIRING.md Outdated
Comment thread barretenberg/cpp/src/barretenberg/ecc/curves/bn254/PAIRING.md Outdated
Comment thread barretenberg/cpp/src/barretenberg/ecc/curves/bn254/PAIRING.md Outdated
Comment thread barretenberg/cpp/src/barretenberg/ecc/curves/bn254/PAIRING.md Outdated
constexpr bool operator==(const field6& other) const { return c0 == other.c0 && c1 == other.c1 && c2 == other.c2; }

/**
* @brief Multiply a field6 element by a0 + a1 * v.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice!

{
base_field A = a0 * c0;
base_field B = a1 * c1;
base_field C = Fq6Params::mul_by_non_residue(a1 * c2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I won't complain if you change the name of the mul_by_non_residue method, it confused me!


constexpr void final_exponentiation_easy_part(const fq12& elt, fq12& r);
*
* @details When calculating pairings, point operations are calculated via an ad-hoc method, so it's more sensible to

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah, nice!

Comment thread barretenberg/cpp/src/barretenberg/ecc/curves/bn254/pairing_impl.hpp Outdated
Comment thread barretenberg/cpp/src/barretenberg/ecc/curves/bn254/pairing_impl.hpp Outdated
Comment thread barretenberg/cpp/src/barretenberg/ecc/curves/bn254/pairing_impl.hpp Outdated
Comment thread barretenberg/cpp/src/barretenberg/ecc/curves/bn254/PAIRING.md Outdated
@notnotraju notnotraju self-requested a review March 10, 2026 14:28

@notnotraju notnotraju left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great, thank you! A few tiny nits here and there.

@federicobarbacovi federicobarbacovi force-pushed the fb/native_curve_audit_pairing branch from eaed213 to 7d20477 Compare March 11, 2026 13:07
@federicobarbacovi federicobarbacovi enabled auto-merge (squash) March 11, 2026 13:51
@federicobarbacovi federicobarbacovi merged commit aac88be into merge-train/barretenberg Mar 11, 2026
12 checks passed
@federicobarbacovi federicobarbacovi deleted the fb/native_curve_audit_pairing branch March 11, 2026 14:01
github-merge-queue Bot pushed a commit that referenced this pull request Mar 11, 2026
BEGIN_COMMIT_OVERRIDE
chore: Native curve audit - pairing (#21104)
feat: batch hiding kernel and translator proofs (#21246)
fix: remove obsolete KZG:masking_challenge from batched translator
expected manifest (#21371)
fix: add TLS alignment pad to fix x86_64-macos segfault (#21372)
END_COMMIT_OVERRIDE
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