Skip to content

Commit

Permalink
chore: bump black to 22.3
Browse files Browse the repository at this point in the history
changes:
* exponent operator ** now allows no spaces around itself: psf/black#538
* optional unicode marker u"" is no longer allowed

[no changelog]
  • Loading branch information
matejcik committed Jun 29, 2022
1 parent 01257ab commit 8c3d3c6
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 81 deletions.
2 changes: 1 addition & 1 deletion common/tools/maxfee.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def round_sats(sats, precision=1):

def compute_maxfee(maxcost, price, txsize):
coins_per_tx = maxcost / price
sats_per_tx = coins_per_tx * 10 ** 8
sats_per_tx = coins_per_tx * 10**8
tx_per_kb = 1024.0 / txsize
sats_per_kb = sats_per_tx * tx_per_kb
return int(sats_per_kb)
Expand Down
8 changes: 4 additions & 4 deletions core/src/apps/common/cbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
def _header(typ: int, l: int) -> bytes:
if l < 24:
return struct.pack(">B", typ + l)
elif l < 2 ** 8:
elif l < 2**8:
return struct.pack(">BB", typ + 24, l)
elif l < 2 ** 16:
elif l < 2**16:
return struct.pack(">BH", typ + 25, l)
elif l < 2 ** 32:
elif l < 2**32:
return struct.pack(">BI", typ + 26, l)
elif l < 2 ** 64:
elif l < 2**64:
return struct.pack(">BQ", typ + 27, l)
else:
raise NotImplementedError # Length not supported
Expand Down
2 changes: 1 addition & 1 deletion core/src/trezor/crypto/rlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _byte_size(x: int) -> int:
if x < 0:
raise ValueError # only unsigned ints are supported
for exp in range(64):
if x < 0x100 ** exp:
if x < 0x100**exp:
return exp

raise ValueError # int is too large
Expand Down
54 changes: 27 additions & 27 deletions crypto/tests/test_bignum.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def int_to_bignum(number, limbs_number=limbs_number):

bn = (limbs_number * limb_type)()
for i in range(limbs_number):
bn[i] = number % 2 ** bits_per_limb
number //= 2 ** bits_per_limb
bn[i] = number % 2**bits_per_limb
number //= 2**bits_per_limb

return bn

Expand All @@ -89,7 +89,7 @@ def bignum_to_int(bignum, limbs_number=limbs_number):
number = 0

for i in reversed(range(limbs_number)):
number *= 2 ** bits_per_limb
number *= 2**bits_per_limb
number += bignum[i]

return number
Expand All @@ -109,7 +109,7 @@ def integer_to_raw_number(number, endianess):

def bignum_is_normalised(bignum):
for limb in bignum:
if limb > 2 ** bits_per_limb:
if limb > 2**bits_per_limb:
return False
return True

Expand All @@ -127,20 +127,20 @@ def rand_int_normalized(self):
return self.randrange(0, 2 ** (limbs_number * bits_per_limb))

def rand_int_256(self):
return self.randrange(0, 2 ** 256)
return self.randrange(0, 2**256)

def rand_int_reduced(self, p):
return self.randrange(0, 2 * p)

def rand_int_bitsize(self, bitsize):
return self.randrange(0, 2 ** bitsize)
return self.randrange(0, 2**bitsize)

def rand_bit_index(self):
return self.randrange(0, limbs_number * bits_per_limb)

def rand_bignum(self, limbs_number=limbs_number):
return (limb_type * limbs_number)(
*[self.randrange(0, 256 ** 4) for _ in range(limbs_number)]
*[self.randrange(0, 256**4) for _ in range(limbs_number)]
)


Expand Down Expand Up @@ -446,13 +446,13 @@ def assert_bn_sqrt(x_old, prime):

assert bignum_is_normalised(bn_x)
assert number_is_fully_reduced(x_new, prime)
assert x_new ** 2 % prime == x_old % prime
assert x_new**2 % prime == x_old % prime


def assert_inverse_mod_power_two(x, m):
return_value = lib.inverse_mod_power_two(c_uint32(x), c_uint32(m))

assert return_value * x % 2 ** m == 1
assert return_value * x % 2**m == 1


def assert_bn_divide_base(x_old, prime):
Expand All @@ -467,7 +467,7 @@ def assert_bn_divide_base(x_old, prime):
assert implication(
number_is_partly_reduced(x_old, prime), number_is_partly_reduced(x_new, prime)
)
assert x_new * 2 ** bits_per_limb % prime == x_old % prime
assert x_new * 2**bits_per_limb % prime == x_old % prime


def assert_bn_inverse(x_old, prime):
Expand Down Expand Up @@ -610,7 +610,7 @@ def assert_bn_divmod10(x_old):
def assert_bn_format(x, prefix, suffix, decimals, exponent, trailing):
def format(amount, prefix, suffix, decimals, exponent, trailing):
if exponent >= 0:
amount *= 10 ** exponent
amount *= 10**exponent
else:
amount //= 10 ** (-exponent)

Expand Down Expand Up @@ -684,17 +684,17 @@ def test_bn_bitcount_1(r):


def test_bn_bitcount_2(bignum_bit_index):
assert_bn_bitcount(2 ** bignum_bit_index - 1)
assert_bn_bitcount(2 ** bignum_bit_index)
assert_bn_bitcount(2**bignum_bit_index - 1)
assert_bn_bitcount(2**bignum_bit_index)


def test_bn_digitcount_1(r):
assert_bn_digitcount(r.rand_int_normalized())


def test_bn_digitcount_2(bignum_decimal_digit_index):
assert_bn_digitcount(10 ** bignum_decimal_digit_index - 1)
assert_bn_digitcount(10 ** bignum_decimal_digit_index)
assert_bn_digitcount(10**bignum_decimal_digit_index - 1)
assert_bn_digitcount(10**bignum_decimal_digit_index)


def test_bn_zero():
Expand All @@ -711,7 +711,7 @@ def test_bn_is_zero_1():


def test_bn_is_zero_2(bignum_bit_index):
assert_bn_is_zero(2 ** bignum_bit_index)
assert_bn_is_zero(2**bignum_bit_index)


def test_bn_is_one_1():
Expand All @@ -720,7 +720,7 @@ def test_bn_is_one_1():


def test_bn_is_one_2(bignum_bit_index):
assert_bn_is_one(2 ** bignum_bit_index)
assert_bn_is_one(2**bignum_bit_index)


def test_bn_is_less_1(r):
Expand All @@ -734,7 +734,7 @@ def test_bn_is_less_1(r):
def test_bn_is_less_2(r):
a = r.rand_int_normalized()
i = r.rand_bit_index()
b = a ^ 2 ** i
b = a ^ 2**i
assert_bn_is_less(a, b)


Expand Down Expand Up @@ -829,8 +829,8 @@ def test_bn_mod_2(r, prime):


def test_bn_multiply_long(r, prime):
x = r.randrange(floor(sqrt(2 ** 519)))
k = r.randrange(floor(sqrt(2 ** 519)))
x = r.randrange(floor(sqrt(2**519)))
k = r.randrange(floor(sqrt(2**519)))
assert_bn_multiply_long(k, x)


Expand All @@ -841,8 +841,8 @@ def test_bn_multiply_reduce_step(r, prime):


def test_bn_multiply(r, prime):
x = r.randrange(floor(sqrt(2 ** 519)))
k = r.randrange(floor(sqrt(2 ** 519)))
x = r.randrange(floor(sqrt(2**519)))
k = r.randrange(floor(sqrt(2**519)))
assert_bn_multiply(k, x, prime)


Expand Down Expand Up @@ -880,7 +880,7 @@ def is_quadratic_residuum(x, p):

def test_inverse_mod_power_two(r):
m = r.randrange(1, 33)
i = r.randrange(1, 2 ** 29, 2)
i = r.randrange(1, 2**29, 2)
assert_inverse_mod_power_two(i, m)


Expand Down Expand Up @@ -934,29 +934,29 @@ def test_bn_addmod(r, prime):
def test_bn_addi_1(r):
while True:
a = r.rand_int_normalized()
b = r.randrange(2 ** 32 - 2 ** bits_per_limb + 1)
b = r.randrange(2**32 - 2**bits_per_limb + 1)
if a + b < 2 ** (limbs_number * bits_per_limb):
break
assert_bn_addi(a, b)


def test_bn_addi_2():
b = 2 ** 32 - 2 ** bits_per_limb
b = 2**32 - 2**bits_per_limb
a = 2 ** (limbs_number * bits_per_limb) - 1 - b
assert_bn_addi(a, b)


def test_bn_subi_1(r, prime):
while True:
a = r.rand_int_normalized()
b = r.randrange(prime % 2 ** bits_per_limb)
b = r.randrange(prime % 2**bits_per_limb)
if a + prime - b < 2 ** (limbs_number * bits_per_limb):
break
assert_bn_subi(a, b, prime)


def test_bn_subi_2(prime):
b = (prime % 2 ** bits_per_limb) - 1
b = (prime % 2**bits_per_limb) - 1
a = 2 ** (limbs_number * bits_per_limb) - 1 - prime + b
assert_bn_subi(a, b, prime)

Expand Down
6 changes: 3 additions & 3 deletions crypto/tests/test_curves.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_curve_parameters(curve):

def test_point_multiply(curve, r):
p = r.randpoint(curve)
k = r.randrange(0, 2 ** 256)
k = r.randrange(0, 2**256)
kp = k * p
res = POINT(int2bn(0), int2bn(0))
lib.point_multiply(curve.ptr, int2bn(k), to_POINT(p), res)
Expand Down Expand Up @@ -236,8 +236,8 @@ def test_point_to_jacobian(curve, r):
jp = JACOBIAN()
lib.curve_to_jacobian(to_POINT(p), jp, int2bn(curve.p))
jx, jy, jz = from_JACOBIAN(jp)
assert jx % curve.p == (p.x() * jz ** 2) % curve.p
assert jy % curve.p == (p.y() * jz ** 3) % curve.p
assert jx % curve.p == (p.x() * jz**2) % curve.p
assert jy % curve.p == (p.y() * jz**3) % curve.p

q = POINT()
lib.jacobian_to_curve(jp, q, int2bn(curve.p))
Expand Down
41 changes: 29 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typing-extensions = ">=3.7.4"
## style
isort = "<5" # 5 changes lots of stuff that need to be addressed first: https://timothycrosley.github.io/isort/docs/upgrade_guides/5.0.0/
flake8 = ">=3.7.0"
black = ">=20.8b0"
black = ">=22.3"
mako = "^1.0.7"
munch = "^2.3.2"
autoflake = "*"
Expand Down
4 changes: 2 additions & 2 deletions python/src/trezorlib/_ed25519.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@


b = 256
q: int = 2 ** 255 - 19
l: int = 2 ** 252 + 27742317777372353535851937790883648493
q: int = 2**255 - 19
l: int = 2**252 + 27742317777372353535851937790883648493

COORD_MASK = ~(1 + 2 + 4 + (1 << b - 1))
COORD_HIGH_BIT = 1 << b - 2
Expand Down
2 changes: 1 addition & 1 deletion python/src/trezorlib/btc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def make_input(vin: "Vin") -> messages.TxInputType:

def make_bin_output(vout: "Vout") -> messages.TxOutputBinType:
return messages.TxOutputBinType(
amount=int(Decimal(vout["value"]) * (10 ** 8)),
amount=int(Decimal(vout["value"]) * (10**8)),
script_pubkey=bytes.fromhex(vout["scriptPubKey"]["hex"]),
)

Expand Down
8 changes: 4 additions & 4 deletions python/src/trezorlib/protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ def wire_type(self) -> int:

def value_fits(self, value: int) -> bool:
if self.type == "uint32":
return 0 <= value < 2 ** 32
return 0 <= value < 2**32
if self.type == "uint64":
return 0 <= value < 2 ** 64
return 0 <= value < 2**64
if self.type == "sint32":
return -(2 ** 31) <= value < 2 ** 31
return -(2**31) <= value < 2**31
if self.type == "sint64":
return -(2 ** 63) <= value < 2 ** 63
return -(2**63) <= value < 2**63

raise ValueError(f"Cannot check range bounds for {self.type}")

Expand Down
2 changes: 1 addition & 1 deletion python/src/trezorlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def b58decode(v: AnyStr, length: Optional[int] = None) -> bytes:

long_value = 0
for (i, c) in enumerate(str_v[::-1]):
long_value += __b58chars.find(c) * (__b58base ** i)
long_value += __b58chars.find(c) * (__b58base**i)

result = b""
while long_value >= 256:
Expand Down
4 changes: 2 additions & 2 deletions tests/device_tests/bitcoin/test_signmessage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def case(id, *args, altcoin=False):
return pytest.param(*args, id=id, marks=marks)


MESSAGE_NFKD = u"Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
MESSAGE_NFC = u"P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
MESSAGE_NFKD = "Pr\u030ci\u0301s\u030cerne\u030c z\u030clut\u030couc\u030cky\u0301 ku\u030an\u030c u\u0301pe\u030cl d\u030ca\u0301belske\u0301 o\u0301dy za\u0301ker\u030cny\u0301 uc\u030cen\u030c be\u030cz\u030ci\u0301 pode\u0301l zo\u0301ny u\u0301lu\u030a"
MESSAGE_NFC = "P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f"
NFKD_NFC_SIGNATURE = "2046a0b46e81492f82e0412c73701b9740e6462c603575ee2d36c7d7b4c20f0f33763ca8cb3027ea8e1ce5e83fda8b6746fea8f5c82655d78fd419e7c766a5e17a"

VECTORS = ( # case name, coin_name, path, script_type, address, message, signature
Expand Down
Loading

0 comments on commit 8c3d3c6

Please sign in to comment.