Skip to content

Commit

Permalink
chore(core): add ability for emu launcher to launch tropic model
Browse files Browse the repository at this point in the history
  • Loading branch information
ibz committed Sep 25, 2024
1 parent 666d698 commit 94517e4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ __pycache__/
proto.gv*
.DS_Store
crypto/tests/libtrezor-crypto.so.dSYM/
tropic-model/
8 changes: 7 additions & 1 deletion core/emu.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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")
Expand All @@ -134,6 +135,7 @@ def cli(
alloc_profiling: bool,
headless: bool,
heap_size: str,
tropic_model: bool,
main: str,
mnemonics: list[str],
log_memory: bool,
Expand Down Expand Up @@ -171,7 +173,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:
Expand Down Expand Up @@ -291,6 +293,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:
Expand Down
20 changes: 20 additions & 0 deletions core/tropic-model.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 94517e4

Please sign in to comment.