mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-10 21:26:07 +00:00
fix(core): scope Cardano confirmation to allow GC
Otherwise, we may run out of heap due to recursion. [no changelog]
This commit is contained in:
parent
103568e2e5
commit
2400fcb95d
@ -89,64 +89,69 @@ async def show_native_script(
|
|||||||
key_hash = script.key_hash # local_cache_attribute
|
key_hash = script.key_hash # local_cache_attribute
|
||||||
scripts = script.scripts # local_cache_attribute
|
scripts = script.scripts # local_cache_attribute
|
||||||
|
|
||||||
script_heading = "Script"
|
|
||||||
if indices is None:
|
if indices is None:
|
||||||
indices = []
|
indices = []
|
||||||
if indices:
|
|
||||||
script_heading += " " + ".".join(str(i) for i in indices)
|
|
||||||
|
|
||||||
script_type_name_suffix = ""
|
async def confirm_native_script() -> None:
|
||||||
if script_type == CNST.PUB_KEY:
|
script_heading = "Script"
|
||||||
if key_path:
|
if indices:
|
||||||
script_type_name_suffix = "path"
|
script_heading += " " + ".".join(str(i) for i in indices)
|
||||||
elif key_hash:
|
|
||||||
script_type_name_suffix = "hash"
|
|
||||||
|
|
||||||
props: list[PropertyType] = [
|
script_type_name_suffix = ""
|
||||||
(
|
if script_type == CNST.PUB_KEY:
|
||||||
f"{script_heading} - {SCRIPT_TYPE_NAMES[script_type]} {script_type_name_suffix}:",
|
if key_path:
|
||||||
None,
|
script_type_name_suffix = "path"
|
||||||
)
|
elif key_hash:
|
||||||
]
|
script_type_name_suffix = "hash"
|
||||||
append = props.append # local_cache_attribute
|
|
||||||
|
|
||||||
if script_type == CNST.PUB_KEY:
|
props: list[PropertyType] = [
|
||||||
assert key_hash is not None or key_path # validate_script
|
|
||||||
if key_hash:
|
|
||||||
append((None, bech32.encode(bech32.HRP_SHARED_KEY_HASH, key_hash)))
|
|
||||||
elif key_path:
|
|
||||||
append((address_n_to_str(key_path), None))
|
|
||||||
elif script_type == CNST.N_OF_K:
|
|
||||||
assert script.required_signatures_count is not None # validate_script
|
|
||||||
append(
|
|
||||||
(
|
(
|
||||||
TR.cardano__x_of_y_signatures_template.format(
|
f"{script_heading} - {SCRIPT_TYPE_NAMES[script_type]} {script_type_name_suffix}:",
|
||||||
script.required_signatures_count, len(scripts)
|
|
||||||
),
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
]
|
||||||
|
append = props.append # local_cache_attribute
|
||||||
|
|
||||||
|
if script_type == CNST.PUB_KEY:
|
||||||
|
assert key_hash is not None or key_path # validate_script
|
||||||
|
if key_hash:
|
||||||
|
append((None, bech32.encode(bech32.HRP_SHARED_KEY_HASH, key_hash)))
|
||||||
|
elif key_path:
|
||||||
|
append((address_n_to_str(key_path), None))
|
||||||
|
elif script_type == CNST.N_OF_K:
|
||||||
|
assert script.required_signatures_count is not None # validate_script
|
||||||
|
append(
|
||||||
|
(
|
||||||
|
TR.cardano__x_of_y_signatures_template.format(
|
||||||
|
script.required_signatures_count, len(scripts)
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif script_type == CNST.INVALID_BEFORE:
|
||||||
|
assert script.invalid_before is not None # validate_script
|
||||||
|
append((str(script.invalid_before), None))
|
||||||
|
elif script_type == CNST.INVALID_HEREAFTER:
|
||||||
|
assert script.invalid_hereafter is not None # validate_script
|
||||||
|
append((str(script.invalid_hereafter), None))
|
||||||
|
|
||||||
|
if script_type in (
|
||||||
|
CNST.ALL,
|
||||||
|
CNST.ANY,
|
||||||
|
CNST.N_OF_K,
|
||||||
|
):
|
||||||
|
assert scripts # validate_script
|
||||||
|
append((TR.cardano__nested_scripts_template.format(len(scripts)), None))
|
||||||
|
|
||||||
|
await confirm_properties(
|
||||||
|
"verify_script",
|
||||||
|
TR.cardano__verify_script,
|
||||||
|
props,
|
||||||
|
br_code=BRT_Other,
|
||||||
)
|
)
|
||||||
elif script_type == CNST.INVALID_BEFORE:
|
|
||||||
assert script.invalid_before is not None # validate_script
|
|
||||||
append((str(script.invalid_before), None))
|
|
||||||
elif script_type == CNST.INVALID_HEREAFTER:
|
|
||||||
assert script.invalid_hereafter is not None # validate_script
|
|
||||||
append((str(script.invalid_hereafter), None))
|
|
||||||
|
|
||||||
if script_type in (
|
# Allow GC to free local variables after confirmation is over
|
||||||
CNST.ALL,
|
await confirm_native_script()
|
||||||
CNST.ANY,
|
|
||||||
CNST.N_OF_K,
|
|
||||||
):
|
|
||||||
assert scripts # validate_script
|
|
||||||
append((TR.cardano__nested_scripts_template.format(len(scripts)), None))
|
|
||||||
|
|
||||||
await confirm_properties(
|
|
||||||
"verify_script",
|
|
||||||
TR.cardano__verify_script,
|
|
||||||
props,
|
|
||||||
br_code=BRT_Other,
|
|
||||||
)
|
|
||||||
|
|
||||||
for i, sub_script in enumerate(scripts):
|
for i, sub_script in enumerate(scripts):
|
||||||
await show_native_script(sub_script, indices + [i + 1])
|
await show_native_script(sub_script, indices + [i + 1])
|
||||||
|
Loading…
Reference in New Issue
Block a user