Skip to content

Conversation

@jait91
Copy link
Contributor

@jait91 jait91 commented Oct 22, 2025

Add optional parent and child modes for aggregator for sharding

jait91 and others added 30 commits September 30, 2025 13:47
Child mode (for child aggregator in sharded setup) differs
from normal mode (for monolithic aggregator) by taking a
shard ID and using its most significant bit as the "path"
for the root node to get the corrrect hash value for the
corresponding node of the parent aggregator's SMT.
Parent mode (for parent aggregator in sharded setup) differs
from normal mode (for monolithic aggregator) in three ways:
- is allows values in leaves to be updated;
- the leaves are not hashed (instead they contain hash values
  computed by and received from child aggregators);
- to maintain fixed structure, the tree is really not sparse
  at all.
- add ToBSON and FromBSON methods to all structs that are stored to mongo db
- remove BSON marshalling from api.Timestamp struct
- move some structs into separate files
Use mongo Date type to store timestamps
- join parent and child merkle paths in inclusion proof
- request id shard bits are now managed internally in the SMT
- set shardID type alias from int64 to int
- use shardID type alias instead of int
Sharding: update child aggregator mode to latest smt changes
Copy link
Member

@MastaP MastaP left a comment

Choose a reason for hiding this comment

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

main question: since requestIDs contain 2-byte algorithm prefix, how do we deal with it in the sharding context?

)

// Authenticator represents the authentication data for a commitment
type Authenticator struct {
Copy link
Member

Choose a reason for hiding this comment

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

why this (third) struct is needed? Seems api.Authenticator and AuthenticatorBSON to be enough

Copy link
Contributor

Choose a reason for hiding this comment

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

We didn't add it, it was just moved to separate file. Looks like design choice to separate api and domain structs. Since it already exists, even though all the fields are the same, it's not worth refactoring IMO.

@lploom
Copy link
Contributor

lploom commented Oct 29, 2025

main question: since requestIDs contain 2-byte algorithm prefix, how do we deal with it in the sharding context?

Sharding uses the rightmost bits so they do not conflict.

@MastaP MastaP linked an issue Oct 29, 2025 that may be closed by this pull request
@MastaP MastaP requested a review from Copilot October 29, 2025 19:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a comprehensive hierarchical sharding system for the aggregator, enabling parent and child aggregator modes. The changes include:

  • Support for three sharding modes: standalone, parent, and child
  • SMT (Sparse Merkle Tree) enhancements for sharded operations
  • Parent-child proof joining and verification
  • Removal of MongoDB BSON serialization in favor of explicit conversion

Reviewed Changes

Copilot reviewed 68 out of 70 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/integration/sharding_e2e_test.go E2E test suite validating hierarchical sharding with parent/child aggregators and proof joining
pkg/api/smt.go Modified path verification to handle naked direction bits and joined proofs
pkg/api/types.go Added ShardID type, shard-related request/response types, and removed BSON marshaling
internal/smt/smt.go Major refactor adding child/parent SMT support with proof joining functionality
internal/service/parent_service.go New parent aggregator service handling shard root submissions and proof generation
internal/sharding/root_aggregator_client.go HTTP client for child aggregators to communicate with parent
internal/signing/commitment_validator.go Added shard ID validation based on LSB matching
internal/storage/mongodb/*.go Replaced direct BSON marshaling with explicit ToBSON/FromBSON conversions
internal/round/round_manager.go Enhanced to support child mode round processing and parent communication

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +246 to +248
// find position of MSB e.g.
// 0b111 -> BitLen=3 -> 3-1=2
msbPos := shardBitmaskBigInt.BitLen() - 1
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The variable name 'msbPos' (Most Significant Bit Position) is misleading. According to the logic, this represents the position of the bit below the MSB, not the MSB itself. The MSB position would be at BitLen-1 before subtracting 1. Consider renaming to 'compareBitPos' or 'shardBitPos' to avoid confusion.

Copilot uses AI. Check for mistakes.
jait91 and others added 3 commits October 29, 2025 22:28
* create constant for miniBatchSize
The implementation of sharded SMT did not have the bug the spec had
(and that was fixed in unicitynetwork/specs#4),
but the old tests would not have caught it if it did.
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.

[TGE] Aggregation layer - SMT sharding

5 participants