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

Most upvoted comments

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.

TL;DR: Either test and merge the updated fix (#31912), or revert the RNDR/RNDRRS feature entirely.

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:

  • Why? My understanding is that the kernel headers in guix should provide the HWCAP2_RNG macro?
  • What is the target audience? Currently it only seems to be self-compiled executables.

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!