Alamgu: The Rust Ledger Platform

Alamgu: The Rust Ledger Platform

Alamgû (Akkadian) n.: engraver of seals

The Beginning

Lately, across ecosystems, more blockchain protocols are allowing security-minded users to store their private keys offline, on hardware devices. The leading hardware wallets are the Ledger devices, for which we have been developing applications that expand the range of Ledger-compatible blockchains and cryptocurrencies.

Historically, most Ledger applications have been written in C, and therefore inherit that language's limitations with regards to safety, maintenance, and memory handling. On the other hand, an advanced programming language like Haskell, which has always been our choice for building robust applications, is not suitable for Ledger devices due to the relatively small RAM space on these embedded devices. Setting out to find an alternative to C for Ledger applications, we also had to find an alternative to Haskell.

Through experimentation we have determined that for low-level, embedded applications, Rust is an ideal programming language. Compared to C, Rust offers improved safety, thanks to its rich type system and memory-safety guarantees; and compared to Haskell, Rust has very little runtime overhead.

The Platform

To unlock these benefits, and to create better wallet apps faster, we developed tooling for Rust-based Ledger applications. Our early investment has reached maturity, and we have consolidated our tooling into a platform named Alamgu. That platform now belongs to the public as an open-source tool. To access Alamgu, visit its Github organization here.

What follows are some examples of what the collection contains:

  • alamgu
    • The build infrastructure support code, written with Nix, which collects many of the constituent parts of Alamgu together.
  • ledger-rust-app
    • An example application compatible with Ledger Nano S devices running FW 2.1.0 and above.
  • ledger-prompts-ui
    • A library for writing interactive prompts for ledger apps.
  • ledger-crypto-helpers
    • A collection of APIs common to all Ledger apps, to deal with things related to cryptography.
  • ledger-log
    • A library for logging from the Ledger device or an emulator, for debugging purposes.

Note: To avoid failure, applications using either ledger-prompts-ui or ledger-log should be built using the Alamgu compiler, with the llvm-ledger-ropi pass enabled.

The Purpose

The availability of Rust tooling for Ledger applications facilitates improvements that reliance on C did not allow. It also offers a path for developing Ledger applications that draws from familiarity with the benefits of Haskell (e.g., strong type safety) without having to deal with the incompatibility of the GHC with Ledger Nano devices.

Now, we are able to use the Alamgu platform for our own projects, and we are also able to share this tooling with the public. Not only should this help others develop better Ledger applications faster, but more generally, Alamgu is a case study for expanding the range of viable programming languages within the hardware constraints of a given device.

For more details, check out the documentation on GitHub.