mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-16 17:42:02 +00:00
style(core): use PEP515 Underscores in Numeric Literals
This commit is contained in:
parent
bd0b91a229
commit
952adc5961
@ -221,5 +221,5 @@ class Decred(Bitcoin):
|
||||
) -> None:
|
||||
writers.write_uint64(w, i.amount)
|
||||
writers.write_uint32(w, 0) # block height fraud proof
|
||||
writers.write_uint32(w, 0xFFFFFFFF) # block index fraud proof
|
||||
writers.write_uint32(w, 0xFFFF_FFFF) # block index fraud proof
|
||||
writers.write_bytes_prefixed(w, script_sig)
|
||||
|
@ -19,7 +19,7 @@ if False:
|
||||
|
||||
from apps.common.coininfo import CoinInfo
|
||||
|
||||
_LOCKTIME_TIMESTAMP_MIN_VALUE = const(500000000)
|
||||
_LOCKTIME_TIMESTAMP_MIN_VALUE = const(500_000_000)
|
||||
|
||||
|
||||
def format_coin_amount(amount: int, coin: CoinInfo) -> str:
|
||||
|
@ -64,14 +64,14 @@ _BIP32_CHANGE_CHAIN = const(1)
|
||||
|
||||
# The maximum allowed change address. This should be large enough for normal
|
||||
# use and still allow to quickly brute-force the correct BIP32 path.
|
||||
_BIP32_MAX_LAST_ELEMENT = const(1000000)
|
||||
_BIP32_MAX_LAST_ELEMENT = const(1_000_000)
|
||||
|
||||
# Setting nSequence to this value for every input in a transaction disables nLockTime.
|
||||
_SEQUENCE_FINAL = const(0xFFFFFFFF)
|
||||
_SEQUENCE_FINAL = const(0xFFFF_FFFF)
|
||||
|
||||
# Setting nSequence to a value greater than this for every input in a transaction
|
||||
# disables replace-by-fee opt-in.
|
||||
_MAX_BIP125_RBF_SEQUENCE = const(0xFFFFFFFD)
|
||||
_MAX_BIP125_RBF_SEQUENCE = const(0xFFFF_FFFD)
|
||||
|
||||
|
||||
class TxInfoBase:
|
||||
|
@ -101,7 +101,7 @@ class TxWeightCalculator:
|
||||
def ser_length_size(length: int) -> int:
|
||||
if length < 253:
|
||||
return 1
|
||||
if length < 0x10000:
|
||||
if length < 0x1_0000:
|
||||
return 3
|
||||
return 5
|
||||
|
||||
@ -111,6 +111,6 @@ class TxWeightCalculator:
|
||||
return 1
|
||||
if length < 0x100:
|
||||
return 2
|
||||
if length < 0x10000:
|
||||
if length < 0x1_0000:
|
||||
return 3
|
||||
return 5
|
||||
|
@ -34,7 +34,7 @@ if False:
|
||||
from .tx_info import OriginalTxInfo, TxInfo
|
||||
from ..writers import Writer
|
||||
|
||||
OVERWINTERED = const(0x80000000)
|
||||
OVERWINTERED = const(0x8000_0000)
|
||||
|
||||
|
||||
class Zip243Hash(Hash143):
|
||||
|
@ -64,7 +64,7 @@ def write_tx_output(
|
||||
|
||||
|
||||
def write_op_push(w: Writer, n: int) -> None:
|
||||
ensure(n >= 0 and n <= 0xFFFFFFFF)
|
||||
ensure(n >= 0 and n <= 0xFFFF_FFFF)
|
||||
if n < 0x4C:
|
||||
w.append(n & 0xFF)
|
||||
elif n < 0xFF:
|
||||
|
@ -59,7 +59,7 @@ if False:
|
||||
|
||||
# the maximum allowed change address. this should be large enough for normal
|
||||
# use and still allow to quickly brute-force the correct bip32 path
|
||||
MAX_CHANGE_ADDRESS_INDEX = const(1000000)
|
||||
MAX_CHANGE_ADDRESS_INDEX = const(1_000_000)
|
||||
ACCOUNT_PATH_INDEX = const(2)
|
||||
BIP_PATH_LENGTH = const(5)
|
||||
|
||||
|
@ -9,7 +9,7 @@ if False:
|
||||
from trezor import wire
|
||||
from trezor.messages.ButtonRequest import EnumTypeButtonRequestType
|
||||
|
||||
HARDENED = const(0x80000000)
|
||||
HARDENED = const(0x8000_0000)
|
||||
|
||||
|
||||
async def button_request(
|
||||
|
@ -3,7 +3,7 @@ def length(address_type: int) -> int:
|
||||
return 1
|
||||
if address_type <= 0xFFFF:
|
||||
return 2
|
||||
if address_type <= 0xFFFFFF:
|
||||
if address_type <= 0xFF_FFFF:
|
||||
return 3
|
||||
# else
|
||||
return 4
|
||||
|
@ -35,7 +35,7 @@ def write_uint16_be(w: Writer, n: int) -> int:
|
||||
|
||||
|
||||
def write_uint32_le(w: Writer, n: int) -> int:
|
||||
ensure(0 <= n <= 0xFFFFFFFF)
|
||||
ensure(0 <= n <= 0xFFFF_FFFF)
|
||||
w.append(n & 0xFF)
|
||||
w.append((n >> 8) & 0xFF)
|
||||
w.append((n >> 16) & 0xFF)
|
||||
@ -44,7 +44,7 @@ def write_uint32_le(w: Writer, n: int) -> int:
|
||||
|
||||
|
||||
def write_uint32_be(w: Writer, n: int) -> int:
|
||||
ensure(0 <= n <= 0xFFFFFFFF)
|
||||
ensure(0 <= n <= 0xFFFF_FFFF)
|
||||
w.append((n >> 24) & 0xFF)
|
||||
w.append((n >> 16) & 0xFF)
|
||||
w.append((n >> 8) & 0xFF)
|
||||
@ -53,7 +53,7 @@ def write_uint32_be(w: Writer, n: int) -> int:
|
||||
|
||||
|
||||
def write_uint64_le(w: Writer, n: int) -> int:
|
||||
ensure(0 <= n <= 0xFFFFFFFFFFFFFFFF)
|
||||
ensure(0 <= n <= 0xFFFF_FFFF_FFFF_FFFF)
|
||||
w.append(n & 0xFF)
|
||||
w.append((n >> 8) & 0xFF)
|
||||
w.append((n >> 16) & 0xFF)
|
||||
@ -66,7 +66,7 @@ def write_uint64_le(w: Writer, n: int) -> int:
|
||||
|
||||
|
||||
def write_uint64_be(w: Writer, n: int) -> int:
|
||||
ensure(0 <= n <= 0xFFFFFFFFFFFFFFFF)
|
||||
ensure(0 <= n <= 0xFFFF_FFFF_FFFF_FFFF)
|
||||
w.append((n >> 56) & 0xFF)
|
||||
w.append((n >> 48) & 0xFF)
|
||||
w.append((n >> 40) & 0xFF)
|
||||
@ -96,10 +96,10 @@ def write_bytes_reversed(w: Writer, b: bytes, length: int) -> int:
|
||||
|
||||
|
||||
def write_bitcoin_varint(w: Writer, n: int) -> None:
|
||||
ensure(n >= 0 and n <= 0xFFFFFFFF)
|
||||
ensure(n >= 0 and n <= 0xFFFF_FFFF)
|
||||
if n < 253:
|
||||
w.append(n & 0xFF)
|
||||
elif n < 0x10000:
|
||||
elif n < 0x1_0000:
|
||||
w.append(253)
|
||||
w.append(n & 0xFF)
|
||||
w.append((n >> 8) & 0xFF)
|
||||
|
@ -20,7 +20,7 @@ async def get_address(ctx, msg, keychain):
|
||||
address_bytes = sha3_256(public_key[1:], keccak=True).digest()[12:]
|
||||
|
||||
if len(msg.address_n) > 1: # path has slip44 network identifier
|
||||
network = networks.by_slip44(msg.address_n[1] & 0x7FFFFFFF)
|
||||
network = networks.by_slip44(msg.address_n[1] & 0x7FFF_FFFF)
|
||||
else:
|
||||
network = None
|
||||
address = address_from_bytes(address_bytes, network)
|
||||
|
@ -116,9 +116,9 @@ def get_total_length(msg: EthereumSignTx, data_total: int) -> int:
|
||||
if msg.chain_id: # forks replay protection
|
||||
if msg.chain_id < 0x100:
|
||||
l = 1
|
||||
elif msg.chain_id < 0x10000:
|
||||
elif msg.chain_id < 0x1_0000:
|
||||
l = 2
|
||||
elif msg.chain_id < 0x1000000:
|
||||
elif msg.chain_id < 0x100_0000:
|
||||
l = 3
|
||||
else:
|
||||
l = 4
|
||||
@ -172,7 +172,7 @@ def check(msg: EthereumSignTx):
|
||||
raise wire.DataError("Data length provided, but no initial chunk")
|
||||
# Our encoding only supports transactions up to 2^24 bytes. To
|
||||
# prevent exceeding the limit we use a stricter limit on data length.
|
||||
if msg.data_length > 16000000:
|
||||
if msg.data_length > 16_000_000:
|
||||
raise wire.DataError("Data length exceeds limit")
|
||||
if len(msg.data_initial_chunk) > msg.data_length:
|
||||
raise wire.DataError("Invalid size of initial chunk")
|
||||
|
@ -18,14 +18,14 @@ NEM_TRANSACTION_TYPE_MOSAIC_CREATION = const(0x4001)
|
||||
NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE = const(0x4002)
|
||||
|
||||
NEM_MAX_DIVISIBILITY = const(6)
|
||||
NEM_MAX_SUPPLY = const(9000000000)
|
||||
NEM_MAX_SUPPLY = const(9_000_000_000)
|
||||
|
||||
NEM_SALT_SIZE = const(32)
|
||||
AES_BLOCK_SIZE = const(16)
|
||||
NEM_HASH_ALG = "keccak"
|
||||
NEM_PUBLIC_KEY_SIZE = const(32) # ed25519 public key
|
||||
NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE = const(10000)
|
||||
NEM_MOSAIC_AMOUNT_DIVISOR = const(1000000)
|
||||
NEM_LEVY_PERCENTILE_DIVISOR_ABSOLUTE = const(10_000)
|
||||
NEM_MOSAIC_AMOUNT_DIVISOR = const(1_000_000)
|
||||
|
||||
NEM_MAX_PLAIN_PAYLOAD_SIZE = const(1024)
|
||||
NEM_MAX_ENCRYPTED_PAYLOAD_SIZE = const(960)
|
||||
|
@ -23,6 +23,6 @@ def serialize_provision_namespace(
|
||||
if namespace.parent:
|
||||
write_bytes_with_len(tx, namespace.parent.encode())
|
||||
else:
|
||||
write_uint32_le(tx, 0xFFFFFFFF)
|
||||
write_uint32_le(tx, 0xFFFF_FFFF)
|
||||
|
||||
return tx
|
||||
|
@ -4,22 +4,22 @@ from trezor.crypto.hashlib import ripemd160, sha256
|
||||
|
||||
from . import base58_ripple
|
||||
|
||||
# HASH_TX_ID = const(0x54584E00) # 'TXN'
|
||||
HASH_TX_SIGN = const(0x53545800) # 'STX'
|
||||
# HASH_TX_SIGN_TESTNET = const(0x73747800) # 'stx'
|
||||
# HASH_TX_ID = const(0x5458_4E00) # 'TXN'
|
||||
HASH_TX_SIGN = const(0x5354_5800) # 'STX'
|
||||
# HASH_TX_SIGN_TESTNET = const(0x7374_7800) # 'stx'
|
||||
|
||||
# https://developers.ripple.com/basic-data-types.html#specifying-currency-amounts
|
||||
DECIMALS = const(6) # 1000000 drops equal 1 XRP
|
||||
DECIMALS = const(6) # 1_000_000 drops equal 1 XRP
|
||||
|
||||
# https://developers.ripple.com/transaction-cost.html
|
||||
MIN_FEE = const(10)
|
||||
# max is not defined officially but we check to make sure
|
||||
MAX_FEE = const(1000000) # equals 1 XRP
|
||||
MAX_FEE = const(1_000_000) # equals 1 XRP
|
||||
# https://xrpl.org/basic-data-types.html#specifying-currency-amounts
|
||||
# the value in docs is in XRP, we declare it here in drops
|
||||
MAX_ALLOWED_AMOUNT = const(100000000000000000)
|
||||
MAX_ALLOWED_AMOUNT = const(100_000_000_000_000_000)
|
||||
|
||||
FLAG_FULLY_CANONICAL = 0x80000000
|
||||
FLAG_FULLY_CANONICAL = 0x8000_0000
|
||||
|
||||
|
||||
def address_from_public_key(pubkey: bytes) -> str:
|
||||
|
@ -124,4 +124,4 @@ def rshift(val, n):
|
||||
Implements signed right-shift.
|
||||
See: http://stackoverflow.com/a/5833119/15677
|
||||
"""
|
||||
return (val % 0x100000000) >> n
|
||||
return (val % 0x1_0000_0000) >> n
|
||||
|
@ -50,7 +50,7 @@ _CURVE_NAME = {
|
||||
}
|
||||
|
||||
# Key paths
|
||||
_U2F_KEY_PATH = const(0x80553246)
|
||||
_U2F_KEY_PATH = const(0x8055_3246)
|
||||
|
||||
|
||||
class Credential:
|
||||
@ -385,7 +385,7 @@ class U2fCredential(Credential):
|
||||
|
||||
def generate_key_handle(self) -> None:
|
||||
# derivation path is m/U2F'/r'/r'/r'/r'/r'/r'/r'/r'
|
||||
path = [HARDENED | random.uniform(0x80000000) for _ in range(0, 8)]
|
||||
path = [HARDENED | random.uniform(0x8000_0000) for _ in range(0, 8)]
|
||||
nodepath = [_U2F_KEY_PATH] + path
|
||||
|
||||
# prepare signing key from random path, compute decompressed public key
|
||||
|
@ -33,7 +33,7 @@ if False:
|
||||
Union,
|
||||
)
|
||||
|
||||
_CID_BROADCAST = const(0xFFFFFFFF) # broadcast channel id
|
||||
_CID_BROADCAST = const(0xFFFF_FFFF) # broadcast channel id
|
||||
|
||||
# types of frame
|
||||
_TYPE_MASK = const(0x80) # frame type mask
|
||||
@ -1180,8 +1180,8 @@ def dispatch_cmd(req: Cmd, dialog_mgr: DialogManager) -> Optional[Cmd]:
|
||||
|
||||
def cmd_init(req: Cmd) -> Cmd:
|
||||
if req.cid == _CID_BROADCAST:
|
||||
# uint32_t except 0 and 0xffffffff
|
||||
resp_cid = random.uniform(0xFFFFFFFE) + 1
|
||||
# uint32_t except 0 and 0xffff_ffff
|
||||
resp_cid = random.uniform(0xFFFF_FFFE) + 1
|
||||
else:
|
||||
resp_cid = req.cid
|
||||
|
||||
|
@ -55,19 +55,19 @@ def count_uvarint(n: int) -> int:
|
||||
return 1
|
||||
if n <= 0x3FFF:
|
||||
return 2
|
||||
if n <= 0x1FFFFF:
|
||||
if n <= 0x1F_FFFF:
|
||||
return 3
|
||||
if n <= 0xFFFFFFF:
|
||||
if n <= 0xFFF_FFFF:
|
||||
return 4
|
||||
if n <= 0x7FFFFFFFF:
|
||||
if n <= 0x7_FFFF_FFFF:
|
||||
return 5
|
||||
if n <= 0x3FFFFFFFFFF:
|
||||
if n <= 0x3FF_FFFF_FFFF:
|
||||
return 6
|
||||
if n <= 0x1FFFFFFFFFFFF:
|
||||
if n <= 0x1_FFFF_FFFF_FFFF:
|
||||
return 7
|
||||
if n <= 0xFFFFFFFFFFFFFF:
|
||||
if n <= 0xFF_FFFF_FFFF_FFFF:
|
||||
return 8
|
||||
if n <= 0x7FFFFFFFFFFFFFFF:
|
||||
if n <= 0x7FFF_FFFF_FFFF_FFFF:
|
||||
return 9
|
||||
raise ValueError
|
||||
|
||||
|
@ -216,7 +216,7 @@ def set_flags(flags: int) -> None:
|
||||
i = 0
|
||||
else:
|
||||
i = int.from_bytes(b, "big")
|
||||
flags = (flags | i) & 0xFFFFFFFF
|
||||
flags = (flags | i) & 0xFFFF_FFFF
|
||||
if flags != i:
|
||||
common.set(_NAMESPACE, _FLAGS, flags.to_bytes(4, "big"))
|
||||
|
||||
|
@ -34,11 +34,11 @@ CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"
|
||||
|
||||
def bech32_polymod(values: List[int]) -> int:
|
||||
"""Internal function that computes the Bech32 checksum."""
|
||||
generator = [0x3B6A57B2, 0x26508E6D, 0x1EA119FA, 0x3D4233DD, 0x2A1462B3]
|
||||
generator = [0x3B6A_57B2, 0x2650_8E6D, 0x1EA1_19FA, 0x3D42_33DD, 0x2A14_62B3]
|
||||
chk = 1
|
||||
for value in values:
|
||||
top = chk >> 25
|
||||
chk = (chk & 0x1FFFFFF) << 5 ^ value
|
||||
chk = (chk & 0x1FF_FFFF) << 5 ^ value
|
||||
for i in range(5):
|
||||
chk ^= generator[i] if ((top >> i) & 1) else 0
|
||||
return chk
|
||||
|
@ -29,11 +29,17 @@ ADDRESS_TYPE_P2SH = 8
|
||||
|
||||
|
||||
def cashaddr_polymod(values: List[int]) -> int:
|
||||
generator = [0x98F2BC8E61, 0x79B76D99E2, 0xF33E5FB3C4, 0xAE2EABE2A8, 0x1E4F43E470]
|
||||
generator = [
|
||||
0x98_F2BC_8E61,
|
||||
0x79_B76D_99E2,
|
||||
0xF3_3E5F_B3C4,
|
||||
0xAE_2EAB_E2A8,
|
||||
0x1E_4F43_E470,
|
||||
]
|
||||
chk = 1
|
||||
for value in values:
|
||||
top = chk >> 35
|
||||
chk = ((chk & 0x07FFFFFFFF) << 5) ^ value
|
||||
chk = ((chk & 0x07_FFFF_FFFF) << 5) ^ value
|
||||
for i in range(5):
|
||||
chk ^= generator[i] if (top & (1 << i)) else 0
|
||||
return chk ^ 1
|
||||
|
@ -93,7 +93,7 @@ _MIN_STRENGTH_BITS = const(128)
|
||||
_MIN_MNEMONIC_LENGTH_WORDS = _METADATA_LENGTH_WORDS + _bits_to_words(_MIN_STRENGTH_BITS)
|
||||
"""The minimum allowed length of the mnemonic in words."""
|
||||
|
||||
_BASE_ITERATION_COUNT = const(10000)
|
||||
_BASE_ITERATION_COUNT = const(10_000)
|
||||
"""The minimum number of iterations to use in PBKDF2."""
|
||||
|
||||
_ROUND_COUNT = const(4)
|
||||
@ -399,21 +399,21 @@ def _rs1024_create_checksum(data: Indices) -> Indices:
|
||||
|
||||
def _rs1024_polymod(values: Indices) -> int:
|
||||
GEN = (
|
||||
0xE0E040,
|
||||
0x1C1C080,
|
||||
0x3838100,
|
||||
0x7070200,
|
||||
0xE0E0009,
|
||||
0x1C0C2412,
|
||||
0x38086C24,
|
||||
0x3090FC48,
|
||||
0x21B1F890,
|
||||
0x3F3F120,
|
||||
0xE0_E040,
|
||||
0x1C1_C080,
|
||||
0x383_8100,
|
||||
0x707_0200,
|
||||
0xE0E_0009,
|
||||
0x1C0C_2412,
|
||||
0x3808_6C24,
|
||||
0x3090_FC48,
|
||||
0x21B1_F890,
|
||||
0x3F3_F120,
|
||||
)
|
||||
chk = 1
|
||||
for v in values:
|
||||
b = chk >> 20
|
||||
chk = (chk & 0xFFFFF) << 10 ^ v
|
||||
chk = (chk & 0xF_FFFF) << 10 ^ v
|
||||
for i in range(10):
|
||||
chk ^= GEN[i] if ((b >> i) & 1) else 0
|
||||
return chk
|
||||
@ -432,16 +432,16 @@ def _rs1024_error_index(data: Indices) -> Optional[int]:
|
||||
Currently unused.
|
||||
"""
|
||||
GEN = (
|
||||
0x91F9F87,
|
||||
0x122F1F07,
|
||||
0x244E1E07,
|
||||
0x81C1C07,
|
||||
0x10281C0E,
|
||||
0x20401C1C,
|
||||
0x103838,
|
||||
0x207070,
|
||||
0x40E0E0,
|
||||
0x81C1C0,
|
||||
0x91F_9F87,
|
||||
0x122F_1F07,
|
||||
0x244E_1E07,
|
||||
0x81C_1C07,
|
||||
0x1028_1C0E,
|
||||
0x2040_1C1C,
|
||||
0x10_3838,
|
||||
0x20_7070,
|
||||
0x40_E0E0,
|
||||
0x81_C1C0,
|
||||
)
|
||||
chk = _rs1024_polymod(tuple(_CUSTOMIZATION_STRING) + data) ^ 1
|
||||
if chk == 0:
|
||||
|
@ -151,7 +151,7 @@ class ConfirmPageable(Confirm):
|
||||
return tasks
|
||||
|
||||
def on_render(self) -> None:
|
||||
PULSE_PERIOD = const(1200000)
|
||||
PULSE_PERIOD = const(1_200_000)
|
||||
|
||||
super().on_render()
|
||||
|
||||
|
@ -35,7 +35,7 @@ def render_swipe_icon() -> None:
|
||||
if utils.DISABLE_ANIMATION:
|
||||
c = ui.GREY
|
||||
else:
|
||||
PULSE_PERIOD = const(1200000)
|
||||
PULSE_PERIOD = const(1_200_000)
|
||||
t = ui.pulse(PULSE_PERIOD)
|
||||
c = ui.blend(ui.GREY, ui.DARK_GREY, t)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user