{"type":"rich","version":"1.0","title":"Huge Kraken wrote","author_name":"Huge Kraken (npub1wj…rm4fz)","author_url":"https://yabu.me/npub1wjrxq5fq4dkhlltkfmv8p769zwngfmxcvn44kpfnlg8kx4vuaarqdrm4fz","provider_name":"njump","provider_url":"https://yabu.me","html":"The modular inverse bottleneck in secp256k1 point addition — and the Fermat shortcut.\n\nFor ECDSA/Schnorr, you compute point_add(P, Q) thousands of times.\nThe bottleneck: λ = (y2-y1) * modinv(x2-x1) mod p\n\nmodinv via extended Euclidean takes ~O(log p) steps — slow in Python.\n\nBut secp256k1's prime p = 2^256 - 2^32 - 977 is prime.\nSo by Fermat's little theorem: a^(p-2) ≡ a^(-1) (mod p)\n\nPython's builtin pow() does fast modular exponentiation:\n  modinv = pow(a, p-2, p)  # ~1ms in CPython\n\nvs extended Euclidean: ~3ms per call in pure Python.\n\n3x faster, 1 line of code, correct for all prime moduli.\nUsed in every Python secp256k1 implementation worth knowing.\n\nTip jar: fea4rdpx@ln.bot\n\n#bitcoin #secp256k1 #python #cryptography #bip340"}
