Skip to content

Commit

Permalink
add some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Dec 6, 2023
1 parent 5fb4c0a commit 9bd0d3c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion core/mock/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
23 changes: 12 additions & 11 deletions core/test/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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 {

Expand All @@ -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)
})

}

Expand Down
23 changes: 9 additions & 14 deletions pkg/encoding/kzgEncoder/multiframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 9bd0d3c

Please sign in to comment.