threshold_test - DKLS23 Threshold ECDSA Tests¶
Overview¶
The threshold_test module provides comprehensive test coverage for the DKLS23
threshold ECDSA implementation. It validates all components of the threshold
signature protocol including oblivious transfer, MtA conversion, secret sharing,
distributed key generation, presigning, and signing.
These tests ensure correctness, security properties, and proper error handling across the entire threshold ECDSA stack.
Test Categories¶
The test suite is organized into the following categories:
- Oblivious Transfer Tests (TestSimpleOT, TestOTExtension)
Basic OT correctness for choice bits 0 and 1
Multiple independent OT transfers
Invalid point rejection (identity element attacks)
OT extension with 256+ OTs
Base OT setup verification
- MtA Tests (TestMtA, TestMtAwc)
Multiplicative-to-additive correctness: a·b = α + β
Real OT security (receiver never sees both messages)
Edge cases near curve order boundary
MtAwc zero-knowledge proof verification
Proof structure validation (no secret leakage)
- Threshold Sharing Tests (TestThresholdSharing, TestPedersenVSS)
Basic Shamir sharing and reconstruction
Feldman VSS verification
Tampered share detection
Various threshold configurations (2-of-3, 3-of-5)
Pedersen VSS with blinding factors
- DKG Tests (TestDKLS23_DKG)
2-of-3 distributed key generation
Public key consistency across parties
Correct public key computation
Session ID validation
- Presigning Tests (TestDKLS23_Presign)
Valid presignature generation
Consistent r values across participants
Session ID requirements
- Signing Tests (TestDKLS23_Sign)
Signature share generation
Standard ECDSA verification
Wrong message detection
Invalid signature share detection
- End-to-End Tests (TestDKLS23_Complete)
Complete 2-of-3 signing flow
Different participant combinations
Standard ECDSA format output
DER encoding validation
Multiple messages with same keys
- Security Tests (TestMaliciousParties)
Invalid share detection during DKG
Commitment mismatch detection
Malicious party identification
Running the Tests¶
Run all threshold tests with pytest:
pytest charm/test/schemes/threshold_test.py -v
Run specific test class:
pytest charm/test/schemes/threshold_test.py::TestDKLS23_Complete -v
Run with coverage:
pytest charm/test/schemes/threshold_test.py --cov=charm.schemes.threshold --cov-report=html
Key Test Scenarios¶
Complete Signing Flow:
def test_complete_2_of_3_signing(self):
dkls = DKLS23(self.group, threshold=2, num_parties=3)
g = self.group.random(G)
# Step 1: Distributed Key Generation
key_shares, public_key = dkls.distributed_keygen(g)
# Step 2: Generate presignatures
presignatures = dkls.presign([1, 2], key_shares, g)
# Step 3: Sign a message
message = b"Hello, threshold ECDSA!"
signature = dkls.sign([1, 2], presignatures, key_shares, message, g)
# Step 4: Verify signature
assert dkls.verify(public_key, signature, message, g)
Curve Agnosticism:
def test_curve_agnostic_prime256v1(self):
from charm.toolbox.eccurve import prime256v1
group = ECGroup(prime256v1)
dkls = DKLS23(group, threshold=2, num_parties=3)
# Protocol works with P-256 curve
Malicious Party Detection:
def test_dkg_invalid_share_detected(self):
# Tamper with a share during DKG
tampered_share = original_share + one
# Victim party detects the invalid share
key_share, complaint = dkg.keygen_round3(victim_id, state, received, msgs)
assert key_share is None # Verification failed
assert complaint is not None # Complaint generated
API Reference¶
Tests for DKLS23 Threshold ECDSA implementation.
Run with: pytest charm/test/schemes/threshold_test.py -v
This module tests: - SimpleOT: Base Oblivious Transfer protocol - OTExtension: IKNP-style OT extension - MtA/MtAwc: Multiplicative-to-Additive conversion - ThresholdSharing/PedersenVSS: Threshold secret sharing - DKLS23_DKG: Distributed Key Generation - DKLS23_Presign: Presigning protocol - DKLS23_Sign: Signing protocol - DKLS23: Complete threshold ECDSA protocol
- class threshold_test.TestCurveAgnostic(methodName='runTest')[source]¶
Bases:
TestCaseTests for curve agnosticism (MEDIUM-11)
- class threshold_test.TestDKLS23_Complete(methodName='runTest')[source]¶
Bases:
TestCaseEnd-to-end tests for complete DKLS23 protocol
- class threshold_test.TestDKLS23_DKG(methodName='runTest')[source]¶
Bases:
TestCaseTests for Distributed Key Generation
- class threshold_test.TestDKLS23_Presign(methodName='runTest')[source]¶
Bases:
TestCaseTests for presigning protocol
- class threshold_test.TestDKLS23_Sign(methodName='runTest')[source]¶
Bases:
TestCaseTests for signing protocol
Test that signature shares are generated correctly
Test that invalid signature shares are detected (MEDIUM-06).
- class threshold_test.TestDPF(methodName='runTest')[source]¶
Bases:
TestCaseTests for Distributed Point Function (GGM-based)
- class threshold_test.TestMPFSS(methodName='runTest')[source]¶
Bases:
TestCaseTests for Multi-Point Function Secret Sharing
- class threshold_test.TestMaliciousParties(methodName='runTest')[source]¶
Bases:
TestCaseTests for adversarial/malicious party scenarios in threshold ECDSA.
These tests verify that the protocol correctly detects and handles various forms of malicious behavior including: - Invalid shares during DKG - Wrong commitments - Commitment mismatches during presigning - Invalid signature shares
- classmethod setUpClass()[source]¶
Hook method for setting up class fixture before running tests in the class.
- test_dkg_insufficient_honest_parties()[source]¶
Test that a party can identify malicious parties when multiple collude.
Run 2-of-3 DKG where 2 parties (party 2 and party 3) send invalid shares to party 1. Verify party 1 can identify both malicious parties.
Test that DKG detects tampered shares during round 3.
Run DKG with 3 parties. In round 2, tamper with party 3’s share to party 1 (add 1 to the share value). Verify that party 1 detects the invalid share in round 3 (returns a complaint).
- test_dkg_wrong_commitment_detected()[source]¶
Test that DKG detects when a party’s commitment doesn’t match their shares.
Run DKG round 1, then modify party 2’s commitment list by changing the first commitment to a random point. Verify share verification fails for party 2’s shares.
- test_mta_receiver_learns_only_chosen_message()[source]¶
Test MtA security property: receiver’s beta depends only on chosen values.
Run MtA protocol and verify that the receiver’s beta calculation depends only on the specific input values used, not any other information. This tests the basic security property of the MtA protocol.
- test_presign_commitment_mismatch_detected()[source]¶
Test that presigning detects when Gamma_i doesn’t match the commitment.
Run presign round 1 with 3 parties. In round 2 messages, replace party 2’s Gamma_i with a different value that doesn’t match the commitment. Verify round 3 raises ValueError about commitment verification.
Note: This test validates the commitment verification logic in the presigning protocol. The test directly verifies commitment checking without going through the full MtA completion (which has a separate API change).
Test that tampering with signature shares produces invalid signatures.
Use simulated presignatures to test that modifying a party’s signature share (s_i) causes the aggregated signature to fail ECDSA verification. This validates that malicious tampering with signature shares is detectable.
- class threshold_test.TestMtA(methodName='runTest')[source]¶
Bases:
TestCaseTests for Multiplicative-to-Additive conversion
- class threshold_test.TestMtAwc(methodName='runTest')[source]¶
Bases:
TestCaseTests for MtA with correctness check
- class threshold_test.TestOTExtension(methodName='runTest')[source]¶
Bases:
TestCaseTests for IKNP-style OT Extension
- class threshold_test.TestPedersenVSS(methodName='runTest')[source]¶
Bases:
TestCaseTests for Pedersen VSS (information-theoretically hiding)
- class threshold_test.TestSilentOT(methodName='runTest')[source]¶
Bases:
TestCaseTests for Silent OT Extension (PCG-based)
- class threshold_test.TestSimpleOT(methodName='runTest')[source]¶
Bases:
TestCaseTests for base Oblivious Transfer (Chou-Orlandi style)
- class threshold_test.TestThresholdSharing(methodName='runTest')[source]¶
Bases:
TestCaseTests for threshold secret sharing (Shamir-style)
- test_basic_sharing_and_reconstruction()[source]¶
Test basic 2-of-3 secret sharing and reconstruction
Test that Feldman VSS detects tampered shares
- test_feldman_vss_verification()[source]¶
Test Feldman VSS verification - shares should verify against commitments
Test that reconstruction fails with insufficient shares