Migrate all 92 Python files in qa/ from Python 2 to Python 3: - Update shebangs from python2 to python3 - Replace print statements with print() calls - Fix imports (http.client, urllib.parse, queue, io, functools) - Convert xrange→range, 0L→0, long→int, cmp→key functions - Fix except/as syntax, bytes/str handling, integer division - Use relative imports in test_framework/ package Add qa/run-tests.sh: multi-stage test runner (1183 lines) - Stage 1: Build/binary verification - Stage 2: Security hardening (PIE, NX, RELRO, canary, FORTIFY) - Stage 3-4: Boost/Google test binaries - Stage 5: Library tests (secp256k1, univalue) - Stage 6: RandomX validation (live chain mining + block checks) - Stage 7: RPC integration (skipped: regtest mining incompatible) - Stage 8: Source code invariant checks - Stage 8b: DragonX-specific source checks (11 tests) - Flags: --chain=dragonx, --live-dragonx, --save-release, --quick - Timestamped reports with release archiving to qa/release-reports/ Add qa/clean-test-reports.sh for housekeeping (--keep=N, --dry-run) Fix test build infrastructure: - src/Makefile.gtest.include: fix zcash_gtest→hush_gtest refs, remove 17 stale source files, add LIBZCASH/LIBHUSH/LIBRANDOMX - src/Makefile.test.include: remove stale sources, deduplicate LDADD/CXXFLAGS, add missing libraries - src/gtest/test_checkblock.cpp: add height param to ContextualCheckBlock - src/test/test_bitcoin.cpp: remove JoinSplitTestingSetup (dead code) Add qa/test-reports/ to .gitignore for transient output.
99 lines
2.0 KiB
Python
99 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) 2016-2024 The Hush developers
|
|
# Distributed under the GPLv3 software license, see the accompanying
|
|
# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
|
# This file is from python-bitcoinlib.
|
|
|
|
"""Bignum routines"""
|
|
|
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
|
|
import struct
|
|
|
|
|
|
# generic big endian MPI format
|
|
|
|
def bn_bytes(v, have_ext=False):
|
|
ext = 0
|
|
if have_ext:
|
|
ext = 1
|
|
return ((v.bit_length()+7)//8) + ext
|
|
|
|
def bn2bin(v):
|
|
s = bytearray()
|
|
i = bn_bytes(v)
|
|
while i > 0:
|
|
s.append((v >> ((i-1) * 8)) & 0xff)
|
|
i -= 1
|
|
return s
|
|
|
|
def bin2bn(s):
|
|
l = 0
|
|
for ch in s:
|
|
l = (l << 8) | ch
|
|
return l
|
|
|
|
def bn2mpi(v):
|
|
have_ext = False
|
|
if v.bit_length() > 0:
|
|
have_ext = (v.bit_length() & 0x07) == 0
|
|
|
|
neg = False
|
|
if v < 0:
|
|
neg = True
|
|
v = -v
|
|
|
|
s = struct.pack(b">I", bn_bytes(v, have_ext))
|
|
ext = bytearray()
|
|
if have_ext:
|
|
ext.append(0)
|
|
v_bin = bn2bin(v)
|
|
if neg:
|
|
if have_ext:
|
|
ext[0] |= 0x80
|
|
else:
|
|
v_bin[0] |= 0x80
|
|
return s + ext + v_bin
|
|
|
|
def mpi2bn(s):
|
|
if len(s) < 4:
|
|
return None
|
|
s_size = bytes(s[:4])
|
|
v_len = struct.unpack(b">I", s_size)[0]
|
|
if len(s) != (v_len + 4):
|
|
return None
|
|
if v_len == 0:
|
|
return 0
|
|
|
|
v_str = bytearray(s[4:])
|
|
neg = False
|
|
i = v_str[0]
|
|
if i & 0x80:
|
|
neg = True
|
|
i &= ~0x80
|
|
v_str[0] = i
|
|
|
|
v = bin2bn(v_str)
|
|
|
|
if neg:
|
|
return -v
|
|
return v
|
|
|
|
# bitcoin-specific little endian format, with implicit size
|
|
def mpi2vch(s):
|
|
r = s[4:] # strip size
|
|
r = r[::-1] # reverse string, converting BE->LE
|
|
return r
|
|
|
|
def bn2vch(v):
|
|
return bytes(mpi2vch(bn2mpi(v)))
|
|
|
|
def vch2mpi(s):
|
|
r = struct.pack(b">I", len(s)) # size
|
|
r += s[::-1] # reverse string, converting LE->BE
|
|
return r
|
|
|
|
def vch2bn(s):
|
|
return mpi2bn(vch2mpi(s))
|
|
|