Skip to content

crypto: Move the twisted curve's b coefficient onto E2 - #1641

Merged
chfast merged 1 commit into
masterfrom
crypto/twist-b-on-curve
Aug 10, 2026
Merged

crypto: Move the twisted curve's b coefficient onto E2#1641
chfast merged 1 commit into
masterfrom
crypto/twist-b-on-curve

Conversation

@chfast

@chfast chfast commented Aug 10, 2026

Copy link
Copy Markdown
Member

The twisted curve's b = 3/ξ lived in Fq6Config as _3_ksi_inv — a field config
holding a curve constant, named after how it is derived rather than what it is —
while E2 carried no B at all, even though Curve has B = Fp{3}. Its single use
now reads y2 == x3 + E2::B instead of y2 == x3 + Fq6Config::_3_ksi_inv, and the
twist is described the same way as G1.

The value is moved verbatim (extracted programmatically, not retyped). I also
confirmed it really is 3/ξ: it equals (27/82, −3/82) mod p, which is
3(9−u)/((9+u)(9−u)), and ξ · B == (3, 0).

The compiled binary is byte-identicalcmp reports no difference against
master, which is the expected outcome for relocating a compile-time constant, and
makes this a zero-risk change on the performance side. 1172/1172 unit tests pass.

🤖 Generated with Claude Code

The twist's b = 3/ξ sat in Fq6Config as _3_ksi_inv: a field config holding a curve
constant, named after how it is derived rather than what it is, while E2 had no B at
all even though Curve has one. Move it to E2::B so is_on_twisted_curve reads
y2 == x3 + E2::B and the twist is described like G1. The compiled binary is
byte-identical.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Moves the BN254 twisted-curve coefficient from field configuration into the E2 curve definition.

Changes:

  • Adds E2::B with the existing coefficient value.
  • Updates twisted-curve validation to use E2::B.
  • Removes the misplaced _3_ksi_inv field constant.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
lib/evmone_precompiles/bn254.hpp Defines the twisted curve’s B coefficient.
lib/evmone_precompiles/pairing/bn254/fields.hpp Removes the coefficient from Fq6Config.
lib/evmone_precompiles/pairing/bn254/utils.hpp Uses E2::B during curve validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.71%. Comparing base (155eb66) to head (92b020a).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1641   +/-   ##
=======================================
  Coverage   97.71%   97.71%           
=======================================
  Files         171      171           
  Lines       15607    15607           
  Branches     3610     3610           
=======================================
  Hits        15251    15251           
  Misses        269      269           
  Partials       87       87           
Flag Coverage Δ
eest-develop 88.62% <100.00%> (ø)
eest-develop-gmp 26.53% <100.00%> (ø)
eest-legacy 17.15% <0.00%> (ø)
eest-libsecp256k1 28.83% <100.00%> (ø)
eest-stable 88.62% <100.00%> (ø)
evmone-unittests 93.42% <100.00%> (ø)

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

Components Coverage Δ
core 96.10% <100.00%> (ø)
tooling 91.92% <ø> (ø)
tests 99.80% <ø> (ø)
Files with missing lines Coverage Δ
lib/evmone_precompiles/pairing/bn254/fields.hpp 100.00% <ø> (ø)
lib/evmone_precompiles/pairing/bn254/utils.hpp 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chfast
chfast merged commit 519a1f4 into master Aug 10, 2026
24 checks passed
@chfast
chfast deleted the crypto/twist-b-on-curve branch August 10, 2026 22:26
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