GetRandBytes() Hangs on Samsung Galaxy S25 and OnePlus 13 #31817

issue giahuy98 openend this issue on February 7, 2025
  1. giahuy98 commented at 1:56 pm on February 7, 2025: none

    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.

     0uint64_t GetRNDRRS() noexcept
     1{
     2    uint8_t ok;
     3    uint64_t r1;
     4    do {
     5        // https://developer.arm.com/documentation/ddi0601/2022-12/AArch64-Registers/RNDRRS--Reseeded-Random-Number
     6        __asm__ volatile("mrs %0, s3_3_c2_c4_1; cset %w1, ne;"
     7                         : "=r"(r1), "=r"(ok)::"cc");
     8        if (ok) break;
     9        __asm__ volatile("yield");
    10    } while (true);
    11    return r1;
    12}
    

    Build with: Android NDK 25.1.8937393 & 27.2.12479018

    Related PR: #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

  2. eval-exec commented at 11:57 am on February 8, 2025: contributor

    I have Samsung Galaxy S23 Ultra:

    Image

    Image

  3. laanwj commented at 10:25 pm on February 13, 2025: member

    Build with: Android NDK 25.1.8937393 & 27.2.12479018

    We’ve had some problems building on android (including NDK 25, see #29360), and are curious how you do the builds for that platform, for testing, can you list more specific build instructions please?

  4. hugohn commented at 10:37 pm on February 13, 2025: contributor
    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!
  5. laanwj commented at 11:04 pm on February 13, 2025: member
    Thanks! i’d looked there but couldn’t find anything that compiles Bitcoin Core, or any C++ code for that matter.
  6. hugohn commented at 11:33 pm on February 13, 2025: contributor

    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

  7. achow101 closed this on Feb 19, 2025

  8. pull[bot] referenced this in commit 139640079f on Feb 19, 2025
  9. glozow commented at 6:44 pm on February 19, 2025: member
    Has not been fixed since #31908 reverted #31826, but also out of scope - see #31908 (comment). I believe this should stay closed.

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-02-22 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me