Skip to content

Commit

Permalink
take feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Dec 11, 2023
1 parent 789cc64 commit 6f84c3e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions core/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ type Sample struct {
}

// SubBatch is a part of the whole Batch with identical Encoding Parameters, i.e. (ChunkLen, NumChunk)
// Blobs with the same encoding parameters are collected in a single subBatch
type SubBatch struct {
Samples []Sample
NumBlobs int
Expand Down
4 changes: 2 additions & 2 deletions core/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type Encoder interface {
// VerifyChunks takes in the chunks, indices, commitments, and encoding parameters and returns an error if the chunks are invalid.
VerifyChunks(chunks []*Chunk, indices []ChunkNumber, commitments BlobCommitments, params EncodingParams) error

// VerifyBatch takes in
UniversalVerifyChunks(params EncodingParams, samples []Sample, numBlobs int) error
// VerifyBatch takes in the encoding parameters, samples and the number of blobs and returns an error if a chunk in any sample is invalid.
UniversalVerifySubBatch(params EncodingParams, samples []Sample, numBlobs int) error

// VerifyBlobLength takes in the commitments and returns an error if the blob length is invalid.
VerifyBlobLength(commitments BlobCommitments) error
Expand Down
2 changes: 1 addition & 1 deletion core/encoding/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (e *Encoder) VerifyChunks(chunks []*core.Chunk, indices []core.ChunkNumber,
}

// convert struct understandable by the crypto library
func (e *Encoder) UniversalVerifyChunks(params core.EncodingParams, samplesCore []core.Sample, numBlobs int) error {
func (e *Encoder) UniversalVerifySubBatch(params core.EncodingParams, samplesCore []core.Sample, numBlobs int) error {
encParams := toEncParams(params)
samples := make([]kzgEncoder.Sample, len(samplesCore))

Expand Down
2 changes: 1 addition & 1 deletion core/encoding/mock_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (e *MockEncoder) VerifyChunks(chunks []*core.Chunk, indices []core.ChunkNum
return args.Error(0)
}

func (e *MockEncoder) UniversalVerifyChunks(params core.EncodingParams, samples []core.Sample, numBlobs int) error {
func (e *MockEncoder) UniversalVerifySubBatch(params core.EncodingParams, samples []core.Sample, numBlobs int) error {
args := e.Called(params, samples, numBlobs)
time.Sleep(e.Delay)
return args.Error(0)
Expand Down
18 changes: 12 additions & 6 deletions core/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,21 @@ func (v *chunkValidator) UpdateOperatorID(operatorID OperatorID) {

func (v *chunkValidator) ValidateBatch(blobs []*BlobMessage, operatorState *OperatorState) error {
subBatchMap := make(map[EncodingParams]*SubBatch)
blobCommitments := make([]BlobCommitments, len(blobs))

for _, blob := range blobs {
for k, blob := range blobs {
if len(blob.Bundles) != len(blob.BlobHeader.QuorumInfos) {
return errors.New("number of bundles does not match number of quorums")
}

// Validate the blob length
err := v.encoder.VerifyBlobLength(blob.BlobHeader.BlobCommitments)
if err != nil {
return err
}
// err := v.encoder.VerifyBlobLength(blob.BlobHeader.BlobCommitments)
//if err != nil {
// return err
//}

blobCommitments[k] = blob.BlobHeader.BlobCommitments

// for each quorum
for _, quorumHeader := range blob.BlobHeader.QuorumInfos {
// Check if the operator is a member of the quorum
Expand Down Expand Up @@ -191,6 +195,8 @@ func (v *chunkValidator) ValidateBatch(blobs []*BlobMessage, operatorState *Oper
go v.universalVerifyWorker(params, subBatch, out)
}



for i := 0; i < numSubBatch; i++ {
err := <-out
if err != nil {
Expand All @@ -203,7 +209,7 @@ func (v *chunkValidator) ValidateBatch(blobs []*BlobMessage, operatorState *Oper

func (v *chunkValidator) universalVerifyWorker(params EncodingParams, subBatch *SubBatch, out chan error) {

err := v.encoder.UniversalVerifyChunks(params, subBatch.Samples, subBatch.NumBlobs)
err := v.encoder.UniversalVerifySubBatch(params, subBatch.Samples, subBatch.NumBlobs)
if err != nil {
out <- err
return
Expand Down
8 changes: 4 additions & 4 deletions pkg/encoding/kzgEncoder/multiframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Sample struct {
// generate a random value using Fiat Shamir transform
// we can also pseudo randomness generated locally, but we have to ensure no adv can manipulate it
// Hashing everything takes about 1ms, so Fiat Shamir transform does not incur much cost
func GenRandomness(params rs.EncodingParams, samples []Sample, m int) (bls.Fr, error) {
func GenRandomness(samples []Sample) (bls.Fr, error) {
var buffer bytes.Buffer
enc := gob.NewEncoder(&buffer)

Expand All @@ -45,7 +45,7 @@ func GenRandomness(params rs.EncodingParams, samples []Sample, m int) (bls.Fr, e
}

// UniversalVerify implements batch verification on a set of chunks given the same chunk dimension (chunkLen, numChunk).
// The details is given in Ethereum Research post whose authors are George Kadianakis, George Kadianakis, George Kadianakis
// The details is given in Ethereum Research post whose authors are George Kadianakis, Ansgar Dietrichs, Dankrad Feist
// https://ethresear.ch/t/a-universal-verification-equation-for-data-availability-sampling/13240
//
// m is number of blob, samples is a list of chunks
Expand All @@ -55,7 +55,7 @@ func (group *KzgEncoderGroup) UniversalVerify(params rs.EncodingParams, samples
for i, s := range samples {
if s.Row >= m {
fmt.Printf("sample %v has %v Row, but there are only %v blobs\n", i, s.Row, m)
return errors.New("sample.Row and numBlob is inconsistend")
return errors.New("sample.Row and numBlob is inconsistent")
}
}

Expand All @@ -67,7 +67,7 @@ func (group *KzgEncoderGroup) UniversalVerify(params rs.EncodingParams, samples
n := len(samples)
fmt.Printf("Batch verify %v frames of %v symbols out of %v blobs \n", n, params.ChunkLen, m)

r, err := GenRandomness(params, samples, m)
r, err := GenRandomness(samples)
if err != nil {
return err
}
Expand Down

0 comments on commit 6f84c3e

Please sign in to comment.