Skip to content

Commit

Permalink
compress signatures in minibatch response
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim committed Aug 20, 2024
1 parent dbeaf12 commit 6c2502c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
11 changes: 11 additions & 0 deletions core/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,14 @@ func TestParseOperatorSocket(t *testing.T) {
assert.NotNil(t, err)
assert.Equal(t, "invalid socket address format: localhost1234;5678", err.Error())
}

func TestSignatureBytes(t *testing.T) {
sig := &core.Signature{
G1Point: core.NewG1Point(big.NewInt(1), big.NewInt(2)),
}
bytes := sig.Bytes()
recovered := new(bn254.G1Affine)
_, err := recovered.SetBytes(bytes[:])
assert.NoError(t, err)
assert.Equal(t, recovered, sig.G1Point.G1Affine)
}
10 changes: 5 additions & 5 deletions disperser/batcher/batch_confirmer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestBatchConfirmerIteration(t *testing.T) {
NumBlobs: 1,
RequestedAt: time.Now(),
DispersalResponse: bat.DispersalResponse{
Signatures: []*core.Signature{opInfo.KeyPair.SignMessage(batchHeaderHash1)},
Signatures: [][32]byte{opInfo.KeyPair.SignMessage(batchHeaderHash1).Bytes()},
RespondedAt: time.Now(),
Error: nil,
},
Expand All @@ -215,7 +215,7 @@ func TestBatchConfirmerIteration(t *testing.T) {
NumBlobs: 1,
RequestedAt: time.Now(),
DispersalResponse: bat.DispersalResponse{
Signatures: []*core.Signature{opInfo.KeyPair.SignMessage(batchHeaderHash2)},
Signatures: [][32]byte{opInfo.KeyPair.SignMessage(batchHeaderHash2).Bytes()},
RespondedAt: time.Now(),
Error: nil,
},
Expand Down Expand Up @@ -359,7 +359,7 @@ func TestBatchConfirmerIterationFailure(t *testing.T) {
NumBlobs: 2,
RequestedAt: time.Now(),
DispersalResponse: bat.DispersalResponse{
Signatures: []*core.Signature{opInfo.KeyPair.SignMessage([32]byte{0})},
Signatures: [][32]byte{opInfo.KeyPair.SignMessage([32]byte{0}).Bytes()},
RespondedAt: time.Now(),
Error: nil,
},
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestBatchConfirmerInsufficientSignatures(t *testing.T) {
NumBlobs: 2,
RequestedAt: time.Now(),
DispersalResponse: bat.DispersalResponse{
Signatures: []*core.Signature{opInfo.KeyPair.SignMessage([32]byte{0})},
Signatures: [][32]byte{opInfo.KeyPair.SignMessage([32]byte{0}).Bytes()},
RespondedAt: time.Now(),
Error: nil,
},
Expand All @@ -449,7 +449,7 @@ func TestBatchConfirmerInsufficientSignatures(t *testing.T) {
NumBlobs: 2,
RequestedAt: time.Now(),
DispersalResponse: bat.DispersalResponse{
Signatures: []*core.Signature{opInfo.KeyPair.SignMessage([32]byte{1})},
Signatures: [][32]byte{opInfo.KeyPair.SignMessage([32]byte{1}).Bytes()},
RespondedAt: time.Now(),
Error: nil,
},
Expand Down
5 changes: 4 additions & 1 deletion disperser/batcher/minibatch_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ type BatchRecord struct {
}

type DispersalResponse struct {
Signatures []*core.Signature
// Signatures is the signatures of the blobs that were dispersed to the operator
// The order of the signatures is the same as the order of the blobs in the minibatch
// The signatures are compressed using G1Affine.Bytes(), to be decompressed using G1Affine.SetBytes()
Signatures [][32]byte
RespondedAt time.Time
Error error
}
Expand Down
6 changes: 5 additions & 1 deletion disperser/batcher/minibatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,13 @@ func (b *Minibatcher) DisperseBatch(ctx context.Context, state *core.IndexedOper
if err != nil {
b.logger.Errorf("failed to send blobs to operator %s: %v", opID.Hex(), err)
}
compressedSignatures := make([][32]byte, 0, len(signatures))
for _, signature := range signatures {
compressedSignatures = append(compressedSignatures, signature.Bytes())
}
// Update the minibatch state
err = b.MinibatchStore.UpdateDispersalResponse(ctx, req, &DispersalResponse{
Signatures: signatures,
Signatures: compressedSignatures,
RespondedAt: time.Now().UTC(),
Error: err,
})
Expand Down

0 comments on commit 6c2502c

Please sign in to comment.