From 9bd0d3c41bd54cb84a1963c3fc1f5fe0fe7894b1 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 6 Dec 2023 20:13:26 +0000 Subject: [PATCH] add some changes --- core/mock/state.go | 2 +- core/test/core_test.go | 23 ++++++++++++----------- pkg/encoding/kzgEncoder/multiframe.go | 23 +++++++++-------------- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/core/mock/state.go b/core/mock/state.go index cc462f21ef..8809ef37f8 100644 --- a/core/mock/state.go +++ b/core/mock/state.go @@ -77,7 +77,7 @@ func (d *ChainDataMock) GetTotalOperatorStateWithQuorums(ctx context.Context, bl aggPubKey.Add(d.KeyPairs[ind].GetPubKeyG1()) } - stake := ind + 1 + stake := ind*ind*6 + 32 host := "0.0.0.0" dispersalPort := fmt.Sprintf("3%03v", int(2*ind)) retrievalPort := fmt.Sprintf("3%03v", int(2*ind+1)) diff --git a/core/test/core_test.go b/core/test/core_test.go index 396b0f0424..820751786f 100644 --- a/core/test/core_test.go +++ b/core/test/core_test.go @@ -192,8 +192,8 @@ func checkBatchByUniversalVerifier(t *testing.T, cst core.IndexedChainState, enc func TestCoreLibrary(t *testing.T) { - numBlob := 5 // must be greater than 0 - blobLengths := []int{1, 64, 1000} + numBlob := 1 // must be greater than 0 + blobLengths := []int{1, 100, 1000} quantizationFactors := []uint{1, 10} operatorCounts := []uint{1, 2, 4, 10, 30} @@ -216,14 +216,14 @@ func TestCoreLibrary(t *testing.T) { for _, operatorCount := range operatorCounts { cst, err := mock.NewChainDataMock(core.OperatorIndex(operatorCount)) assert.NoError(t, err) - + batches := make([]core.EncodedBlob, 0) + batchHeader := core.BatchHeader{ + ReferenceBlockNumber: bn, + BatchRoot: [32]byte{}, + } // batch can only be tested per operatorCount, because the assignment would be wrong otherwise for _, blobLength := range blobLengths { - batches := make([]core.EncodedBlob, 0) - batchHeader := core.BatchHeader{ - ReferenceBlockNumber: bn, - BatchRoot: [32]byte{}, - } + for _, quantizationFactor := range quantizationFactors { for _, securityParam := range securityParams { @@ -242,10 +242,11 @@ func TestCoreLibrary(t *testing.T) { } } - t.Run(fmt.Sprintf("universal verifier operatorCount=%v over %v blobs", operatorCount, len(batches)), func(t *testing.T) { - checkBatchByUniversalVerifier(t, cst, batches, batchHeader) - }) + } + t.Run(fmt.Sprintf("universal verifier operatorCount=%v over %v blobs", operatorCount, len(batches)), func(t *testing.T) { + checkBatchByUniversalVerifier(t, cst, batches, batchHeader) + }) } diff --git a/pkg/encoding/kzgEncoder/multiframe.go b/pkg/encoding/kzgEncoder/multiframe.go index da48ed6167..06c96bb93b 100644 --- a/pkg/encoding/kzgEncoder/multiframe.go +++ b/pkg/encoding/kzgEncoder/multiframe.go @@ -21,31 +21,26 @@ 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) { - var buffer bytes.Buffer enc := gob.NewEncoder(&buffer) - err := enc.Encode(samples) - if err != nil { - return bls.ZERO, err - } - err = enc.Encode(params) - if err != nil { - return bls.ZERO, err - } - - err = enc.Encode(m) - if err != nil { - return bls.ZERO, err + for _, sample := range samples { + err := enc.Encode(sample.Commitment) + if err != nil { + return bls.ZERO, err + } } var randomFr bls.Fr - err = bls.HashToSingleField(&randomFr, buffer.Bytes()) + err := bls.HashToSingleField(&randomFr, buffer.Bytes()) if err != nil { return bls.ZERO, err } + return randomFr, nil }