Repository navigation
Conversation
…ban-hex `circom-to-soroban-hex` never read the `curve` field of the input JSON, so a BN254 key was silently re-encoded into the BLS12-381 byte layout. The resulting blob contains points that are not on BLS12-381 and only fails later, deep inside `VerificationKey::from_bytes`. Changes: - read `curve` and refuse anything but BLS12-381, normalising `bls12381`, `bls12-381` and `BLS12_381` so the committed circom key is accepted (the previous naive `!= "bls12-381"` check rejected the real key); - validate every group element before encoding: field-range parse, `z == 1`, and `is_on_curve`, so a mis-curved or hand-edited key cannot slip through; - return `Result<_, VkError>` from `vk_hex`; `main` prints the reason to stderr and exits 1 with empty stdout, so a shell pipeline can never capture a mis-curved key blob; - restore the G2 limb-order test with arkworks' actual order (`c1` then `c0`, `ark-bls12-381 0.4.0` `curves/g2.rs::serialize_with_mode`) and add a round-trip test that decodes the committed key's `beta_2` back through `G2Affine::deserialize_uncompressed`, the same path `G2Affine::from_array` uses on-chain. Acceptance evidence (local, Rust 1.99.0): - bn128 key -> exit 1, 0 bytes on stdout, stderr: curve mismatch: ... got "bn128"; refusing to re-encode ... - bls12381 key -> 1060 bytes (2120 hex), IC length prefix `00000004` - `cargo test --manifest-path packages/contracts/circom-to-soroban-hex/Cargo.toml` -> 6 passed, 0 failed - `cargo fmt --check` and `cargo clippy --all-targets -- -D warnings` clean
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.
Closes #65
Problem
circom-to-soroban-hexnever read thecurvefield of the input JSON. Running it on the committed BN254 key (packages/circuits/build/verification_key.json) silently re-encodes it into the BLS12-381 byte layout. The resulting blob contains points that are not on BLS12-381 and only fails much later, insideVerificationKey::from_bytes.Fix
packages/contracts/circom-to-soroban-hex/src/main.rscurveand refuse anything that is not BLS12-381. Names are normalised first, sobls12381(what circom writes),bls12-381(issue title) andBLS12_381are all accepted — a naive!= "bls12-381"check rejects the real committed key.z == 1, andis_on_curve. A mis-curved or hand-edited key cannot slip through even if thecurvefield is spoofed.vk_hexnow returnsResult<_, VkError>;mainprints the reason to stderr and exits 1 with empty stdout, so a shell pipeline can never capture a mis-curved blob.Cargo.toml: remove the duplicatedark-bls12-381/ark-serializekeys (the manifest declared both0.4.0and0.6.0, so the crate did not resolve).Tests
cargo test --manifest-path packages/contracts/circom-to-soroban-hex/Cargo.toml→ 6 passed, 0 failedbn128_key_is_rejected_without_hex— the committed BN254 key returnsCurveMismatch("bn128")and no hex.bls12381_key_emits_expected_layout— the committed BLS12-381 key encodes to 1060 bytes (2120 hex chars), IC length prefix00000004.real_vk_g2_points_round_trip— the encodedbeta_2decodes back throughG2Affine::deserialize_uncompressed, the same pathG2Affine::from_arrayuses on-chain.g2_limbs_serialize_as_c1_then_c0— pins arkworks' real limb order (ark-bls12-381 0.4.0,curves/g2.rs::serialize_with_mode). The previous test asserted the opposite order and could never pass; that is why it was removed rather than fixed.curve_spellings_are_equivalent,missing_curve_is_rejected.Verification (local, Rust 1.99.0)
cargo fmt --checkandcargo clippy --all-targets -- -D warningsare clean.