Skip to content

Commit 41db3e8

Browse files
authored
multi: fix a number of unrelated issues (#175)
* Fix a number of unrelated issues. * Don't send a traceback to the app window. * Fix formatting of tracebacks in logs. * Fix test.
1 parent 269819d commit 41db3e8

File tree

7 files changed

+53
-81
lines changed

7 files changed

+53
-81
lines changed

decred/decred/crypto/secp256k1/curve.py

Lines changed: 41 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -199,29 +199,48 @@ def generateKey():
199199
return PrivateKey(curve, b, x, y)
200200

201201

202-
class KoblitzCurve:
203-
"""
204-
KoblitzCurve provides a secp256k1 Koblitz curve implementation.
205-
"""
202+
def fromHex(hx):
203+
return int(hx, 16)
206204

207-
def __init__(
208-
self, P, N, B, Gx, Gy, BitSize, H, q, byteSize, lambda_, beta, a1, b1, a2, b2
209-
):
210-
self.P = P
211-
self.N = N
212-
self.B = B
213-
self.Gx = Gx
214-
self.Gy = Gy
215-
self.BitSize = BitSize
216-
self.H = H
217-
self.q = q
218-
self.byteSize = byteSize
219-
self.lambda_ = lambda_
220-
self.beta = beta
221-
self.a1 = a1
222-
self.b1 = b1
223-
self.a2 = a2
224-
self.b2 = b2
205+
206+
class Curve:
207+
def __init__(self):
208+
bitSize = 256
209+
p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F")
210+
self.P = p
211+
self.N = fromHex(
212+
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"
213+
)
214+
self.B = fromHex(
215+
"0000000000000000000000000000000000000000000000000000000000000007"
216+
)
217+
self.Gx = fromHex(
218+
"79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
219+
)
220+
self.Gy = fromHex(
221+
"483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"
222+
)
223+
self.BitSize = bitSize
224+
self.H = 1
225+
self.q = (p + 1) // 4
226+
# Provided for convenience since this gets computed repeatedly.
227+
self.byteSize = bitSize / 8
228+
# Next 6 constants are from Hal Finney's bitcointalk.org post:
229+
# https://bitcointalk.org/index.php?topic=3238.msg45565#msg45565
230+
# May he rest in peace.
231+
#
232+
# They have also been independently derived from the code in the
233+
# EndomorphismVectors function in gensecp256k1.go.
234+
self.lambda_ = fromHex(
235+
"5363AD4CC05C30E0A5261C028812645A122E22EA20816678DF02967C1B23BD72"
236+
)
237+
self.beta = FieldVal.fromHex(
238+
"7AE96A2B657C07106E64479EAC3434E99CF0497512F58995C1396C28719501EE"
239+
)
240+
self.a1 = fromHex("3086D221A7D46BCDE86C90E49284EB15")
241+
self.b1 = fromHex("-E4437ED6010E88286F547FA90ABFE4C3")
242+
self.a2 = fromHex("114CA50F7A8E2F3F657C1108D9D44CFD8")
243+
self.b2 = fromHex("3086D221A7D46BCDE86C90E49284EB15")
225244

226245
def scalarBaseMult(self, k):
227246
"""
@@ -983,57 +1002,6 @@ def fieldJacobianToBigAffine(self, x, y, z):
9831002
# Convert the field values for the now affine point to integers.
9841003
return ByteArray(x.bytes()).int(), ByteArray(y.bytes()).int()
9851004

986-
987-
def fromHex(hx):
988-
"""
989-
fromHex converts the passed hex string into an integer. This is only
990-
meant for the hard-coded constants so errors in the source code can be
991-
detected. It will (and must) only be called for initialization purposes.
992-
"""
993-
return int(hx, 16)
994-
995-
996-
class Curve(KoblitzCurve):
997-
def __init__(self):
998-
bitSize = 256
999-
p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F")
1000-
super().__init__(
1001-
P=p,
1002-
N=fromHex(
1003-
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"
1004-
),
1005-
B=fromHex(
1006-
"0000000000000000000000000000000000000000000000000000000000000007"
1007-
),
1008-
Gx=fromHex(
1009-
"79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
1010-
),
1011-
Gy=fromHex(
1012-
"483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"
1013-
),
1014-
BitSize=bitSize,
1015-
H=1,
1016-
q=(p + 1) // 4,
1017-
# Provided for convenience since this gets computed repeatedly.
1018-
byteSize=bitSize / 8,
1019-
# Next 6 constants are from Hal Finney's bitcointalk.org post:
1020-
# https://bitcointalk.org/index.php?topic=3238.msg45565#msg45565
1021-
# May he rest in peace.
1022-
#
1023-
# They have also been independently derived from the code in the
1024-
# EndomorphismVectors function in gensecp256k1.go.
1025-
lambda_=fromHex(
1026-
"5363AD4CC05C30E0A5261C028812645A122E22EA20816678DF02967C1B23BD72"
1027-
),
1028-
beta=FieldVal.fromHex(
1029-
"7AE96A2B657C07106E64479EAC3434E99CF0497512F58995C1396C28719501EE"
1030-
),
1031-
a1=fromHex("3086D221A7D46BCDE86C90E49284EB15"),
1032-
b1=fromHex("-E4437ED6010E88286F547FA90ABFE4C3"),
1033-
a2=fromHex("114CA50F7A8E2F3F657C1108D9D44CFD8"),
1034-
b2=fromHex("3086D221A7D46BCDE86C90E49284EB15"),
1035-
)
1036-
10371005
def bigAffineToField(self, x, y):
10381006
"""
10391007
bigAffineToField takes an affine point (x, y) as integers

decred/decred/dcr/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ def addressSignal(self, addr, txid):
18331833
tx = self.blockchain.tx(txid)
18341834
self.addTxid(addr, tx.txid())
18351835

1836-
matches = False
1836+
matches = 0
18371837
# scan the inputs for any spends.
18381838
for txin in tx.txIn:
18391839
op = txin.previousOutPoint

decred/decred/dcr/dcrdata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def __init__(self, db, netParams, datapath, skipConnect=False):
429429
self.heightMap = db.child("height", datatypes=("INTEGER", "BLOB"))
430430
self.headerDB = db.child("header", blobber=msgblock.BlockHeader)
431431
self.txBlockMap = db.child("blocklink")
432-
self.tipHeight = None
432+
self.tipHeight = -1
433433
self.subsidyCache = txscript.SubsidyCache(netParams)
434434
self.addrSubscribers = {}
435435
self.blockSubscribers = []

decred/decred/dcr/wire/msgtx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def s(thing, description, nIndent=0):
458458
s("version", self.version)
459459
for i, txIn in enumerate(self.txIn):
460460
s("txIn {}".format(i), "")
461-
s("previousOutPoint".format(i), "", 1)
461+
s("previousOutPoint", "", 1)
462462
s("txid", txIn.previousOutPoint.txid(), 2)
463463
s("idx", txIn.previousOutPoint.index, 2)
464464
s("tree", txIn.previousOutPoint.tree, 2)

decred/decred/util/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
def formatTraceback(err):
2222
"""
23-
Format a traceback for an error.
23+
Format a traceback for an error so that it can go into logs.
2424
2525
Args:
2626
err (BaseException): The error the traceback is extracted from.
@@ -29,7 +29,7 @@ def formatTraceback(err):
2929
str: The __str__() of the error, followed by the standard formatting
3030
of the traceback on the following lines.
3131
"""
32-
return f"{err}\nTraceback:\n{traceback.print_tb(err.__traceback__)}"
32+
return "".join(traceback.format_exception(None, err, err.__traceback__))
3333

3434

3535
def mkdir(path):
@@ -117,7 +117,7 @@ def prepareLogging(filepath=None, logLvl=logging.INFO, lvlMap=None):
117117
maxBytes=5 * 1024 * 1024,
118118
backupCount=2,
119119
encoding=None,
120-
delay=0,
120+
delay=False,
121121
)
122122
fileHandler.setFormatter(log_formatter)
123123
LogSettings.root.addHandler(fileHandler)

decred/tests/unit/util/test_helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
def test_formatTraceback():
1919
# Cannot actually raise an error because pytest intercepts it.
20-
assert helpers.formatTraceback(DecredError("errmsg")) == "errmsg\nTraceback:\nNone"
20+
assert (
21+
helpers.formatTraceback(DecredError("errmsg")) == "decred.DecredError: errmsg\n"
22+
)
2123

2224

2325
def test_mkdir(tmp_path):

tinywallet/tinywallet/screens.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,9 @@ def stacked(self):
11081108
try:
11091109
app.dcrdata.connect()
11101110
except DecredError as e:
1111-
app.appWindow.showError(f"failed to connect to dcrdata: {e}")
1111+
msg = "failed to connect to dcrdata"
1112+
app.appWindow.showError(msg)
1113+
log.warning(f"{msg}\n{formatTraceback(e)}")
11121114
return
11131115

11141116
# Check for a dcrd configuration. If found, request the cryptoKey so the

0 commit comments

Comments
 (0)