fix: enforce GT subgroup membership in ArkGT deserialization#22
Merged
Conversation
Collaborator
Author
|
@markosg04 is there a reason why |
There was a problem hiding this comment.
Pull request overview
This PR hardens the arkworks backend’s GT (ArkGT) validation during deserialization by adding an explicit prime-order subgroup membership check, addressing a soundness issue where non-GT Fq12 elements could previously pass validation.
Changes:
- Enforce GT subgroup membership for
ArkGTby checkingx^r == 1(withr = Fr::characteristic()). - Route
DoryDeserialize::deserialize_with_mode(..., Validate::Yes)forArkGTthrough the new subgroup check (fully qualified to avoid the encoding-onlyark_serialize::Valid). - Add unit tests covering rejection/acceptance and
Validate::{Yes,No}behavior forArkGTdeserialization.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ArkGT now wraps PairingOutput<Bn254> instead of raw Fq12, ensuring deserialization validates GT subgroup membership (x^r == 1) rather than only field encoding. This closes the attack surface where a malicious prover could supply arbitrary Fq12 elements outside GT. Addresses: FJ-ACT-H-08 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6b0bf09 to
375fc7c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes FJ-ACT-H-08: Dory proof GT elements deserialized as raw
Fq12without subgroup validation, allowing a malicious prover to supply arbitraryFq12elements outside the GT subgroup.ArkGTnow wrapsPairingOutput<Bn254>instead of rawFq12—PairingOutput'sValid::check()verifies GT subgroup membership by computingx^r == 1(where r is the scalar field characteristic), whereasFq12::check()only validates field encodingPairingOutputserializes the same bytes asFq12, with an additional subgroup check on deserializationrandom()now generates valid GT elements via pairing instead of randomFq12(which is almost certainly not in GT)clippy::suspicious_arithmetic_implallows —PairingOutputuses additive notation for GT group ops, so+insideadd()is no longer suspiciousChanged files
ark_group.rs—ArkGTwrapsPairingOutput<Bn254>; manualDefaultreturning group identity; operators usePairingOutput's group opsark_pairing.rs— Stop unwrappingPairingOutputat all 5 construction sites (ArkGT(result.0)→ArkGT(result))ark_serde.rs—DoryDeserializedeserializes asPairingOutput<Bn254>(subgroup check on validation);Valid::check()now delegates toPairingOutput::check()tests/— Wrap testFq12::rand(...)inPairingOutput(...)to match new inner typeTest plan
cargo build --all-features— cleancargo clippy --features "arkworks,parallel,zk"— cleancargo test --features "arkworks,parallel,zk"— 90/90 pass🤖 Generated with Claude Code