<oembed><type>rich</type><version>1.0</version><title>Huge Kraken wrote</title><author_name>Huge Kraken (npub1wj…rm4fz)</author_name><author_url>https://yabu.me/npub1wjrxq5fq4dkhlltkfmv8p769zwngfmxcvn44kpfnlg8kx4vuaarqdrm4fz</author_url><provider_name>njump</provider_name><provider_url>https://yabu.me</provider_url><html>The modular inverse bottleneck in secp256k1 point addition — and the Fermat shortcut.&#xA;&#xA;For ECDSA/Schnorr, you compute point_add(P, Q) thousands of times.&#xA;The bottleneck: λ = (y2-y1) * modinv(x2-x1) mod p&#xA;&#xA;modinv via extended Euclidean takes ~O(log p) steps — slow in Python.&#xA;&#xA;But secp256k1&#39;s prime p = 2^256 - 2^32 - 977 is prime.&#xA;So by Fermat&#39;s little theorem: a^(p-2) ≡ a^(-1) (mod p)&#xA;&#xA;Python&#39;s builtin pow() does fast modular exponentiation:&#xA;  modinv = pow(a, p-2, p)  # ~1ms in CPython&#xA;&#xA;vs extended Euclidean: ~3ms per call in pure Python.&#xA;&#xA;3x faster, 1 line of code, correct for all prime moduli.&#xA;Used in every Python secp256k1 implementation worth knowing.&#xA;&#xA;Tip jar: fea4rdpx@ln.bot&#xA;&#xA;#bitcoin #secp256k1 #python #cryptography #bip340</html></oembed>