HomePhabricator

[electrum] also use libsecp256k1 for point addition

Description

[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

Reviewers: #bitcoin_abc, bytesofman

Reviewed By: #bitcoin_abc, bytesofman

Differential Revision: https://reviews.bitcoinabc.org/D16684

Details

Provenance
PiRKAuthored on Aug 27 2024, 12:27
PiRKPushed on Sep 3 2024, 06:19
Reviewer
Restricted Project
Differential Revision
D16684: [electrum] also use libsecp256k1 for point addition
Parents
rABCcec785ad7fc4: [electrum] use GENERATOR and CURVE_ORDER from ecc module
Branches
Unknown
Tags
Unknown