Skip to content

Dev testing#48

Open
itsHaseebSaeed wants to merge 10 commits intodevfrom
dev-testing
Open

Dev testing#48
itsHaseebSaeed wants to merge 10 commits intodevfrom
dev-testing

Conversation

@itsHaseebSaeed
Copy link
Collaborator

@itsHaseebSaeed itsHaseebSaeed commented Oct 29, 2025

Privacy-Enhanced Trainer Commitments (Swarm V2 Upgrade)

Highlights

  • Introduced a Swarm V2 stack that layers privacy-preserving trainer commitments on top of the existing training lifecycle.
  • Aggregators can now opt into a privacy mode: they lodge trainer commitments during training, reserve bond per commitment, and reveal identities later.
  • Introduced bond-backed enforcement with configurable penalties and finder rewards to discourage missed reveals.

Contract Changes

  • forge/src/swarm/registry/RoundTrainerRegistryV2.sol

    • Replaces the simple trainer registry with namespaced storage for both trainer metadata and privacy commitments.

    • Implements _commitTrainerPrivacy, _revealTrainerPrivacy, _slashTrainerCommitment, bond accounting, and configuration setters.

    • Exposes read helpers for trainer info, bond state, pending commitment counts, and privacy configuration.

    • forge/src/swarm/SwarmV2.sol

    • Extends Swarm by inheriting the new RoundTrainerRegistryV2 with commitment lifecycle helpers.

    • Adds aggregator-only APIs: registerRoundContributionPrivacy, revealTrainerCommitment, slashTrainerCommitment, configureTrainerPrivacy, bond deposit/withdraw, and a privacy-mode toggle.

    • Guards evaluator assignments and reward calculations to include pending commitments so tasks scale with unrevealed trainers.

  • forge/src/swarm/SwarmV2Factory.sol

    • Mirrors the V1 factory but wires in the Swarm V2 logic address and reuses existing selector/calculator/access/compensation factories.

Scripts & Demo Assets

  • Demo scaffolding (forge/test/training/DemoParams.sol, forge/test/training/FullCyclePrivacy.t.sol) now orchestrates a privacy-enabled round: commitments, evaluator registration, reveals, deliberate missed reveal, slashing, and reward distribution.

Tests

  • forge/test/swarm/SwarmV2.t.sol
    • Validates access control modifiers, full training lifecycle, privacy-mode interactions (commit/reveal/slash), and reward flows with pending commitments.
  • forge/test/swarm/registry/RoundTrainerRegistryV2.t.sol
    • Unit tests commitment storage, bond accounting, model hash updates, and edge cases around duplicate/late operations.
  • forge/test/training/FullCyclePrivacy.t.sol
    • Scenario test exercising the entire privacy demo, including slashing and reward distribution.
  • Existing V1 tests remain untouched but still relevant for regression comparison.

Testing Guidance

  • Run the targeted suite to validate the upgrade:
    • forge test --match-contract SwarmV2Test
    • forge test --match-contract RoundTrainerRegistryTest
    • forge test --match-contract FullCyclePrivacy

@itsHaseebSaeed itsHaseebSaeed requested a review from Mick00 October 29, 2025 18:49
Copy link
Collaborator

@Mick00 Mick00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution, it is a really interesting feature!

If I am not mistaken, I think the only thing missing would be an end to end round test.

Then we can merge this PR and start working on the integration with the Python side of things

Updated:
- SwarmV2.sol: Renamed public function
- SwarmV2.t.sol: Updated test calls
- FullCyclePrivacy.t.sol: Updated test call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants