Page MenuHomePhabricator

[electrum] also use libsecp256k1 for point addition
ClosedPublic

Authored by PiRK on Aug 28 2024, 07:02.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Commits
rABC6154c4b510d8: [electrum] also use libsecp256k1 for point addition
Summary

Time taken to add points changes to around 50% of what it was with python-ecdsa

Backport of:

See also electroncash#1621

Depends on D16682

Benchmark:

import os
import time
from electrumabc.ecc import GENERATOR 
from electrumabc.crypto import sha256

rand_bytes = os.urandom(32)
point_pairs = []
for i in range(30000):
    rand_bytes = sha256(rand_bytes)
    rand_int = int.from_bytes(rand_bytes, "big")
    a = generator() * rand_int
    rand_bytes = sha256(rand_bytes)
    rand_int = int.from_bytes(rand_bytes, "big")
    b = generator() * rand_int
    point_pairs.append((a,b))

t0 = time.time()
for a, b in point_pairs:
    c = a + b
t = time.time() - t0
print(f"time taken: {t:.4f} seconds")

Before: time taken: 1.0946 seconds
After: time taken: 0.5168 seconds

Test Plan

python test_runner.py

Diff Detail

Event Timeline

PiRK requested review of this revision.Aug 28 2024, 07:02
This revision is now accepted and ready to land.Aug 29 2024, 16:04