Skip to main content

Ledger Blue, Stax, Flex and Nano S/S+/X application emulator

Project description

Speculos

codecov lgtm

screenshot btc nano s

The goal of this project is to emulate Ledger Nano S/S+, Nano X, Blue, Flex and Stax apps on standard desktop computers, without any hardware device. More information can be found here in the documentation website (or in the docs/ folder directly).

Usage example:

./speculos.py apps/btc.elf --model nanos
# ... and open a browser on http://127.0.0.1:5000

Installation

From Python pypi packages

The easiest, stable way to install Speculos is with pip:

pip install speculos

It is advised to use Python virtualenv, otherwise admin rights will probably be necessary.

From sources

Installing Speculos from sources is a bit heavier and, depending on the platform, complex, due to all the dependency needed for compiling the emulator.

On Debian (10 or later) or Ubuntu (18.04 or later):

sudo apt install \
    git cmake gcc-arm-linux-gnueabihf libc6-dev-armhf-cross gdb-multiarch \
    python3-pyqt5 python3-construct python3-flask-restful python3-jsonschema \
    python3-mnemonic python3-pil python3-pyelftools python3-requests \
    qemu-user-static libvncserver-dev

# from the root directory of the source repository
pip install .

Dependency management will vary on other platforms; using Docker images and/or WSL should facilitate the installation.

Bugs and contributions

Feel free to open issues and create pull requests on this GitHub repository.

The master branch is protected to disable force pushing. Contributions should be made through pull requests, which are reviewed by @LedgerHQ members before being merged to master:

  • @LedgerHQ members can create branches directly on the repository (if member of a team with write access to the repository)
  • External contributors should fork the repository

Limitations

There is absolutely no guarantee that apps will have the same behavior on hardware devices and Speculos, though the differences are limited.

Syscalls

The emulator handles only a few syscalls made by common apps. For instance, syscalls related to app install, firmware update or OS info can't be implemented.

Invalid syscall parameters might throw an exception on a real device while being ignored on Speculos. Notably, this is the case for application allowed derivation path and curve and application settings flags which are enforced by the device OS, but ignored by Speculos.

Memory alignment

Attempts to perform unaligned accesses when not allowed (eg. dereferencing a misaligned pointer) will cause an alignment fault on a Ledger Nano S device but not on Speculos. Note that such unaligned accesses are supported by other Ledger devices.

Following code crashes on LNS device, but not on Speculos nor on other devices.

uint8_t buffer[20];
for (int i = 0; i < 20; i++) {
    buffer[i] = i;
}
uint32_t display_value = *((uint32_t*) (buffer + 1));
PRINTF("display_value: %d\n", display_value);

Watchdog

NanoX, Flex and Stax devices use an internal watchdog enforcing usage of regular calls to io_seproxyhal_io_heartbeat();. This watchdog is not emulated on Speculos.

Security

Apps can make arbitrary Linux system calls (and use QEMU semihosting features), thus don't run Speculos on untrusted apps.

It's worth noting that the syscall implementation (src/) doesn't expect malicious input. By the way, in Speculos, there is no privilege separation between the app and the syscalls. This doesn't reflect the security of the firmware on hardware devices where app and OS isolation is enforced.

Speculos is not part of Ledger bug bounty program.

Are you developing a Nano App as an external developer?

For a smooth and quick integration:

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

speculos-0.11.0.tar.gz (17.0 MB view details)

Uploaded Source

Built Distribution

speculos-0.11.0-py3-none-any.whl (2.9 MB view details)

Uploaded Python 3

File details

Details for the file speculos-0.11.0.tar.gz.

File metadata

  • Download URL: speculos-0.11.0.tar.gz
  • Upload date:
  • Size: 17.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.18

File hashes

Hashes for speculos-0.11.0.tar.gz
Algorithm Hash digest
SHA256 b49dfdc26b889a304e807df4abc94bec207cc2bd772144172b38a1820794c4e3
MD5 50a051be57025cb5001ee5f12816d457
BLAKE2b-256 333b263e453c69cf7a87c3e2d4a827133261299c718b588a7a3eb2c00f786c11

See more details on using hashes here.

File details

Details for the file speculos-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: speculos-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 2.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.18

File hashes

Hashes for speculos-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 680c62cbb63ef74a360ac8aa8d36781c7be6e50c2f6ad0e056441b19ac9b92a6
MD5 e0e88e22eac82936d6ab80f90b9b9ac6
BLAKE2b-256 c490cd4fecfb18a2efa45a6466107ca4b20fa76ec38e9e3cefe2b460ad1394b5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page