Skip to content

Replace reverting, quadratic on-chain leaderboard implementation #8

Closed

Description

@llinsss

Problem

getLeaderboard() copies every registered address and bubble-sorts the full set on every call. This is O(n²) work and can become too expensive for an RPC eth_call. It also evaluates total - 1; with zero registered players, Solidity 0.8 checked arithmetic underflows and the empty leaderboard reverts.

Reproduction

  1. Deploy a fresh MathBlocGame with no registered players.
  2. Call getLeaderboard(10).
  3. Observe an arithmetic panic instead of [].

Proposed scope

  • Return an empty array safely when registeredPlayers.length == 0 or topN == 0.
  • Replace full on-chain sorting with a scalable design (event-indexed/off-chain leaderboard, bounded top-K maintenance, or paginated unsorted reads with client/indexer ranking).
  • Define stable tie-breaking and pagination semantics.
  • Preserve a practical migration/compatibility path for existing consumers.

Acceptance criteria

  • Empty and topN=0 calls return [].
  • Behavior is deterministic for ties and topN > playerCount.
  • Gas/RPC performance is measured at realistic player counts and no longer grows quadratically per read.
  • Tests cover 0, 1, tied, large-N, and oversized topN cases.
  • Frontend and daily activity script use the new API safely.

Activity

  1. Xaxxoo commented on Aug 21, 2026

    @Xaxxoo
    Contributor

    Hi, can I please take up on this issue ?

  2. grantfox-oss commented on Aug 22, 2026

    @grantfox-oss

    🦊 GrantFox — @Xaxxoo has been assigned to this issue as part of the Third Campaign campaign!

    Next steps:

    1. Open a Pull Request referencing this issue (e.g., Closes #8)
    2. Your PR will be reviewed by the DogStark maintainers

    Good luck! Track your progress on GrantFox.

  3. grantfox-oss commented on Aug 31, 2026

    @grantfox-oss

    🎉 This issue has been marked as completed on GrantFox!

    @Xaxxoo's PR #13 was approved and merged by @llinsss.

    🏆 @Xaxxoo: You earned 40 FoxPoints for this contribution! Your current tier: Builder (1,668 total points). Track your full progress on GrantFox.

    👏 Great work, @Xaxxoo! Keep contributing to DogStark.

  4. added a commit that references this issue on Aug 31, 2026
    be820ed
  5. grantfox-oss commented on Aug 31, 2026

    @grantfox-oss

    🎉 This issue has been marked as completed on GrantFox!

    @Xaxxoo's PR #16 was approved and merged by @llinsss.

    🏆 @Xaxxoo: You earned 40 FoxPoints for this contribution! Your current tier: Builder (1,708 total points). Track your full progress on GrantFox.

    👏 Great work, @Xaxxoo! Keep contributing to DogStark.

  6. added a commit that references this issue on Aug 31, 2026
    78bf495
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third Campaign

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions