-
Notifications
You must be signed in to change notification settings - Fork 33
Description
Summary
The master branch fails to sync past Fork #1 (block 450,947) when compiled with GCC 13 due to an optimization bug affecting the BMW256 component of the LYRA2REv2 hash chain.
Root Cause
GCC 13's -O2 optimization introduces undefined behavior in sph_bmw.c, causing the BMW256 hash function to produce incorrect results. This affects all LYRA2REv2 blocks (both standalone and auxpow merge-mined blocks).
The LYRA2REv2 hash chain is:
Blake256 → Keccak256 → CubeHash256 → LYRA2 → Skein256 → CubeHash256 → BMW256
The BMW256 step produces incorrect output when compiled with -O2, causing valid blocks to fail PoW verification.
Key Finding: Same-Chain Merge Mining
Investigation revealed that LYRA2REv2 auxpow blocks use same-chain merge mining (LYRA2REv2 → LYRA2REv2), not cross-chain merge mining to Litecoin (LYRA2REv2 → SCRYPT). This means the BMW256 fix applies to both standalone and auxpow LYRA2REv2 blocks.
The Fix
Rebuild the hash-related object files with -O0 (no optimization):
# In src/ directory, rebuild affected files with -O0
gcc -c -O0 sph_bmw.c -o sph_bmw.o
gcc -c -O0 Lyra2RE.c -o Lyra2RE.o
gcc -c -O0 Lyra2.c -o Lyra2.o
gcc -c -O0 Sponge.c -o Sponge.o
# Then relink bitmarkd
make bitmarkdOr modify the Makefile to compile these files with -O0 or -O1 instead of -O2.
Verification Results
After applying the fix, a fresh sync was performed:
| Metric | Result |
|---|---|
| Blocks Synced | 582,944+ |
| Fork #1 (450,947) | ✅ PASSED |
| Fork #2 (511,111) | ✅ PASSED |
| LYRA2REv2 Blocks Verified | 22,199+ |
| PoW Errors | 0 |
Environment
- OS: Ubuntu 24.04
- GCC: 13.3.0
- Affected Optimization Level:
-O2 - Safe Optimization Levels:
-O0,-O1
Recommended Permanent Fix
Update the Makefile to explicitly compile sph_bmw.c (and ideally all LYRA2RE-related C files) with -O1 or -O0:
# Add specific rule for BMW256 to avoid GCC optimization bug
sph_bmw.o: sph_bmw.c
$(CC) -c -O1 $(CFLAGS_NO_O2) $< -o $@Related
This issue supersedes the investigation in issue #71 with a confirmed root cause and fix.