From 3f0ebcd9794e3bd253f1d7b1f870e2a346342876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ioan=20Biz=C4=83u?= Date: Wed, 25 Sep 2024 18:46:20 +0200 Subject: [PATCH] chore(core): add ability for emu launcher to launch tropic model --- .gitignore | 1 + core/emu.py | 8 +++++++- core/tropic-model.sh | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100755 core/tropic-model.sh diff --git a/.gitignore b/.gitignore index a2e0a1518d..0dc9dc4953 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ __pycache__/ proto.gv* .DS_Store crypto/tests/libtrezor-crypto.so.dSYM/ +tropic-model/ diff --git a/core/emu.py b/core/emu.py index 0cf88a6ca9..14daa2d718 100755 --- a/core/emu.py +++ b/core/emu.py @@ -112,6 +112,7 @@ def _from_env(name: str) -> bool: @click.option("-G", "--alloc-profiling/--no-alloc-profiling", default=_from_env("TREZOR_MEMPERF"), help="Profile memory allocation (requires special micropython build)") @click.option("-h", "--headless", is_flag=True, help="Headless mode (no display, disables animation)") @click.option("--heap-size", metavar="SIZE", default="20M", help="Configure heap size") +@click.option("-m", "--tropic-model", is_flag=True, help="Start the Tropic Square model, needed for running the Tropic tests. Needs to be installed first.") @click.option("--main", help="Path to python main file") @click.option("--mnemonic", "mnemonics", multiple=True, help="Initialize device with given mnemonic. Specify multiple times for Shamir shares.") @click.option("--log-memory/--no-log-memory", default=_from_env("TREZOR_LOG_MEMORY"), help="Print memory usage after workflows") @@ -139,6 +140,7 @@ def cli( alloc_profiling: bool, headless: bool, heap_size: str, + tropic_model: bool, main: str, mnemonics: list[str], log_memory: bool, @@ -177,7 +179,7 @@ def cli( if command and not run_command: raise click.ClickException("Extra arguments found. Did you mean to use -c?") - if watch and (command or debugger): + if watch and (command or debugger or tropic_model): raise click.ClickException("Cannot use -w together with -c or -D") if watch and inotify is None: @@ -297,6 +299,10 @@ def cli( emulator.client, record_dir, report_func=print ) + if tropic_model: + run_command = True + command = "./tropic-model.sh" + if run_command: ret = run_command_with_emulator(emulator, command) elif watch: diff --git a/core/tropic-model.sh b/core/tropic-model.sh new file mode 100755 index 0000000000..ee7c88e640 --- /dev/null +++ b/core/tropic-model.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +if [ ! -d "tropic-model" ]; then + echo "=================================================" + echo "Please install the Tropic model to the tropic-model/ directory first, using the steps below!" + echo "1. mkdir tropic-model && python3 -mvenv tropic-model/venv && source tropic-model/venv/bin/activate" + echo "2. Follow instructions here: https://github.com/tropicsquare/ts-tvl/tree/master?tab=readme-ov-file#installing" + echo " (basically, download the tvl-XXX.whl and pip install it under the venv created above - which should be already activated)" + echo "3. Get config files for the model from https://github.com/tropicsquare/ts-tvl/tree/master/tvl/server/model_config" + echo " i. model_config.yml" + echo " ii. tropic01_ese_certificate_1.pem" + echo " iii.tropic01_ese_private_key_1.pem" + echo " iv. tropic01_ese_public_key_1.pem" + echo "=================================================" + exit 1 +fi + +cd tropic-model +source venv/bin/activate +model_server tcp -vv -c model_config.yml