An update about the chronic address bug on VanitySearch:
I have found the source of the error. In case you didn't know, everything released after VanitySearch 1.13 fails to math any base58 address, on newer GCC (11+, and maybe 10 as well)
This has to do with the sha256.cpp and sha256_sse.cpp files inside the hash/ folder. Specifically,
sha256_checksum and
sha256sse_checksum functions.
These functions fail to make the correct checksum when you are running with optimization flags on, but I managed to get even more specific than that.
It appears that a single O2 optimization flag, -fstrict-aliasing is causing all the chaos. Taking the SSE version of this function for example:
void sha256sse_checksum(uint32_t *i0, uint32_t *i1, uint32_t *i2, uint32_t *i3,
uint8_t *d0, uint8_t *d1, uint8_t *d2, uint8_t *d3) {
__m128i s[8];
_sha256sse::Initialize(s);
_sha256sse::Transform2(s, i0, i1, i2, i3);
#ifndef WIN64
uint32_t *s32 = (uint32_t *)(&s[0]);
*((uint32_t *)d0) = __builtin_bswap32(s32[3]);
*((uint32_t *)d1) = __builtin_bswap32(s32[2]);
*((uint32_t *)d2) = __builtin_bswap32(s32[1]);
*((uint32_t *)d3) = __builtin_bswap32(s32[0]);
#else
*((uint32_t *)d0) = _byteswap_ulong(s[0].m128i_u32[3]);
*((uint32_t *)d1) = _byteswap_ulong(s[0].m128i_u32[2]);
*((uint32_t *)d2) = _byteswap_ulong(s[0].m128i_u32[1]);
*((uint32_t *)d3) = _byteswap_ulong(s[0].m128i_u32[0]);
#endif
}
Aliasing is an optimization technique where the compiler assumes that you're never going to cast variables into crazy types of different sizes and makes some fast but unsafe memory writes as a result.
It's unsafe because if the type indeed is cast into a larger size type, then some garbage will be written into the higher parts of the variable. That's where the gibberish in the checksum characters comes from. The parameters d0-3 are expanded into uint32 and then assigned, and that's where strict aliasing messes things up.
Something similar happens with sha256_checksum but with memcpy instead.
These functions were introduced in the following commit:
https://github.com/JeanLucPons/VanitySearch/commit/ea177b7b36c0db66f110d4358fd4fd4704a6603d right before v1.14 was released.
To fix this mess, all you have to do is pass -fno-strict-aliasing (please write this carefully) in the CXXFLAGS in the makefile.
I am working on a patched version of this where only the offending functions get this flag. So my codebase is spaghetti right now. Please stand by.