bitcoin: GetRandBytes() Hangs on Samsung Galaxy S25 and OnePlus 13
Is there an existing issue for this?
- I have searched the existing issues
Current behaviour
We have been using Bitcoin Core natively in the Nunchuk Bitcoin wallet, available on both desktop and mobile. On Samsung Galaxy S25 and OnePlus 13 (both running Android 15 with the SM8750-AB Snapdragon 8 Elite 3nm processor), the app fails to initialize due to an issue in GetRandBytes().
The problem occurs when GetRandBytes() calls GetRNDRRS(), resulting in an infinite loop without retrieving entropy from the hardware.
uint64_t GetRNDRRS() noexcept
{
uint8_t ok;
uint64_t r1;
do {
// https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDRRS--Reseeded-Random-Number
__asm__ volatile("mrs %0, s3_3_c2_c4_1; cset %w1, ne;"
: "=r"(r1), "=r"(ok)::"cc");
if (ok) break;
__asm__ volatile("yield");
} while (true);
return r1;
}
Build with: Android NDK 25.1.8937393 & 27.2.12479018
Related PR: https://github.com/bitcoin/bitcoin/pull/26839
Tested on commit: 57b47c47ef0bd36e1c32d709c62998c51dc76f34
Expected behaviour
GetRandBytes() should return entropy without hanging.
Steps to reproduce
- Build Bitcoin Core for Android on master or 57b47c47ef0bd36e1c32d709c62998c51dc76f34
- Call
GetRandBytes - Function gets stuck
Relevant log output
No response
How did you obtain Bitcoin Core
Compiled from source
What version of Bitcoin Core are you using?
master@57b47c47ef0bd36e1c32d709c62998c51dc76f34
Operating system and version
Android 15
Machine specifications
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (15 by maintainers)
Commits related to this issue
- Merge bitcoin/bitcoin#31826: random: Check `GetRNDRRS` is supported in `InitHardwareRand` to avoid infinite loop 09b150bb8adae00854f02ece69fc6ef222fb07d9 In `InitHardwareRand`, do trail test for `RND... — committed to orngr/bitcoin by achow101 2 years ago
- Remove support for RNDR/RNDRRS for aarch64 on Linux This hardware feature is - rarely supported on SoCs (and broken on like half of the chips that support it in the first place) (#31817) - apparentl... — committed to laanwj/bitcoin by laanwj 2 years ago
- Merge bitcoin/bitcoin#32248: Remove support for RNDR/RNDRRS for aarch64 7749d929a0d9dfe71541a22e557ea41e01df28ce Remove support for RNDR/RNDRRS for aarch64 on Linux (laanwj) Pull request description... — committed to bitcoin/bitcoin by achow101 2 years ago
- Remove support for RNDR/RNDRRS for aarch64 on Linux This hardware feature is - rarely supported on SoCs (and broken on like half of the chips that support it in the first place) (#31817) - apparentl... — committed to fanquake/bitcoin by laanwj 2 years ago
- Remove support for RNDR/RNDRRS for aarch64 on Linux This hardware feature is - rarely supported on SoCs (and broken on like half of the chips that support it in the first place) (#31817) - apparentl... — committed to fanquake/bitcoin by laanwj 2 years ago
- Remove support for RNDR/RNDRRS for aarch64 on Linux This hardware feature is - rarely supported on SoCs (and broken on like half of the chips that support it in the first place) (#31817) - apparentl... — committed to fanquake/bitcoin by laanwj 2 years ago
- Remove support for RNDR/RNDRRS for aarch64 on Linux This hardware feature is - rarely supported on SoCs (and broken on like half of the chips that support it in the first place) (#31817) - apparentl... — committed to luke-jr/bitcoin by laanwj 2 years ago
Agree, let’s just drop the support for now, it’s rarely supported (broken on like half of the chips that support it in the first place), apparently not compiled into the release binary anyway, hard to test, and there are plenty of other sources of entropy.
It’s not worth so much discussion, or CI work.
31912 is currently a draft, so before further review and testing (and merge), it would be good to get something non-draft ready first.
The discussion is a bit spread out, but when I looked in https://github.com/bitcoin/bitcoin/pull/31908#issuecomment-2687917758, the feature wasn’t compiled into the release binaries. This raises two questions:
HWCAP2_RNGmacro?About the CI: It is possible, but testing compilation or the path on a “happy” device doesn’t help with the issue here on “sad” devices. See https://github.com/bitcoin/bitcoin/pull/31908#issuecomment-2676190482
Reflecting on this after a while, i’m still not convinced that a hardware feature not working to spec needs to be handled in user space. IMO this needs to be fixed (or worked around otherwise) in the kernel, as per https://github.com/bitcoin/bitcoin/pull/31908#issuecomment-2669309907.
Edit: If you can point ot another project (such as OpenSSL) merging code to handle this edge case i’d be more easily convinced we need this.
You need to first compile the SDK, which is a wrapper for libnunchuk (written in C++ and reuses Core code). @laanwj
https://github.com/nunchuk-io/nunchuk-android-nativesdk
Hey @laanwj ! Our Nunchuk Android app is open source at https://github.com/nunchuk-io/nunchuk-android. You can take a look at the build instructions included in the repo. Let us know if you have any questions!