{"record":{"id":"4ea8ae9a0f2efa3d","repo":"bytedance/deer-flow","slug":"bad-bech32-checksum-in-value-r","errorCode":null,"errorMessage":"bad bech32 checksum in {value!r}","messagePattern":"bad bech32 checksum in (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/app/channels/buzz_nostr.py","lineNumber":57,"sourceCode":"        chk = (chk & 0x1FFFFFF) << 5 ^ v\n        for i in range(5):\n            chk ^= gen[i] if ((b >> i) & 1) else 0\n    return chk\n\n\ndef _bech32_decode(expected_hrp: str, value: str) -> bytes:\n    if \"1\" not in value:\n        raise ValueError(f\"not bech32: {value!r}\")\n    hrp, data_part = value.rsplit(\"1\", 1)\n    if hrp != expected_hrp:\n        raise ValueError(f\"expected {expected_hrp!r} bech32, got {hrp!r}\")\n    try:\n        data = [_BECH32_CHARSET.index(c) for c in data_part]\n    except ValueError as exc:\n        raise ValueError(f\"invalid bech32 character in {value!r}\") from exc\n    hrp_expanded = [ord(c) >> 5 for c in hrp] + [0] + [ord(c) & 31 for c in hrp]\n    if _bech32_polymod(hrp_expanded + data) != 1:\n        raise ValueError(f\"bad bech32 checksum in {value!r}\")\n    acc = bits = 0\n    out = bytearray()\n    for v in data[:-6]:\n        acc = (acc << 5) | v\n        bits += 5\n        if bits >= 8:\n            bits -= 8\n            out.append((acc >> bits) & 0xFF)\n    if len(out) != 32:\n        raise ValueError(f\"expected 32-byte payload in {value!r}\")\n    return bytes(out)\n\n\ndef _parse_32_bytes(value: str, bech_hrp: str) -> bytes:\n    value = value.strip()\n    if value.lower().startswith(f\"{bech_hrp}1\"):\n        return _bech32_decode(bech_hrp, value.lower())\n    try:","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/bytedance/deer-flow/blob/1dd6ba1acb03700589994b0366c5d1c7d05e2eff/backend/app/channels/buzz_nostr.py#L39-L75","documentation":"Bech32 strings end with a 6-character checksum derived from the hrp and data via the polymod function. The decoder recomputes it and requires the result to be exactly 1; otherwise the string is corrupt or mistyped and this ValueError is raised. This catches single-character typos and truncation that survived the charset check.","triggerScenarios":"A key whose data part was altered — one character changed, characters dropped or added, or the string truncated/extended — so the recomputed polymod checksum no longer equals 1. Common with manual transcription or partial clipboard copies.","commonSituations":"User retyped the key and made one typo; clipboard copied only the first N characters; a YAML editor 'smart-quoted' or trimmed part of the value; key from an incompatible bech32 variant (bech32m) where the checksum constant differs.","solutions":["Re-copy the complete key from its original source — checksum failures almost always mean transcription corruption.","Paste as 64-char hex instead, which has no checksum to fail.","Verify in an external Nostr tool (e.g. a key converter) that the key is valid before configuring it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def _polymod_ok(hrp: str, data_part: str) -> bool:\n    # reuse the module's own decoder in a dry-run\n    try:\n        _bech32_decode(hrp, f'{hrp}1{data_part}')\n        return True\n    except ValueError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    parse_pubkey(user_value)\nexcept ValueError as e:\n    if 'checksum' in str(e):\n        reject_with_hint('key corrupted in transit — re-copy it')\n    raise","preventionTips":["Treat checksum failures as corruption and always re-copy from source rather than hand-fixing.","Validate keys in an external Nostr tool before configuring.","Use hex keys for machine-managed deployments."],"tags":["buzz","nostr","bech32","validation"],"backgroundTag":null,"analyzedSha":"1dd6ba1acb03700589994b0366c5d1c7d05e2eff","analyzedAt":"2026-08-14T21:20:34.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}