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

未关闭
#189 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
半天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, kotlin, rust

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Rust
星标
114
派生
69
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Blockstream/lwk 的其他 Issue

查看 Blockstream/lwk 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。