Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
schnorr.test.cpp File Reference

Go to the source code of this file.

Typedefs

using Fr = grumpkin::fr
 
using Fq = grumpkin::fq
 
using G1 = grumpkin::g1
 

Functions

 TEST (schnorr, verify_signature)
 
 TEST (schnorr, verify_signature_failure_wrong_message)
 
 TEST (schnorr, verify_signature_failure_wrong_key)
 
 TEST (schnorr, signatures_not_deterministic)
 
 TEST (schnorr, signature_internals_consistency)
 Verify the signature internals independently, without relying on construct + verify using the same code path.
 
 TEST (schnorr, challenge_dst_pinned)
 Pin the schnorr challenge domain separator.
 
 TEST (schnorr, cross_field_serialization_is_lossless)
 Verify that the cross-field serialization round-trip is lossless.
 
 TEST (schnorr, bbapi_byte_interface_round_trip)
 Verify that the bbapi byte interface produces valid signatures.
 
 TEST (schnorr, pinned_test_vector_small)
 Pinned test vector #1: small inputs.
 
 TEST (schnorr, pinned_test_vector_large)
 Pinned test vector #2: random-looking large inputs.
 

Typedef Documentation

◆ Fq

using Fq = grumpkin::fq

Definition at line 11 of file schnorr.test.cpp.

◆ Fr

using Fr = grumpkin::fr

Definition at line 10 of file schnorr.test.cpp.

◆ G1

using G1 = grumpkin::g1

Definition at line 12 of file schnorr.test.cpp.

Function Documentation

◆ TEST() [1/10]

TEST ( schnorr  ,
bbapi_byte_interface_round_trip   
)

Verify that the bbapi byte interface produces valid signatures.

Simulates the bbapi path: message comes as 32 bytes (a serialized field element), gets deserialized to Fq, used for signing, then verified.

Definition at line 165 of file schnorr.test.cpp.

◆ TEST() [2/10]

TEST ( schnorr  ,
challenge_dst_pinned   
)

Pin the schnorr challenge domain separator.

Cross-implementation regression: the value here must match SCHNORR_CHALLENGE_DST in noir-lang/schnorr (src/lib.nr). Both sides derive the same constant from poseidon2_hash_bytes("schnorr_grumpkin_poseidon2"); if either side drifts, every signature stops verifying across the cpp signer / noir verifier boundary.

Definition at line 125 of file schnorr.test.cpp.

◆ TEST() [3/10]

TEST ( schnorr  ,
cross_field_serialization_is_lossless   
)

Verify that the cross-field serialization round-trip is lossless.

Since Fr (Grumpkin scalar = BN254 Fq) has a larger modulus than Fq (Grumpkin base = BN254 Fr), every Fq value should survive the Fq -> bytes -> Fr conversion without loss.

Definition at line 137 of file schnorr.test.cpp.

◆ TEST() [4/10]

TEST ( schnorr  ,
pinned_test_vector_large   
)

Pinned test vector #2: random-looking large inputs.

Definition at line 264 of file schnorr.test.cpp.

◆ TEST() [5/10]

TEST ( schnorr  ,
pinned_test_vector_small   
)

Pinned test vector #1: small inputs.

Hardcoded (private_key, nonce_k, message) -> (public_key, signature). The expected outputs are pinned; any change to the schnorr scheme (e.g. hash function, challenge ordering) will break this. Round-trip verification ensures the recomputed values still satisfy the verifier.

Definition at line 242 of file schnorr.test.cpp.

◆ TEST() [6/10]

TEST ( schnorr  ,
signature_internals_consistency   
)

Verify the signature internals independently, without relying on construct + verify using the same code path.

This test manually recomputes the Poseidon2 challenge and checks the Schnorr equation s = k - priv * e, catching bugs like the reinterpret_cast issue where both sides had a matching bug that cancelled out.

Definition at line 87 of file schnorr.test.cpp.

◆ TEST() [7/10]

TEST ( schnorr  ,
signatures_not_deterministic   
)

Definition at line 59 of file schnorr.test.cpp.

◆ TEST() [8/10]

TEST ( schnorr  ,
verify_signature   
)

Definition at line 14 of file schnorr.test.cpp.

◆ TEST() [9/10]

TEST ( schnorr  ,
verify_signature_failure_wrong_key   
)

Definition at line 43 of file schnorr.test.cpp.

◆ TEST() [10/10]

TEST ( schnorr  ,
verify_signature_failure_wrong_message   
)

Definition at line 28 of file schnorr.test.cpp.