Author Topic: Does Bitcoin Cash's CashAddr and Bitcoin Core's Bech32 use fundamentally diff...  (Read 174 times)

cryptos4pz

  • Administrator
  • Full Member
  • *****
  • Posts: 103
    • View Profile
Does Bitcoin Cash's CashAddr and Bitcoin Core's Bech32 use fundamentally different checksums (polymod)?

Copied from discussion on r/btc (Feb 12, 2020):

Reviewing the spec for CashAddr and the spec for Bech32, the checksum methods seem to be fundamentally different. Am I reading this correctly?

CashAddr sample code:

```c uint64_t PolyMod(const data &v) { uint64_t c = 1; for (uint8_t d : v) { uint8_t c0 = c >> 35; c = ((c & 0x07ffffffff) << 5) ^ d;

    if (c0 & 0x01) c ^= 0x98f2bc8e61;
    if (c0 & 0x02) c ^= 0x79b76d99e2;
    if (c0 & 0x04) c ^= 0xf33e5fb3c4;
    if (c0 & 0x08) c ^= 0xae2eabe2a8;
    if (c0 & 0x10) c ^= 0x1e4f43e470;
}

return c ^ 1;
} ```

Bech32 sample code:

python def bech32_polymod(values): GEN = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3] chk = 1 for v in values: b = (chk >> 25) chk = (chk & 0x1ffffff) << 5 ^ v for i in range(5): chk ^= GEN if ((b >> i) & 1) else 0 return chk

I ask because I was trying to put together a PR to pycoin to add CashAddr support. I got it all done then noticed that my checksums seemed problematic. Best I could find, the polymod functions are incompatible between bech32 libraries and cashaddr libraries.

Thoughts.

Source: https://np.reddit.com/r/btc/comments/f2tvjc/does_bitcoin_cashs_cashaddr_and_bitcoin_cores/

Related: https://np.reddit.com/r/btc/comments/f3q2hc/the_cashaddr_spec_claims_it_can_always_detect_six/
« Last Edit: February 14, 2020, 07:19:17 PM by cryptos4pz »