Skip to content

crypto: Restrict conjugate() to degree-2 extension fields#1485

Open
chfast wants to merge 1 commit intomasterfrom
crypto/conjugate
Open

crypto: Restrict conjugate() to degree-2 extension fields#1485
chfast wants to merge 1 commit intomasterfrom
crypto/conjugate

Conversation

@chfast
Copy link
Copy Markdown
Member

@chfast chfast commented Apr 6, 2026

The conjugate operation (negating the second coefficient) is only mathematically correct for degree-2 extensions. Add a requires clause to prevent misuse on degree-3+ types where it would produce incorrect results silently.

The conjugate operation (negating the second coefficient) is only
mathematically correct for degree-2 extensions. Add a requires clause
to prevent misuse on degree-3+ types where it would produce incorrect
results silently.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents mathematically incorrect use of ExtFieldElem::conjugate() by restricting it to quadratic (degree-2) extension fields, where conjugation is defined as negating the second coefficient.

Changes:

  • Add a C++20 requires(DEGREE == 2) constraint to ExtFieldElem::conjugate().
  • Simplify the conjugation implementation to directly return (a, -b) for degree-2 elements.
  • Update the doc comment to explicitly document the degree-2 semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.79%. Comparing base (2381428) to head (563268e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1485      +/-   ##
==========================================
- Coverage   96.79%   96.79%   -0.01%     
==========================================
  Files         154      154              
  Lines       13932    13929       -3     
  Branches     3265     3264       -1     
==========================================
- Hits        13486    13483       -3     
  Misses        306      306              
  Partials      140      140              
Flag Coverage Δ
eest-develop 92.75% <100.00%> (-0.01%) ⬇️
eest-develop-gmp 28.05% <100.00%> (-0.02%) ⬇️
eest-legacy 15.25% <0.00%> (+<0.01%) ⬆️
eest-libsecp256k1 29.75% <100.00%> (-0.02%) ⬇️
evmone-unittests 91.51% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 95.93% <100.00%> (-0.01%) ⬇️
tooling 85.03% <ø> (ø)
tests 99.77% <ø> (ø)
Files with missing lines Coverage Δ
lib/evmone_precompiles/pairing/field_template.hpp 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants