Line 316-320 looks like too much defensive. I would remove them at all. What could happen such that "something is very wrong"?
Nitpick: lines 308-312 could be implemented as a single   ```max(1, _CURVE_CACHE_SIZE / num_rlzs)```