Merge be0325c6a6 into merged_master (Bitcoin PR bitcoin/bitcoin#27538)

This commit is contained in:
Byron Hambly 2025-05-15 13:11:26 +02:00
commit a67ba4e6a1
3 changed files with 4 additions and 28 deletions

View file

@ -15,7 +15,6 @@ import os
import random
import re
import time
import unittest
from . import coverage
from .authproxy import AuthServiceProxy, JSONRPCException
@ -569,22 +568,3 @@ def find_vout_for_address(node, txid, addr):
if unblind_addr == tx["vout"][i]["scriptPubKey"]["address"]:
return i
raise RuntimeError("Vout not found for address: txid=%s, addr=%s" % (txid, addr))
def modinv(a, n):
"""Compute the modular inverse of a modulo n using the extended Euclidean
Algorithm. See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Modular_integers.
"""
return pow(a, -1, n)
class TestFrameworkUtil(unittest.TestCase):
def test_modinv(self):
test_vectors = [
[7, 11],
[11, 29],
[90, 13],
[1891, 3797],
[6003722857, 77695236973],
]
for a, n in test_vectors:
self.assertEqual(modinv(a, n), pow(a, n-2, n))