fix(consensus): restore BCH ASERT fractional polynomial #21

Merged
getrigeos merged 2 commits from fix/asert-fractional-polynomial into v2 2026-08-24 18:54:24 +00:00
getrigeos commented 2026-08-24 16:20:24 +00:00 (Migrated from github.com)

Summary

Preserve the v1 mainnet ASERT rule and stage the exact BCH CalculateASERT fractional polynomial for the next consensus upgrade.

The v1 implementation divides the quadratic term by 65536, while both divisions in the cubic term make that term zero for every u16 fractional value. This differs from the BCH reference by up to about 15.2% near the upper fractional boundary.

This change:

  • keeps the legacy factor explicit so existing mainnet history remains valid;
  • adds the exact BCH polynomial using u128 intermediates;
  • introduces ASERT_BCH_ACTIVATION_HEIGHT as None, leaving production activation disabled;
  • adds exact legacy, BCH and pre/post-activation regression vectors.

Closes #20.

Protocol impact

There is no current mainnet consensus change. With activation set to None, next_target uses the existing v1 rule at every height.

A future v2 consensus release can set one announced activation height. Headers below it will continue to use the legacy rule, while the corrected BCH rule will apply at and above it.

Proof, wire format, storage format, wallet and network messages are unchanged.

Verification

  • cargo fmt --all -- --check
  • cargo test --release -p noid_chain --locked (347 passed, 1 ignored; 5 integration tests and 1 doc test passed)
## Summary Preserve the v1 mainnet ASERT rule and stage the exact BCH `CalculateASERT` fractional polynomial for the next consensus upgrade. The v1 implementation divides the quadratic term by `65536`, while both divisions in the cubic term make that term zero for every `u16` fractional value. This differs from the BCH reference by up to about 15.2% near the upper fractional boundary. This change: - keeps the legacy factor explicit so existing mainnet history remains valid; - adds the exact BCH polynomial using `u128` intermediates; - introduces `ASERT_BCH_ACTIVATION_HEIGHT` as `None`, leaving production activation disabled; - adds exact legacy, BCH and pre/post-activation regression vectors. Closes #20. ## Protocol impact There is no current mainnet consensus change. With activation set to `None`, `next_target` uses the existing v1 rule at every height. A future v2 consensus release can set one announced activation height. Headers below it will continue to use the legacy rule, while the corrected BCH rule will apply at and above it. Proof, wire format, storage format, wallet and network messages are unchanged. ## Verification - `cargo fmt --all -- --check` - `cargo test --release -p noid_chain --locked` (347 passed, 1 ignored; 5 integration tests and 1 doc test passed)
ignotusnemo commented 2026-08-24 18:44:40 +00:00 (Migrated from github.com)

Thanks. The BCH correction and regression vectors are correct. I will extend this PR with the legacy rule and an explicitly disabled v2 activation before merge. This will keep the existing mainnet history and current behavior unchanged while leaving the corrected rule ready for the common v2 activation height.

Thanks. The BCH correction and regression vectors are correct. I will extend this PR with the legacy rule and an explicitly disabled v2 activation before merge. This will keep the existing mainnet history and current behavior unchanged while leaving the corrected rule ready for the common v2 activation height.
Sign in to join this conversation.
No description provided.