Kotlin bindings: UniFFI checksum mismatch on 32-bit ARM Android (needs uniffi >= 0.32.1)

Aperta
#189 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, kotlin, rust

Direzione di ricerca

The fix is a uniffi version bump: the pin uniffi = "=0.29.4" in the workspace Cargo.toml moves to 0.32.1 or later, and the Kotlin bindings must be regenerated. Start with the generated checksum check uniffiCheckApiChecksums and the uniffi_lwk_checksum_func_derive_asset_id symbol. Done means the checksums match on an armeabi-v7a AOT build and no aarch64 checksums regress, so 0.31.2 must be avoided.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

On 32-bit ARM Android (armeabi-v7a), loading the LWK Kotlin bindings fails once the app is AOT-compiled:

java.lang.ExceptionInInitializerError
	at lwk.UniffiLib.<clinit>(lwk.android.kt)
	at lwk.Network$Companion.mainnet(lwk.android.kt)
Caused by: java.lang.RuntimeException: UniFFI API checksum mismatch: try cleaning and rebuilding your project
	at lwk.IntegrityCheckingUniffiLib.uniffiCheckApiChecksums(lwk.android.kt:2292)
	at lwk.IntegrityCheckingUniffiLib.<clinit>(lwk.android.kt:2278)

We see this in production in Blockstream Green on 32-bit Android devices installed from Google Play. The .so and the bindings match. The cause is a signedness bug in UniFFI's Kotlin bindings, fixed upstream in uniffi 0.31.2 / 0.32.1. LWK pins uniffi = "=0.29.4".

Cause

This is uniffi mozilla/uniffi-rs#2740:

  • The checksum functions return Rust u16. The generated Kotlin declares them as JNA direct-mapped native short.
  • On armv7, the Rust side correctly zero-extends the u16 (AAPCS), so 0xF889 arrives as 0x0000F889.
  • JNA/libffi pass the register through unchanged.
  • ART's compiled JNI stubs on arm32 don't re-extend small return values, so Kotlin sees 63625 instead of the expected (short) -1911.

The interpreter path (generic JNI trampoline) sign-extends, so the bug only appears once the code is AOT-compiled, for example by Play cloud profiles or background dexopt. A plain adb install usually doesn't reproduce it. arm64 is unaffected because ART's arm64 stubs extend.

In LWK 0.19.1, 280 of the 513 checksum checks expect a negative value. The first one, uniffi_lwk_checksum_func_derive_asset_id, expects -1911, so initialization always fails. The bug is not limited to checksums: any exported function returning u8/u16 gets values ≥ 0x80/0x8000 wrong on compiled arm32 code.

Reproduction

Android 7.1.1 armeabi-v7a emulator (system-images;android-25;google_apis;armeabi-v7a, x86_64 host). The test runs with dalvikvm the lwk/IntegrityCheckingUniffiLib.class from the lwk-android 0.19.1 AAR, JNA 5.18.1, and the AAR's armeabi-v7a/liblwk.so. A small probe calls uniffi_lwk_checksum_func_derive_asset_id through JNA direct mapping.

Run derive_asset_id (expect -1911) IntegrityCheckingUniffiLib
Interpreted (-Xnodex2oat) -1911 OK
AOT (-Xcompiler-option --compiler-filter=speed) 63625 checksum mismatch

In an app: install on a 32-bit device, or with adb install --abi armeabi-v7a on a 64-bit device that supports 32-bit apps. Then run adb shell cmd package compile -m speed -f <package> and initialize LWK.

Fix

Upgrade uniffi to 0.32.1 or later:

I'm preparing a PR with the bump.

Lingua principale
Rust
Stelle
114
Fork
69
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Blockstream/lwk

Tutte le issue di Blockstream/lwk

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.