fix(dpp)!: version-gate distribution function floating-point evaluation#3462
Draft
PastaPastaPasta wants to merge 1 commit intov3.1-devfrom
Draft
fix(dpp)!: version-gate distribution function floating-point evaluation#3462PastaPastaPasta wants to merge 1 commit intov3.1-devfrom
PastaPastaPasta wants to merge 1 commit intov3.1-devfrom
Conversation
DistributionFunction::evaluate() uses f64 transcendental functions (pow/exp/log) to compute consensus-critical token rewards. The std implementations are platform-dependent, risking consensus divergence between nodes with different architectures or libm versions. Gate these operations behind distribution_function_evaluate_version in DPPTokenVersions. Version 0 preserves the original std behavior (.powf/.exp/.ln) for existing protocol versions. Version 1+ uses deterministic libm functions for cross-platform consistency. Changes: - Add distribution_function_evaluate_version field to DPPTokenVersions - Create TOKEN_VERSIONS_V3 with deterministic evaluation enabled - Add libm 0.2 dependency to rs-dpp - Thread platform_version through evaluate() -> evaluate_interval() -> rewards_in_interval() call chain - Version-gate 4 transcendental call sites: Polynomial (pow), Exponential (exp), Logarithmic (log), InvertedLogarithmic (log) - Add determinism regression tests for all 4 affected variants
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue being fixed or feature implemented
DistributionFunction::evaluate()uses f64 transcendental functions (powf/exp/ln) to compute consensus-critical token rewards. The std implementations are platform-dependent (varying across CPU architectures and libm versions), risking consensus divergence between nodes computing different integer rewards for the same claim.Concrete proof:
125^(1/3)yields 4 on some platforms (stdpowf) vs 5 on others. The deterministiclibmpath always returns 5.What was done?
Gate transcendental float operations behind
distribution_function_evaluate_versioninDPPTokenVersions:.powf(),.exp(),.ln())libmfunctions (pow,exp,log)Changes:
distribution_function_evaluate_versionfield toDPPTokenVersionsTOKEN_VERSIONS_V3with deterministic evaluation enabled (for use in a future protocol version)libm = "0.2"dependency to rs-dppplatform_versionthroughevaluate()→evaluate_interval()→rewards_in_interval()call chainpow), Exponential (exp), Logarithmic (log), InvertedLogarithmic (log)Note:
TOKEN_VERSIONS_V3is created but not yet assigned to a platform version. A future PR creatingPLATFORM_V13should reference it to activate deterministic evaluation on the network.How Has This Been Tested?
evaluate()unit tests pass (47 existing + 3 new determinism tests)validation.rstests passevaluate_intervaltests pass (withtoken-reward-explanationsfeature)distribution_function_evaluate_version = 1cargo check -p dpp -p drivecompiles cleanBreaking Changes
Function signature changes (compile-time only, no behavioral change for existing protocol versions):
DistributionFunction::evaluate()now requiresplatform_version: &PlatformVersionDistributionFunction::evaluate_interval()now requiresplatform_version: &PlatformVersionRewardDistributionType::rewards_in_interval()now requiresplatform_version: &PlatformVersionChecklist: