Skip to content

Conversation

iartemov-ledger
Copy link

@iartemov-ledger iartemov-ledger commented Sep 12, 2025

Tested with app-starknet that was built and installed locally as:

docker run --rm -ti --name app-starknet  --net=host --privileged -v "/dev/bus/usb:/dev/bus/usb" -v "$(realpath .):/app" --publish 5001:5001 --publish 9999:9999 -v "/home/iartemov/git/LedgerHQ_apps/ledger-secure-sdk:/tmp/my-sdk" -v "/home/iartemov/git/LedgerHQ_apps/ledger-device-rust-sdk:/tmp/my-rust-sdk" -v "/tmp/.X11-unix:/tmp/.X11-unix" -e DISPLAY=$DISPLAY ghcr.io/ledgerhq/ledger-app-builder/ledger-app-dev-tools:latest

# In the container
    export LEDGER_SDK_PATH=/tmp/my-sdk/
    cd starknet
    rm -rf target
    cargo +$RUST_NIGHTLY update include_gif
    cargo +$RUST_NIGHTLY update ledger_secure_sdk_sys
    cargo +$RUST_NIGHTLY update ledger_device_sdk
    cargo ledger build flex
    ledgerctl install -f target/flex/release/app_flex.json

where:

  • ledger-secure-sdk corresponds to ledger-secure-sdk@API_LEVEL_24 (case-1 - with arch sub-folder removed for the sake of test, case-2 - with all the files present)
  • ledger-device-rust-sdk corresponds to ledger-device-rust-sdk@remove_libc (the present branch)
  • local app-starknet case -1 was redirected to the local Rust SDK:
diff --git a/starknet/Cargo.toml b/starknet/Cargo.toml
index 66d85f2..2283586 100644
--- a/starknet/Cargo.toml
+++ b/starknet/Cargo.toml
@@ -5,8 +5,10 @@ edition = "2021"
 authors = ["Ledger"]
 
 [dependencies]
-ledger_device_sdk = {version = "1.22.11"}
-ledger_secure_sdk_sys = { version = "1.8.2", features = ["heap"]}
+#ledger_device_sdk = {version = "1.22.11"}
+ledger_device_sdk = { path = "/tmp/my-rust-sdk/ledger_device_sdk" }
+#ledger_secure_sdk_sys = { version = "1.8.2", features = ["heap"]}
+ledger_secure_sdk_sys = { path = "/tmp/my-rust-sdk/ledger_secure_sdk_sys"}
 include_gif = "1.2.0"
 hex = { version = "0.4", default-features = false, features = ["alloc"]}
 num-bigint = { version = "0.4", default-features = false }

and in case-2 that was without changes.

Then I compared the case-1 and case-2 result binaries.

Using readelf -S starknet/target/flex/release/starknet :

  • case-1 (with the change):
Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        c0de0000 010000 011800 00  AX  0   0  4
  [ 2] .rel_flash        PROGBITS        c0df1800 021800 000618 00   A  0   0 512
  [ 3] .rodata           PROGBITS        c0df2000 022000 004800 00 AMS  0   0 512
  [ 4] .data             PROGBITS        da7a0000 026800 000000 00   A  0   0  4
  [ 5] .nvm_data         PROGBITS        c0df6800 026800 000400 00  WA  0   0 512
  [ 6] .bss              NOBITS          da7a0000 030000 002c6c 00  WA  0   0  4
  [ 7] ledger.target     PROGBITS        00000000 030000 000005 00      0   0  1
  [ 8] ledger.target_id  PROGBITS        00000000 030005 00000b 00      0   0  1
  [ 9] ledger.targe[...] PROGBITS        00000000 030010 00000c 00      0   0  1
  [10] ledger.api_level  PROGBITS        00000000 03001c 000003 00      0   0  1
  [11] ledger.sdk_v[...] PROGBITS        00000000 03001f 00001b 00      0   0  1
  [12] ledger.rust_[...] PROGBITS        00000000 03003a 000007 00      0   0  1
  [13] ledger.rust_[...] PROGBITS        00000000 030041 000016 00      0   0  1
  [14] ledger.sdk_name   PROGBITS        00000000 030057 000012 00      0   0  1
  [15] ledger.sdk_hash   PROGBITS        00000000 030069 00002f 00      0   0  1
  [16] ledger.sdk_g[...] PROGBITS        00000000 030098 000005 00      0   0  1
  [17] .rel.text         REL             00000000 0300a0 005e70 08   I 21   1  4
  [18] .rel.rodata       REL             00000000 035f10 000618 08   I 21   3  4
  [19] .comment          PROGBITS        00000000 036528 0000af 01  MS  0   0  1
  [20] .ARM.attributes   ARM_ATTRIBUTES  00000000 0365d7 000034 00      0   0  1
  [21] .symtab           SYMTAB          00000000 03660c 007ed0 10     23 1811  4
  [22] .shstrtab         STRTAB          00000000 03e4dc 000121 00      0   0  1
  [23] .strtab           STRTAB          00000000 03e5fd 00a342 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), y (purecode), p (processor specific)
readelf: Error: the PHDR segment must occur before any LOAD segment
readelf: Error: the PHDR segment is not covered by a LOAD segment
  • case-2 (without changes):
Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        c0de0000 010000 011800 00  AX  0   0  4
  [ 2] .rel_flash        PROGBITS        c0df1800 021800 000618 00   A  0   0 512
  [ 3] .rodata           PROGBITS        c0df2000 022000 004800 00 AMS  0   0 512
  [ 4] .data             PROGBITS        da7a0000 026800 000000 00   A  0   0  4
  [ 5] .nvm_data         PROGBITS        c0df6800 026800 000400 00  WA  0   0 512
  [ 6] .bss              NOBITS          da7a0000 030000 002c6c 00  WA  0   0  4
  [ 7] ledger.target     PROGBITS        00000000 030000 000005 00      0   0  1
  [ 8] ledger.target_id  PROGBITS        00000000 030005 00000b 00      0   0  1
  [ 9] ledger.targe[...] PROGBITS        00000000 030010 00000c 00      0   0  1
  [10] ledger.api_level  PROGBITS        00000000 03001c 000003 00      0   0  1
  [11] ledger.sdk_v[...] PROGBITS        00000000 03001f 000015 00      0   0  1
  [12] ledger.rust_[...] PROGBITS        00000000 030034 000007 00      0   0  1
  [13] ledger.rust_[...] PROGBITS        00000000 03003b 000016 00      0   0  1
  [14] ledger.sdk_name   PROGBITS        00000000 030051 000012 00      0   0  1
  [15] ledger.sdk_hash   PROGBITS        00000000 030063 000029 00      0   0  1
  [16] ledger.sdk_g[...] PROGBITS        00000000 03008c 000005 00      0   0  1
  [17] .rel.text         REL             00000000 030094 005e70 08   I 21   1  4
  [18] .rel.rodata       REL             00000000 035f04 000618 08   I 21   3  4
  [19] .comment          PROGBITS        00000000 03651c 0000d5 01  MS  0   0  1
  [20] .ARM.attributes   ARM_ATTRIBUTES  00000000 0365f1 000034 00      0   0  1
  [21] .symtab           SYMTAB          00000000 036628 007ed0 10     23 1811  4
  [22] .shstrtab         STRTAB          00000000 03e4f8 000121 00      0   0  1
  [23] .strtab           STRTAB          00000000 03e619 00a342 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), y (purecode), p (processor specific)
readelf: Error: the PHDR segment must occur before any LOAD segment
readelf: Error: the PHDR segment is not covered by a LOAD segment

we can see that the sizes of sections almost did not change (as for .text section for example), only few sections changed slightly (as for example ledger.sdk_version one)

Then I compared few functions that make part of libc:

  • memcmp():
c0df16a6 <memcmp>:
c0df16a6:	f7ff bfdd 	b.w	c0df1664 <_ZN17compiler_builtins3mem6memcmp17h0956d9528bdc24a9E>

...
c0df1664 <_ZN17compiler_builtins3mem6memcmp17h0956d9528bdc24a9E>:
c0df1664:	b5d0      	push	{r4, r6, r7, lr}
c0df1666:	af02      	add	r7, sp, #8
c0df1668:	b142      	cbz	r2, c0df167c <_ZN17compiler_builtins3mem6memcmp17h0956d9528bdc24a9E+0x18>
c0df166a:	f810 3b01 	ldrb.w	r3, [r0], #1
c0df166e:	3a01      	subs	r2, #1
c0df1670:	f811 4b01 	ldrb.w	r4, [r1], #1
c0df1674:	42a3      	cmp	r3, r4
c0df1676:	d0f7      	beq.n	c0df1668 <_ZN17compiler_builtins3mem6memcmp17h0956d9528bdc24a9E+0x4>
c0df1678:	1b18      	subs	r0, r3, r4
c0df167a:	bdd0      	pop	{r4, r6, r7, pc}
c0df167c:	2000      	movs	r0, #0
c0df167e:	bdd0      	pop	{r4, r6, r7, pc}
  • strlen():
c0df13b0 <strlen>:
c0df13b0:	f000 b966 	b.w	c0df1680 <_ZN17compiler_builtins3mem6strlen17ha9b2bc55fe0aca04E>

...

c0df1680 <_ZN17compiler_builtins3mem6strlen17ha9b2bc55fe0aca04E>:
c0df1680:	4601      	mov	r1, r0
c0df1682:	2000      	movs	r0, #0
c0df1684:	5c0a      	ldrb	r2, [r1, r0]
c0df1686:	b10a      	cbz	r2, c0df168c <_ZN17compiler_builtins3mem6strlen17ha9b2bc55fe0aca04E+0xc>
c0df1688:	3001      	adds	r0, #1
c0df168a:	e7fb      	b.n	c0df1684 <_ZN17compiler_builtins3mem6strlen17ha9b2bc55fe0aca04E+0x4>
c0df168c:	4770      	bx	lr

We see that in the both cases a "compiler_builtins" is used behind, not a function from libc (that explains also why it builds).

Conclusion: the Rust application build does not require the libraries from C SDK.

Just in case I'm attaching the disassembles for the case-1 and case-2:
1.txt
2.txt

@iartemov-ledger iartemov-ledger marked this pull request as ready for review September 24, 2025 11:06
Copy link
Contributor

@yogh333 yogh333 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok LGTM
Could you please bump versions for both crates ledger_secure_sdk_sys and ledger_device_sdk (which depends on ledger_secure_sdk_sys) ?
Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants