diff --git a/core/src/apps/cardano/helpers/utils.py b/core/src/apps/cardano/helpers/utils.py index 6246581fe2..e0af3ada0b 100644 --- a/core/src/apps/cardano/helpers/utils.py +++ b/core/src/apps/cardano/helpers/utils.py @@ -18,17 +18,12 @@ def variable_length_encode(number: int) -> bytes: if number < 0: raise ValueError("Negative numbers not supported. Number supplied: %s" % number) - encoded = [] - - bit_length = len(bin(number)[2:]) - encoded.append(number & 127) - - while bit_length > 7: + encoded = [number & 0x7F] + while number > 0x7F: number >>= 7 - bit_length -= 7 - encoded.insert(0, (number & 127) + 128) + encoded.append((number & 0x7F) + 0x80) - return bytes(encoded) + return bytes(reversed(encoded)) def to_account_path(path: list[int]) -> list[int]: