Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ jobs:
- factory-setup
- firmware-debug
- simulator
- simulator-ng
runs-on: ubuntu-22.04
container:
image: ${{ inputs.container-repo }}:${{ inputs.container-version }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ customers cannot upgrade their bootloader, its changes are recorded separately.
- Add API call to fetch multiple xpubs at once
- Add the option for the simulator to write its memory to file.
- Bitcoin: add support for OP_RETURN outputs
- simulator-ng: a new simulator with a graphical user interface

### 9.23.2
- Improve touch sensor reliability when the sdcard is inserted
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ else()
include(CTest)
add_subdirectory(test/unit-test)
add_subdirectory(test/simulator)
add_subdirectory(test/simulator-ng)
if(COVERAGE)
find_program(GCOVR gcovr)
if(NOT GCOVR STREQUAL "GCOVR-NOTFOUND")
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ rust-docs: | build
$(MAKE) -C build rust-docs
simulator: | build-build-noasan
$(MAKE) -C build-build-noasan simulator
simulator-ng: | build-build-noasan
$(MAKE) -C build-build-noasan simulator-ng
run-simulator: | simulator
./build-build-noasan/bin/simulator
unit-test: | build-build
Expand Down Expand Up @@ -189,3 +191,7 @@ prepare-tidy: | build build-build
$(MAKE) -C build-build rust-cbindgen
clean:
rm -rf build build-build build-debug build-build-noasan

# When you vendor rust libs avoid duplicates
vendor-rust-deps:
(cd external; ./vendor-rust.sh)
2 changes: 1 addition & 1 deletion .cargo/config.toml → src/rust/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ branch = "bitbox-20250922"
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "external/vendor"
directory = "../../external/vendor"
15 changes: 13 additions & 2 deletions src/rust/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,16 @@ We generate one header file `rust.h` and ever product specific function is `#ifd

# Vendoring

Run the vendoring script `vendor.sh` to vendor dependencies from crates.io. The
script will ensure that also rust std libs dependencies are vendored.
Run the vendoring script `vendor-rust.sh` to vendor dependencies from
crates.io. The script will ensure that also rust std libs dependencies are
vendored.

When the toolchain (and standard libraries) are updated they usually depend on
newer versions of crates. Update our lockfile to the same versions to avoid
vendoringing duplicate versions. You can use:

```
cargo update <package> --precise <version>
```

to specify specific versions to up/downgrade to.
9 changes: 9 additions & 0 deletions src/rust/bitbox02-rust-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ target-c-unit-tests = [
"firmware",
"c-unit-testing",
]
target-simulator-ng = [
"dep:bitcoin", # for rust_base58_encode_check()
"app-bitcoin",
"app-litecoin",
"app-ethereum",
"app-cardano",
"app-u2f",
"firmware",
]

platform-bitbox02 = []
platform-bitbox02plus = ["util/sha2", "bitbox02-noise", "bitbox02-rust"]
Expand Down
4 changes: 2 additions & 2 deletions src/rust/bitbox02-rust/src/general/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

use core::time::Duration;

use bitbox02::{delay, ug_clear_buffer, ug_font_select_9x9, ug_put_string, ug_send_buffer};
use bitbox02::{delay, screen_clear, ug_font_select_9x9, ug_put_string, ug_send_buffer};

pub fn print_debug_internal(duration: Duration, msg: &str) {
ug_clear_buffer();
screen_clear();
ug_font_select_9x9();
ug_put_string(0, 0, msg, false);
ug_send_buffer();
Expand Down
101 changes: 62 additions & 39 deletions src/rust/bitbox02-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,62 @@ const ALLOWLIST_VARS: &[&str] = &[
"BIP32_SERIALIZED_LEN",
"BIP39_WORDLIST_LEN",
"EC_PUBLIC_KEY_LEN",
"font_font_a_11X10",
"font_font_a_9X9",
"font_monogram_5X9",
"font_password_11X12",
"INPUT_STRING_MAX_SIZE",
"KEYSTORE_MAX_SEED_LENGTH",
"MAX_LABEL_SIZE",
"MAX_PK_SCRIPT_SIZE",
"MAX_UNLOCK_ATTEMPTS",
"MAX_VARINT_SIZE",
"MEMORY_DEVICE_NAME_MAX_LEN",
"MEMORY_MULTISIG_NAME_MAX_LEN",
"SD_MAX_FILE_SIZE",
"XPUB_ENCODED_LEN",
"font_font_a_11X10",
"font_font_a_9X9",
"font_monogram_5X9",
"font_password_11X12",
"MEMORY_SPI_BLE_FIRMWARE_MAX_SIZE",
"MEMORY_SPI_BLE_FIRMWARE_1_ADDR",
"MEMORY_SPI_BLE_FIRMWARE_2_ADDR",
"MEMORY_PLATFORM_BITBOX02",
"MEMORY_PLATFORM_BITBOX02_PLUS",
"MEMORY_PLATFORM_BITBOX02",
"MEMORY_SECURECHIP_TYPE_ATECC",
"MEMORY_SECURECHIP_TYPE_OPTIGA",
"MAX_UNLOCK_ATTEMPTS",
"MEMORY_SPI_BLE_FIRMWARE_1_ADDR",
"MEMORY_SPI_BLE_FIRMWARE_2_ADDR",
"MEMORY_SPI_BLE_FIRMWARE_MAX_SIZE",
"SCREEN_HEIGHT",
"SCREEN_WIDTH",
"SD_MAX_FILE_SIZE",
"SLIDER_POSITION_TWO_THIRD",
"XPUB_ENCODED_LEN",
];

const ALLOWLIST_TYPES: &[&str] = &[
"buffer_t",
"component_t",
"confirm_params_t",
"event_types",
"event_slider_data_t",
"trinary_input_string_params_t",
"UG_COLOR",
];

const ALLOWLIST_FNS: &[&str] = &[
"UG_ClearBuffer",
"UG_FontSelect",
"UG_PutString",
"UG_SendBuffer",
"bip32_derive_xpub",
"bitbox02_smarteeprom_init",
"bitbox_secp256k1_dleq_prove",
"bitbox_secp256k1_dleq_verify",
"bitbox02_smarteeprom_init",
"communication_mode_ble_enabled",
"confirm_create",
"confirm_transaction_address_create",
"confirm_transaction_fee_create",
"delay_ms",
"delay_us",
"emit_event",
"empty_create",
"unlock_animation_create",
"fake_memory_factoryreset",
"fake_securechip_event_counter_reset",
"fake_securechip_event_counter",
"hww_setup",
"keystore_bip39_mnemonic_to_seed",
"keystore_copy_seed",
"keystore_copy_bip39_seed",
"keystore_copy_seed",
"keystore_create_and_store_seed",
"keystore_encrypt_and_store_seed",
"keystore_get_bip39_word",
Expand All @@ -79,57 +86,64 @@ const ALLOWLIST_FNS: &[&str] = &[
"keystore_mock_unlocked",
"keystore_secp256k1_nonce_commit",
"keystore_secp256k1_sign",
"keystore_unlock",
"keystore_test_get_retained_bip39_seed_encrypted",
"keystore_test_get_retained_seed_encrypted",
"keystore_unlock_bip39_check",
"keystore_unlock_bip39_finalize",
"keystore_test_get_retained_seed_encrypted",
"keystore_test_get_retained_bip39_seed_encrypted",
"keystore_unlock_bip39",
"keystore_unlock",
"label_create",
"localtime",
"memory_set_salt_root",
"lock_animation_start",
"lock_animation_stop",
"memory_add_noise_remote_static_pubkey",
"memory_ble_enable",
"memory_ble_enabled",
"memory_set_salt_root",
"memory_bootloader_hash",
"memory_check_noise_remote_static_pubkey",
"memory_get_attestation_bootloader_hash",
"memory_get_attestation_pubkey_and_certificate",
"memory_get_encrypted_seed_and_hmac",
"memory_get_ble_metadata",
"memory_get_device_name",
"memory_get_encrypted_seed_and_hmac",
"memory_get_noise_static_private_key",
"memory_get_platform",
"memory_get_securechip_type",
"memory_get_seed_birthdate",
"memory_is_initialized",
"memory_is_mnemonic_passphrase_enabled",
"memory_is_seeded",
"memory_multisig_get_by_hash",
"memory_multisig_set_by_hash",
"memory_set_ble_metadata",
"memory_set_device_name",
"memory_set_initialized",
"memory_set_mnemonic_passphrase_enabled",
"memory_set_salt_root",
"memory_set_seed_birthdate",
"memory_setup",
"memory_ble_enabled",
"memory_ble_enable",
"memory_get_ble_metadata",
"memory_set_ble_metadata",
"memory_get_platform",
"memory_get_securechip_type",
"memory_spi_get_active_ble_firmware_version",
"spi_mem_protected_area_write",
"menu_create",
"fake_memory_factoryreset",
"spi_mem_full_erase",
"orientation_screen",
"printf",
"progress_create",
"progress_set",
"queue_hww_queue",
"queue_pull",
"random_32_bytes_mcu",
"random_32_bytes",
"random_fake_reset",
"reboot_to_bootloader",
"reset_reset",
"reset_ble",
"reset_reset",
"screen_clear",
"screen_init",
"screen_print_debug",
"screen_process",
"screen_saver_disable",
"screen_saver_enable",
"screen_splash",
"sd_card_inserted",
"sd_erase_file_in_subdir",
"sd_format",
Expand All @@ -143,23 +157,32 @@ const ALLOWLIST_FNS: &[&str] = &[
"securechip_model",
"securechip_monotonic_increments_remaining",
"securechip_u2f_counter_set",
"fake_securechip_event_counter",
"fake_securechip_event_counter_reset",
"smarteeprom_is_enabled",
"smarteeprom_disable",
"smarteeprom_bb02_config",
"smarteeprom_disable",
"smarteeprom_is_enabled",
"spi_mem_full_erase",
"spi_mem_protected_area_write",
"status_create",
"trinary_choice_create",
"trinary_input_string_create",
"trinary_input_string_set_input",
"ui_screen_stack_pop",
"unlock_animation_create",
"UG_ClearBuffer",
"UG_FontSelect",
"UG_PutString",
"UG_SendBuffer",
"ui_screen_stack_pop_all",
"ui_screen_stack_pop",
"ui_screen_stack_push",
"usb_packet_process",
"usb_processing_hww",
"usb_processing_init",
"usb_processing_process",
"util_format_datetime",
"communication_mode_ble_enabled",
];

const RUSTIFIED_ENUMS: &[&str] = &[
"event_types",
"keystore_error_t",
"keystore_secp256k1_pubkey_format",
"memory_result_t",
Expand Down
7 changes: 7 additions & 0 deletions src/rust/bitbox02-sys/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@

#if defined(TESTING)
#include <fake_memory.h>
#include <hww.h>
#include <touch/gestures.h>
#include <ui/event.h>
#include <ui/event_handler.h>
#include <usb/usb_packet.h>
#include <usb/usb_processing.h>
#include <workflow/orientation_screen.h>
#endif

#if !defined(TESTING)
Expand Down
3 changes: 3 additions & 0 deletions src/rust/bitbox02/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ app-ethereum = []
app-bitcoin = []
app-litecoin = []
app-u2f = []

# Expose raw C bindings as bitbox02::bindings module
bindings = []
7 changes: 5 additions & 2 deletions src/rust/bitbox02/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ extern crate alloc;

use alloc::string::String;

#[cfg(feature = "bindings")]
pub use bitbox02_sys as bindings;

#[cfg(feature = "testing")]
pub mod testing;

Expand Down Expand Up @@ -62,8 +65,8 @@ pub fn ug_put_string(x: i16, y: i16, input: &str, inverted: bool) {
}
}

pub fn ug_clear_buffer() {
unsafe { bitbox02_sys::UG_ClearBuffer() }
pub fn screen_clear() {
unsafe { bitbox02_sys::screen_clear() }
}

pub fn ug_send_buffer() {
Expand Down
4 changes: 4 additions & 0 deletions src/ui/components/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
#include <stdbool.h>
#include <string.h>

#if defined(TESTING)
#define STATUS_DEFAULT_DELAY 100 // counts
#else
#define STATUS_DEFAULT_DELAY 500 // counts
#endif

typedef struct {
bool status;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ typedef struct {
int32_t velocity;
} event_slider_data_t;

enum {
enum event_types {
EVENT_SLIDE,
EVENT_SLIDE_RELEASED,
EVENT_CONTINUOUS_TAP,
Expand Down
4 changes: 4 additions & 0 deletions src/ui/screen_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ void screen_process(void);
* Period of screen updates.
* The screen is refreshed every SCREEN_FRAME_RATE event loops cycles.
*/
#if defined(TESTING)
#define SCREEN_FRAME_RATE 1
#else
#define SCREEN_FRAME_RATE 30
#endif

#endif
1 change: 1 addition & 0 deletions test/simulator-ng/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Loading