Skip to content

Add externally verifiable test vectors for Electrum v1/v2 mnemonic derivation - #3

Draft
edtubbs with Copilot wants to merge 15 commits into
0.1.5-dev-electrum-seedfrom
copilot/validate-electrum-mnemonic-changes
Draft

Add externally verifiable test vectors for Electrum v1/v2 mnemonic derivation#3
edtubbs with Copilot wants to merge 15 commits into
0.1.5-dev-electrum-seedfrom
copilot/validate-electrum-mnemonic-changes

Conversation

Copilot AI commented Feb 5, 2026

Copy link
Copy Markdown

Adds comprehensive test vectors with independent verification for Electrum v1 and v2 mnemonic-to-key derivation. Previous implementation lacked external validation.

Test Vectors Added

bip39_tests.c:

  • Electrum v2 (PBKDF2-HMAC-SHA512): versions 0x01 and 0x100, with/without passphrases
  • Electrum v1 (SHA256 stretching): 12-word mnemonics, fallback paths
  • All vectors include Python verification commands using standard library

key_tests.c:

  • Electrum v1 custom derivation test using electrum_v1_derive_privkey32()
  • Tests multiple keypaths: 0/0 (receiving), 0/1 (change), 5/0
  • Previously incorrectly tested BIP32 HD derivation instead of Electrum v1's custom algorithm

Independent Verification

Python script (test/verify_electrum_v1_vectors.py):

from ecdsa import SECP256k1, SigningKey
from hashlib import sha256

# Electrum v1: privkey = (master_secret + SHA256(n:for_change:mpk)) mod order
sk = SigningKey.from_string(master_secret, curve=SECP256k1)
mpk = sk.get_verifying_key().to_string().hex()
prefix_str = f"{n}:{for_change}:{mpk}"
offset = sha256(prefix_str.encode()).digest()

Uses ecdsa library (official Electrum dependency) to independently verify all test vectors.

Key Fixes

  • Electrum v1 test: Changed from dogecoin_hdnode_from_seed() (BIP32) to electrum_v1_derive_privkey32() (custom derivation)
  • Keypath display: Fixed CLI to show electrum_v1:n/for_change format correctly (was reversed)
  • Cross-compilation: Replaced strtok with strtok_r in bip39.c, spv.c, utils.c (fixes aarch64 linker errors)
  • Test registration: Added test_electrum_v1_mnemonic_to_master_key() to unittester.c

Documentation

  • doc/electrum_v1_keypath.md: Keypath format reference (electrum_v1:n/for_change)
  • doc/electrum_v1_vs_bip32.md: Clarifies Electrum v1 uses custom derivation, not BIP32/BIP84 paths
  • Enhanced function comments with verification methods and algorithm references

Verification Methods

All test vectors can be independently verified:

  • Electrum v2: python3 -c "import hashlib; print(hashlib.pbkdf2_hmac('sha512', b'mnemonic', b'electrum', 2048).hex())"
  • Electrum v1: python3 test/verify_electrum_v1_vectors.py
  • CLI: ./such -c mnemonic_to_key -n "alpha bravo" -l matches test expectations

Test vectors reference NIST standards (PBKDF2: RFC 2898, SHA-256: FIPS 180-4) and official Electrum implementation.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 5, 2026 22:01
… and key_tests

Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Copilot AI changed the title [WIP] Validate Electrum mnemonic to key and address generation changes Add Electrum v1/v2 mnemonic test vectors with references Feb 5, 2026
Copilot AI requested a review from edtubbs February 5, 2026 22:05
Copilot AI and others added 2 commits February 5, 2026 22:11
…ernal references

Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Copilot AI changed the title Add Electrum v1/v2 mnemonic test vectors with references Add externally verifiable test vectors for Electrum v1/v2 mnemonics Feb 5, 2026
@edtubbs
edtubbs force-pushed the 0.1.5-dev-electrum-seed branch from faf608c to 1979133 Compare February 5, 2026 22:17
…ix expected value

Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Copilot AI changed the title Add externally verifiable test vectors for Electrum v1/v2 mnemonics Register test_electrum_v1_mnemonic_to_master_key and fix expected seed value Feb 5, 2026
@edtubbs
edtubbs force-pushed the 0.1.5-dev-electrum-seed branch 2 times, most recently from 1cdd749 to 2fa6243 Compare February 5, 2026 22:29
…tion

Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Copilot AI changed the title Register test_electrum_v1_mnemonic_to_master_key and fix expected seed value Validate Electrum test vectors against reference implementations and fix test registration Feb 5, 2026
@edtubbs
edtubbs force-pushed the 0.1.5-dev-electrum-seed branch from 2fa6243 to bc8b234 Compare February 5, 2026 23:46
Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Copilot AI changed the title Validate Electrum test vectors against reference implementations and fix test registration Squash 7 commits into single commit for Electrum test vectors Feb 5, 2026
Copilot AI changed the title Replace strtok with strtok_r to fix aarch64 linker error Add Electrum mnemonic test vectors and fix strtok linker errors Feb 9, 2026
Copilot AI changed the title Add Electrum mnemonic test vectors and fix strtok linker errors Add externally verifiable Electrum v1/v2 test vectors and fix strtok linker errors Feb 12, 2026
Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Copilot AI changed the title Add externally verifiable Electrum v1/v2 test vectors and fix strtok linker errors Add Electrum v1/v2 mnemonic test vectors with external verification Feb 12, 2026
Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Copilot AI changed the title Add Electrum v1/v2 mnemonic test vectors with external verification Add externally-verifiable Electrum v1/v2 test vectors and fix v1 derivation Feb 12, 2026
Co-authored-by: edtubbs <84785904+edtubbs@users.noreply.github.com>
Copilot AI changed the title Add externally-verifiable Electrum v1/v2 test vectors and fix v1 derivation Add validated test vectors for Electrum v1/v2 mnemonic derivation Feb 12, 2026
Copilot AI changed the title Add validated test vectors for Electrum v1/v2 mnemonic derivation Add externally-verifiable Electrum v1/v2 mnemonic test vectors and fix v1 derivation path Feb 12, 2026
Copilot AI changed the title Add externally-verifiable Electrum v1/v2 mnemonic test vectors and fix v1 derivation path Add independently verified Electrum v1/v2 mnemonic test vectors and fix v1 derivation Feb 12, 2026
Copilot AI changed the title Add independently verified Electrum v1/v2 mnemonic test vectors and fix v1 derivation Add externally verifiable test vectors for Electrum v1/v2 mnemonic derivation Feb 12, 2026
@edtubbs
edtubbs force-pushed the 0.1.5-dev-electrum-seed branch 3 times, most recently from 9f23b1c to bcd590a Compare February 17, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants