Skip to content

sha: restrict the x86 bswap asm to x86 - #41

Merged
Bitflash-sh merged 1 commit into
Bitflash-sh:mainfrom
ericscalibur:fix/arm64-sha-bswap
Jul 30, 2026
Merged

sha: restrict the x86 bswap asm to x86#41
Bitflash-sh merged 1 commit into
Bitflash-sh:mainfrom
ericscalibur:fix/arm64-sha-bswap

Conversation

@ericscalibur

Copy link
Copy Markdown
Contributor

ByteReverse(word32) in src/sha.h uses the x86 bswap instruction via inline asm, guarded only by #if defined(__GNUC__). GCC and Clang define GNUC on every architecture they target, so on aarch64 the guard passes and the assembler then rejects the instruction:

Error: unknown mnemonic `bswap' -- `bswap %eax'

This makes the tree fail to build on any ARM64 host -- Apple Silicon, ARM servers, a Raspberry Pi -- at a point far from anything the user did.

Narrow the guard to the architectures where the instruction exists. The portable C fallback directly below is then used everywhere else; it was already there and already correct.

ByteReverse(word32) in src/sha.h uses the x86 `bswap` instruction via inline
asm, guarded only by `#if defined(__GNUC__)`. GCC and Clang define __GNUC__ on
every architecture they target, so on aarch64 the guard passes and the
assembler then rejects the instruction:

    Error: unknown mnemonic `bswap' -- `bswap %eax'

This makes the tree fail to build on any ARM64 host -- Apple Silicon, ARM
servers, a Raspberry Pi -- at a point far from anything the user did.

Narrow the guard to the architectures where the instruction exists. The
portable C fallback directly below is then used everywhere else; it was
already there and already correct.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ericscalibur
ericscalibur force-pushed the fix/arm64-sha-bswap branch from 41686ac to 51e333f Compare July 30, 2026 05:01
Vic-Nas added a commit to Vic-Nas/bitflash-mod that referenced this pull request Jul 30, 2026
…RM64 build (port of Bitflash-sh#41); gitignore: cover key files (port of Bitflash-sh#43)

## Bootstrap seeds (Bitflash-sh#36)

A node with an empty cache has only the Nostr relays for discovery --
if those are down, blocked, or just slow, a first run has no way into
the network at all, which is exactly the moment a user has the least
patience. Seeds are the floor under that: a compiled-in list of
long-lived peers, tried automatically only when the peer cache is
empty.

A seed entry is deliberately just an address and an encryption key,
no meeting node -- the rendezvous relay pairs on the service's public
key, and a .btf address is that key, so a seed is findable by walking
the known relays. Recording which relay a seed was on would rot the
moment it failed over, which is the exact "advertising a rendezvous
nobody is registered at" failure this project has chased before.
Seeds carry no special authority: they hand out the same signed,
self-certifying descriptors any peer does, so a hostile seed can
stall a bootstrap but can't forge a peer or feed a false chain.

The compiled list here is empty, deliberately -- upstream shipped
their own dedicated bootstrap node's address in their version of this
commit, but that's their infrastructure, not something this fork has
any relationship to or authority to point users at. /btfseed=
ADDRESS:ENCHEX (repeatable, CLI-only) covers testing and private
networks without needing a compiled entry.

Adapted the hex-decode call to our own BtfPeerCacheHexToBytes rather
than a generic HexToBytes upstream doesn't have under that name.

## ARM64 build failure (Bitflash-sh#41)

ByteReverse(word32) in sha.h used the x86 bswap instruction via
inline asm, guarded only by #if defined(__GNUC__) -- true on every
architecture GCC/Clang target, so on aarch64 the assembler rejected
the instruction outright. The 64-bit ByteReverse right below it
already had the correct guard (&& defined(__x86_64__)); the 32-bit
one just never got it. Fails the build on Apple Silicon, ARM servers,
or a Raspberry Pi -- all plausible headless-node hosts.

## .gitignore gaps (Bitflash-sh#43)

*.dat/wallet.dat were covered, but btf_enc.key (this node's .btf
identity) and nostr.key (its Nostr signing key) are not .dat files
and are exactly as sensitive -- already listed explicitly in our
.gitignore from an earlier session, but walletrpc.token (bearer
authority to spend from the wallet over the wallet API) was missing
entirely, along with a general *.key catch-all and patterns for key
backup archives, mempool dumps, and stray .patch/.rej/.orig files. A
node run with its data directory inside a working tree -- the obvious
thing to do while developing -- would otherwise leave all of this
untracked but committable.
@Bitflash-sh

Copy link
Copy Markdown
Owner

Correct, and the file argues your case for you: the word64 overload thirty lines below already guards the same instruction properly.

#if defined(__GNUC__) && defined(__x86_64__)
    __asm__ ("bswap %0" : "=r" (value) : "0" (value));

The word32 version was simply left inconsistent with its own neighbour, so your patch brings it in line with the style already in the file rather than introducing a new convention. The fallback chain below it was always there and handles every other target.

Since ByteReverse(word32) sits in the block-hashing path, I did not want to take a compile-time guard on faith — a wrong turn here would corrupt hashes rather than fail loudly. Built it on x86_64 (mingw-w64 UCRT64, where __x86_64__ is defined, so the asm path is still taken) and synced a clean datadir against the live network:

AddToBlockIndex: new best=5bd7cb255d814e  height=0
...
ProcessBlock: ACCEPTED
AddToBlockIndex: new best=2758d080b2960b  height=1280

1280 real blocks validated from genesis, proof-of-work checks included, with no hash errors and no rejections. The x86 path is untouched, as intended.

I have no ARM64 host to confirm the build failure directly, but the mechanism is not in doubt: GCC and Clang define __GNUC__ on every target they support, so the bare guard was never architecture-specific.

Reviewed clean.

@Bitflash-sh
Bitflash-sh merged commit 417dce7 into Bitflash-sh:main Jul 30, 2026
@Bitflash-sh Bitflash-sh mentioned this pull request Jul 30, 2026
Bitflash-sh added a commit that referenced this pull request Jul 30, 2026
Headless mining fix (#42), ARM64 build (#41), format-string
checking (#44), gitignore for key material (#43).

#42 is the reason this release exists: -gen has mined nothing on
headless nodes since v1.2.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants