fix(sdk): pass uncompress_pubkey key by reference
What changed, and why it matters
This commit fixes a Rust programming mistake in how a public-key helper function passes data across the app-to-firmware boundary. The function now passes the 33-byte compressed public key by reference (pointer) instead of copying it by value. The change also turns on a compiler lint that forbids unsafe cross-language type definitions. The fix is defensive: passing large arrays by value across an 'extern C' ABI can create undefined behavior or stack/memory issues, especially on a no-std embedded device like a hardware wallet. There is no direct evidence in the commit that this was exploitable to steal coins or bypass security, but it removes a class of low-level memory/ABI risk.
Treat as a low-risk hardening fix. Review whether any other `extern "C"` SDK traits pass arrays or Rust-specific types by value, because the new `deny(improper_ctypes_definitions)` lint will now flag them. No urgent user action is indicated, but firmware builds should be verified to compile cleanly with the new lint.
Security signals we found
ABI boundary hardening: extern "C" function signature changed from by-value array to by-reference array
Compiler lint enabled: #![deny(improper_ctypes_definitions)]
Cryptographic API affected: ecdsa_uncompress_pubkey handles public keys
Potential undefined behavior / improper C type due to passing [u8; 33] by value across FFI
No explicit security advisory, CVE, or changelog entry in the commit
Evidence from the diff
The patch changes ecdsa_uncompress_pubkey in the Trezor app SDK and its core implementation from taking public_key: [u8; 33] by value to public_key: &'a [u8; 33] by reference. Because the trait method is marked extern "C", passing a fixed-size array by value across the FFI ABI is fragile and can be classified as an improper C type. The commit adds #![deny(improper_ctypes_definitions)] in core/embed/api/src/lib.rs, which instructs the Rust compiler to reject such patterns. Call sites are updated to pass the slice reference directly instead of dereferencing (*public_key). This is a hardening/correctness fix for an ABI boundary in the firmware’s cryptographic API.
Changed components
core/embed/api/src/crypto/mod.rscore/embed/api/src/lib.rssdk/crates/trezor-app-sdk/src/app_runtime/crypto.rssdk/crates/trezor-app-sdk/src/mock.rssdk/crates/trezor-app-sdk/src/traits/crypto.rsInspect captured patch +10 / −8
### core/embed/api/src/crypto/mod.rs
@@ -290,12 +290,12 @@ impl CryptoV1 for TrezorCryptoV1Impl {
.into()
}
- extern "C" fn ecdsa_uncompress_pubkey(
+ extern "C" fn ecdsa_uncompress_pubkey<'a>(
&self,
curve: EcdsaCurve,
- public_key: [u8; 33],
+ public_key: &'a [u8; 33],
) -> FastResult<[u8; 65], CryptoError> {
- crypto::ecdsa::uncompress_pubkey(ecdsa_curve(curve), &public_key)
+ crypto::ecdsa::uncompress_pubkey(ecdsa_curve(curve), public_key)
.map_err(|_| CryptoError::InvalidPublicKey)
.into()
}
### core/embed/api/src/lib.rs
@@ -1,5 +1,7 @@
#![no_std]
#![cfg_attr(not(target_os = "none"), feature(thread_local))]
+// Every app API function crosses the app ABI boundary
+#![deny(improper_ctypes_definitions)]
use rtl::fatal_error;
use trezor_app_sdk::traits::{ApiGetter, ApiVariant};
### sdk/crates/trezor-app-sdk/src/app_runtime/crypto.rs
@@ -214,7 +214,7 @@ pub fn ecdsa_recover_pubkey(curve: EcdsaCurve, signature: &[u8], digest: &[u8])
/// [`PublicNode::public_key`], into its 65-byte `0x04`-prefixed form.
pub fn ecdsa_uncompress_pubkey(curve: EcdsaCurve, public_key: &[u8; 33]) -> Result<[u8; 65]> {
get_crypto_or_die()
- .ecdsa_uncompress_pubkey(curve, *public_key)
+ .ecdsa_uncompress_pubkey(curve, public_key)
.into_app_result()
.c()
}
### sdk/crates/trezor-app-sdk/src/mock.rs
@@ -198,10 +198,10 @@ impl CryptoV1 for DummyCrypto {
unimplemented!("not exercised by the current test suite")
}
- extern "C" fn ecdsa_uncompress_pubkey(
+ extern "C" fn ecdsa_uncompress_pubkey<'a>(
&self,
_curve: EcdsaCurve,
- _public_key: [u8; 33],
+ _public_key: &'a [u8; 33],
) -> FastResult<[u8; 65], CryptoError> {
unimplemented!("not exercised by the current test suite")
}
### sdk/crates/trezor-app-sdk/src/traits/crypto.rs
@@ -197,10 +197,10 @@ pub trait CryptoV1: Send + Sync {
/// Uncompresses a 33-byte compressed ECDSA `public_key` into its 65-byte
/// `0x04`-prefixed form.
- extern "C" fn ecdsa_uncompress_pubkey(
+ extern "C" fn ecdsa_uncompress_pubkey<'a>(
&self,
curve: EcdsaCurve,
- public_key: [u8; 33],
+ public_key: &'a [u8; 33],
) -> FastResult<[u8; 65], CryptoError>;
/// Verifies a 64-byte Ed25519 `signature` of `message` against theWhy this scored 35/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.