feat: deterministic distribution ordering with address tie-break (#472)#500
Open
MorsH14 wants to merge 1 commit into
Open
feat: deterministic distribution ordering with address tie-break (#472)#500MorsH14 wants to merge 1 commit into
MorsH14 wants to merge 1 commit into
Conversation
|
@MorsH14 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…RevoraOrg#472) Sort `prove_distribution_for_period` and `simulate_distribution` output by (share_bps desc, address-XDR bytes asc) so indexers always receive a canonical ordering regardless of the input `holders` slice order. Key changes: - Add `addr_lt` private helper: byte-wise XDR comparison for Address tie-break - Add `sort_holder_indices`: O(n²) selection sort with u256 bitmask (4×u64), safe for n ≤ MAX_CHUNK_PERIODS (200) - Implement `prove_distribution_for_period`: reads PeriodRevenue, decimals, RoundingMode; normalises revenue; sorts holders; builds domain-separated SHA-256 digest (offering + period_id + sorted entries) - Update `simulate_distribution` to sort before iterating (same key) - Fix pre-existing DataKey2 missing variants (SupplyCap, DepositedRevenue, MinRevenueThreshold, InvestmentConstraints) that prevented CI compilation - Fix pre-existing missing RevoraError::StaleConcentrationData (= 52) - Register `test_prove_distribution` module; update ordering test from assert_ne → assert_eq; add `prove_distribution_identical_bps_tie_break_by_address` fixture - Update DistributionEntry doc comment and README event spec section Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
0ea9542 to
e30d267
Compare
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.
Closes #472
Closes #476
Summary
prove_distribution_for_period— reads on-chain period revenue, normalises by payment-token decimals, computes per-holder payouts, then sorts and digests the result canonically.prove_distribution_for_periodandsimulate_distribution:(share_bps desc, address-XDR bytes asc).(issuer, namespace, token, period_id)so different periods always produce distinct digests even with identical revenue amounts.DataKey2missing variants (SupplyCap,DepositedRevenue,MinRevenueThreshold,InvestmentConstraints) and missingRevoraError::StaleConcentrationDatathat blocked CI compilation.Changes
src/lib.rsaddr_lt+sort_holder_indicesprivate helpers; implementprove_distribution_for_period; sortsimulate_distributionbefore iterating; fix 5 pre-existing missing enum variants; registertest_prove_distributionmodulesrc/test_prove_distribution.rsassert_ne→assert_eq); addprove_distribution_identical_bps_tie_break_by_addressfixtureREADME.mdImplementation details
addr_lt(env, a, b)— byte-wise XDR comparison used as address tie-break.sort_holder_indices(env, bps_vec, addr_vec, n)— O(n²) selection sort with a 256-bit bitmask (4 × u64), safe for n ≤ MAX_CHUNK_PERIODS (200).prove_distribution_for_periodis pure read-only (no state mutation). Caps at 200 holders.Test plan
prove_distribution_sorting_makes_order_invariant— swapped input produces identical digest and entry order.prove_distribution_identical_bps_tie_break_by_address— tie-break fixture: same BPS → stable address-bytes-ascending order regardless of input permutation.prove_distribution_different_periods_produce_different_digests— period domain-separation with identical revenue.prove_distribution_*tests (normal case, empty holders, zero BPS, USDC 6-decimal normalisation, RoundHalfUp, 200-holder cap) pass unmodified.cargo fmt --check,cargo clippy -D warnings,cargo test --test-threads=1.🤖 Generated with Claude Code