From 92b020a0ecea9b2445c7446278b9af0904c16dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 11 Aug 2026 00:06:21 +0200 Subject: [PATCH] crypto: Move the twisted curve's b coefficient onto E2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/evmone_precompiles/bn254.hpp | 3 +++ lib/evmone_precompiles/pairing/bn254/fields.hpp | 4 ---- lib/evmone_precompiles/pairing/bn254/utils.hpp | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/evmone_precompiles/bn254.hpp b/lib/evmone_precompiles/bn254.hpp index 929879ee9a..4d9fa955df 100644 --- a/lib/evmone_precompiles/bn254.hpp +++ b/lib/evmone_precompiles/bn254.hpp @@ -73,6 +73,9 @@ struct E2 { using Fp = Fq2; static constexpr auto A = 0; + /// b/ξ, i.e. Curve::B divided by the Fq⁶ non-residue ξ. + static constexpr Fp B{0x2b149d40ceb8aaae81be18991be06ac3b5b4c5e559dbefa33267e6dc24a138e5_u256, + 0x9713b03af0fed4cd2cafadeed8fdf4a74fa084e52d1852e4a2bd0685c315d2_u256}; }; using ExtPoint = ecc::AffinePoint; diff --git a/lib/evmone_precompiles/pairing/bn254/fields.hpp b/lib/evmone_precompiles/pairing/bn254/fields.hpp index 4c96860f2a..89ecb0fc46 100644 --- a/lib/evmone_precompiles/pairing/bn254/fields.hpp +++ b/lib/evmone_precompiles/pairing/bn254/fields.hpp @@ -22,10 +22,6 @@ struct Fq6Config using ValueT = Fq2; static constexpr uint8_t DEGREE = 3; static constexpr auto ksi = Fq2({Fq(9_u256), Fq(1_u256)}); - static constexpr auto _3_ksi_inv = Fq2({ - Fq(0x2b149d40ceb8aaae81be18991be06ac3b5b4c5e559dbefa33267e6dc24a138e5_u256), - Fq(0x9713b03af0fed4cd2cafadeed8fdf4a74fa084e52d1852e4a2bd0685c315d2_u256), - }); }; using Fq6 = ecc::ExtFieldElem; diff --git a/lib/evmone_precompiles/pairing/bn254/utils.hpp b/lib/evmone_precompiles/pairing/bn254/utils.hpp index b1ab9bf211..77788b1c02 100644 --- a/lib/evmone_precompiles/pairing/bn254/utils.hpp +++ b/lib/evmone_precompiles/pairing/bn254/utils.hpp @@ -49,7 +49,7 @@ constexpr bool is_on_twisted_curve(const ecc::AffinePoint& p) const auto x3 = p.x * p.x * p.x; const auto y2 = p.y * p.y; - return y2 == x3 + Fq6Config::_3_ksi_inv; + return y2 == x3 + E2::B; } // Frobenius endomorphism related functions are implemented based on