Repository navigation
Add BIP-374 DLEQ proof verification - #107
FreeOnlineUser wants to merge 6 commits into
Conversation
Implement DLEQ proof verification and generation as per BIP-374. This includes functions to verify and generate DLEQ proofs for ECDH computations without revealing private keys.
This file contains tests for BIP-374 DLEQ proof verification and generation, including various scenarios for tagged hashing, proof generation, and verification.
Added tests to verify failure conditions for DLEQ proof generation.
|
Added edge case hardening based on cryptographic review: Verification (
Generation (
Tests:
Spec Compliance Note: This implements BIP-374 DLEQ verification for BIP-375 Silent Payments use cases. The optional message parameter ( Validation:
No breaking changes to existing API signatures. |
What about extending bitcoinfuzz with DLEQ-related targets? It could be tested against the reference implementation, NBitcoin, or rust-dleq. |
|
If the nonce derivation skips the required
|
The pure-python backend never implemented these (they were left as commented-out stubs copied from the ctypes bindings), so any code using them worked only when the prebuilt libsecp256k1 binary loaded. Since ec_pubkey_parse returns immutable bytes in this backend, the result cannot always be written back in place like libsecp256k1 does: ec_pubkey_tweak_mul mutates the input when it is a bytearray and always returns the resulting point. The ctypes ec_pubkey_tweak_mul now also returns the tweaked pubkey so callers can use one return-value idiom across both backends.
Address review feedback on the nonce derivation: - Derive the nonce deterministically via the BIP0374/aux and BIP0374/nonce tagged hashes from the secret, fresh auxiliary randomness r, the points A and C, and the optional message m, as specified. The previous raw random nonce (and the caller-supplied nonce parameter, a reuse footgun) are gone; generate_dleq_proof now takes auxiliary randomness r instead. - Support the optional 32-byte message m in generation and verification, committed in both the nonce and the challenge. - Support a custom generator G in generation (verification already had it); normalize all points to compressed encodings for the challenge hash. - Self-verify each generated proof before returning, as the reference implementation does. - Run the official BIP-374 test vectors byte-exact (test_vectors_generate_proof.csv and test_vectors_verify_proof.csv, embedded verbatim), plus the existing property tests, now against both secp256k1 backends. - Move the tests to tests/tests/test_dleq.py so the test runner actually discovers them, and drop the pytest dependency and typing import for micropython compatibility.
|
Updated:
|
Add BIP-374 DLEQ proof verification
Description
Adds DLEQ (Discrete Log Equality) proof verification as specified in BIP-374. This complements the existing BIP-375 PSBT field support in #79 by providing the actual cryptographic verification.
What this adds
verify_dleq_proof(A, B, C, proof)- Verify a BIP-374 DLEQ proofgenerate_dleq_proof(a, B)- Generate a DLEQ proof (for testing/coordinators)tagged_hash(tag, data)- BIP-340 style tagged hashingWhy this matters
BIP-375 Silent Payments PSBTs include DLEQ proofs (
PSBT_GLOBAL_SP_DLEQ) to prove ECDH shares were computed correctly. Without verification, signing devices must trust the coordinator's math.With this, a signing device can:
Usage
Implementation notes
ec_pubkey_negate()returns a new point (doesn't modify in-place)Related
References