Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: bump share size to 512 #244

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
)

func main() {
// Size of each share, in bytes
bufferSize := 64
// shareSize is the size of each share (in bytes).
shareSize := 512
// Init new codec
codec := rsmt2d.NewLeoRSCodec()

ones := bytes.Repeat([]byte{1}, bufferSize)
twos := bytes.Repeat([]byte{2}, bufferSize)
threes := bytes.Repeat([]byte{3}, bufferSize)
fours := bytes.Repeat([]byte{4}, bufferSize)
ones := bytes.Repeat([]byte{1}, shareSize)
twos := bytes.Repeat([]byte{2}, shareSize)
threes := bytes.Repeat([]byte{3}, shareSize)
fours := bytes.Repeat([]byte{4}, shareSize)

// Compute parity shares
eds, err := rsmt2d.ComputeExtendedDataSquare(
Expand Down
45 changes: 18 additions & 27 deletions extendeddatacrossword_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"github.com/stretchr/testify/require"
)

// shareSize is the size of each share (in bytes) used for testing.
const shareSize = 512

// PseudoFraudProof is an example fraud proof.
// TODO a real fraud proof would have a Merkle proof for each share.
type PseudoFraudProof struct {
Expand All @@ -20,19 +23,16 @@ type PseudoFraudProof struct {
}

func TestRepairExtendedDataSquare(t *testing.T) {
bufferSize := 64
tests := []struct {
name string
// Size of each share, in bytes
shareSize int
codec Codec
name string
codec Codec
}{
{"leopard", bufferSize, NewLeoRSCodec()},
{"leopard", NewLeoRSCodec()},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
name, codec, shareSize := test.name, test.codec, test.shareSize
name, codec := test.name, test.codec
original := createTestEds(codec, shareSize)

rowRoots, err := original.RowRoots()
Expand Down Expand Up @@ -90,20 +90,17 @@ func TestRepairExtendedDataSquare(t *testing.T) {
}

func TestValidFraudProof(t *testing.T) {
bufferSize := 64
corruptChunk := bytes.Repeat([]byte{66}, bufferSize)
corruptChunk := bytes.Repeat([]byte{66}, shareSize)
tests := []struct {
name string
// Size of each share, in bytes
shareSize int
codec Codec
name string
codec Codec
}{
{"leopard", bufferSize, NewLeoRSCodec()},
{"leopard", NewLeoRSCodec()},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
name, codec, shareSize := test.name, test.codec, test.shareSize
name, codec := test.name, test.codec
original := createTestEds(codec, shareSize)

var byzData *ErrByzantineData
Expand Down Expand Up @@ -151,21 +148,17 @@ func TestValidFraudProof(t *testing.T) {
}

func TestCannotRepairSquareWithBadRoots(t *testing.T) {
bufferSize := 64
corruptChunk := bytes.Repeat([]byte{66}, bufferSize)
corruptChunk := bytes.Repeat([]byte{66}, shareSize)
tests := []struct {
name string
// Size of each share, in bytes
shareSize int
codec Codec
name string
codec Codec
}{
{"leopard", bufferSize, NewLeoRSCodec()},
{"leopard", NewLeoRSCodec()},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
codec, shareSize := test.codec, test.shareSize
original := createTestEds(codec, shareSize)
original := createTestEds(test.codec, shareSize)

rowRoots, err := original.RowRoots()
require.NoError(t, err)
Expand All @@ -184,7 +177,6 @@ func TestCannotRepairSquareWithBadRoots(t *testing.T) {
}

func TestCorruptedEdsReturnsErrByzantineData(t *testing.T) {
shareSize := 64
corruptChunk := bytes.Repeat([]byte{66}, shareSize)

tests := []struct {
Expand Down Expand Up @@ -261,7 +253,6 @@ func TestCorruptedEdsReturnsErrByzantineData(t *testing.T) {
}

func BenchmarkRepair(b *testing.B) {
chunkSize := uint(256)
// For different ODS sizes
for originalDataWidth := 4; originalDataWidth <= 512; originalDataWidth *= 2 {
for codecName, codec := range codecs {
Expand All @@ -271,7 +262,7 @@ func BenchmarkRepair(b *testing.B) {
}

// Generate a new range original data square then extend it
square := genRandDS(originalDataWidth, int(chunkSize))
square := genRandDS(originalDataWidth, shareSize)
eds, err := ComputeExtendedDataSquare(square, codec, NewDefaultTree)
if err != nil {
b.Error(err)
Expand Down
40 changes: 17 additions & 23 deletions extendeddatasquare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ import (
"github.com/stretchr/testify/assert"
)

const ShardSize = 64

var (
zeros = bytes.Repeat([]byte{0}, ShardSize)
ones = bytes.Repeat([]byte{1}, ShardSize)
twos = bytes.Repeat([]byte{2}, ShardSize)
threes = bytes.Repeat([]byte{3}, ShardSize)
fours = bytes.Repeat([]byte{4}, ShardSize)
fives = bytes.Repeat([]byte{5}, ShardSize)
eights = bytes.Repeat([]byte{8}, ShardSize)
elevens = bytes.Repeat([]byte{11}, ShardSize)
thirteens = bytes.Repeat([]byte{13}, ShardSize)
fifteens = bytes.Repeat([]byte{15}, ShardSize)
zeros = bytes.Repeat([]byte{0}, shareSize)
ones = bytes.Repeat([]byte{1}, shareSize)
twos = bytes.Repeat([]byte{2}, shareSize)
threes = bytes.Repeat([]byte{3}, shareSize)
fours = bytes.Repeat([]byte{4}, shareSize)
fives = bytes.Repeat([]byte{5}, shareSize)
eights = bytes.Repeat([]byte{8}, shareSize)
elevens = bytes.Repeat([]byte{11}, shareSize)
thirteens = bytes.Repeat([]byte{13}, shareSize)
fifteens = bytes.Repeat([]byte{15}, shareSize)
)

func TestComputeExtendedDataSquare(t *testing.T) {
Expand Down Expand Up @@ -99,38 +97,34 @@ func TestMarshalJSON(t *testing.T) {
func TestNewExtendedDataSquare(t *testing.T) {
t.Run("returns an error if edsWidth is not even", func(t *testing.T) {
edsWidth := uint(1)
chunkSize := uint(512)

_, err := NewExtendedDataSquare(NewLeoRSCodec(), NewDefaultTree, edsWidth, chunkSize)
_, err := NewExtendedDataSquare(NewLeoRSCodec(), NewDefaultTree, edsWidth, shareSize)
assert.Error(t, err)
})
t.Run("returns a 4x4 EDS", func(t *testing.T) {
edsWidth := uint(4)
chunkSize := uint(512)

got, err := NewExtendedDataSquare(NewLeoRSCodec(), NewDefaultTree, edsWidth, chunkSize)
got, err := NewExtendedDataSquare(NewLeoRSCodec(), NewDefaultTree, edsWidth, shareSize)
assert.NoError(t, err)
assert.Equal(t, edsWidth, got.width)
assert.Equal(t, chunkSize, got.chunkSize)
assert.Equal(t, uint(shareSize), got.chunkSize)
})
t.Run("returns a 4x4 EDS that can be populated via SetCell", func(t *testing.T) {
edsWidth := uint(4)
chunkSize := uint(512)

got, err := NewExtendedDataSquare(NewLeoRSCodec(), NewDefaultTree, edsWidth, chunkSize)
got, err := NewExtendedDataSquare(NewLeoRSCodec(), NewDefaultTree, edsWidth, shareSize)
assert.NoError(t, err)

chunk := bytes.Repeat([]byte{1}, int(chunkSize))
chunk := bytes.Repeat([]byte{1}, int(shareSize))
err = got.SetCell(0, 0, chunk)
assert.NoError(t, err)
assert.Equal(t, chunk, got.squareRow[0][0])
})
t.Run("returns an error when SetCell is invoked on an EDS with a chunk that is not the correct size", func(t *testing.T) {
edsWidth := uint(4)
chunkSize := uint(512)
incorrectChunkSize := uint(513)
incorrectChunkSize := shareSize + 1

got, err := NewExtendedDataSquare(NewLeoRSCodec(), NewDefaultTree, edsWidth, chunkSize)
got, err := NewExtendedDataSquare(NewLeoRSCodec(), NewDefaultTree, edsWidth, shareSize)
assert.NoError(t, err)

chunk := bytes.Repeat([]byte{1}, int(incorrectChunkSize))
Expand Down
41 changes: 19 additions & 22 deletions rsmt2d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import (
"github.com/stretchr/testify/assert"
)

// shareSize is the size of each share (in bytes) used for testing.
const shareSize = 512

func TestEdsRepairRoundtripSimple(t *testing.T) {
bufferSize := 64
tests := []struct {
name string
// Size of each share, in bytes
shareSize int
codec rsmt2d.Codec
name string
codec rsmt2d.Codec
}{
{"leopard", bufferSize, rsmt2d.NewLeoRSCodec()},
{"leopard", rsmt2d.NewLeoRSCodec()},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ones := bytes.Repeat([]byte{1}, bufferSize)
twos := bytes.Repeat([]byte{2}, bufferSize)
threes := bytes.Repeat([]byte{3}, bufferSize)
fours := bytes.Repeat([]byte{4}, bufferSize)
ones := bytes.Repeat([]byte{1}, shareSize)
twos := bytes.Repeat([]byte{2}, shareSize)
threes := bytes.Repeat([]byte{3}, shareSize)
fours := bytes.Repeat([]byte{4}, shareSize)

// Compute parity shares
eds, err := rsmt2d.ComputeExtendedDataSquare(
Expand Down Expand Up @@ -75,22 +75,19 @@ func TestEdsRepairRoundtripSimple(t *testing.T) {
}

func TestEdsRepairTwice(t *testing.T) {
bufferSize := 64
tests := []struct {
name string
// Size of each share, in bytes
shareSize int
codec rsmt2d.Codec
name string
codec rsmt2d.Codec
}{
{"leopard", bufferSize, rsmt2d.NewLeoRSCodec()},
{"leopard", rsmt2d.NewLeoRSCodec()},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ones := bytes.Repeat([]byte{1}, bufferSize)
twos := bytes.Repeat([]byte{2}, bufferSize)
threes := bytes.Repeat([]byte{3}, bufferSize)
fours := bytes.Repeat([]byte{4}, bufferSize)
ones := bytes.Repeat([]byte{1}, shareSize)
twos := bytes.Repeat([]byte{2}, shareSize)
threes := bytes.Repeat([]byte{3}, shareSize)
fours := bytes.Repeat([]byte{4}, shareSize)

// Compute parity shares
eds, err := rsmt2d.ComputeExtendedDataSquare(
Expand All @@ -114,7 +111,7 @@ func TestEdsRepairTwice(t *testing.T) {
flattened := eds.Flattened()

// Delete some shares, just enough so that repairing is possible, then remove one more.
missing := make([]byte, bufferSize)
missing := make([]byte, shareSize)
copy(missing, flattened[1])
flattened[0], flattened[1], flattened[2], flattened[3] = nil, nil, nil, nil
flattened[4], flattened[5], flattened[6], flattened[7] = nil, nil, nil, nil
Expand All @@ -137,7 +134,7 @@ func TestEdsRepairTwice(t *testing.T) {
t.Errorf("RepairExtendedDataSquare did not fail with `%v`, got `%v`", rsmt2d.ErrUnrepairableDataSquare, err)
}
// Re-insert missing share and try again.
flattened[1] = make([]byte, bufferSize)
flattened[1] = make([]byte, shareSize)
copy(flattened[1], missing)

// Re-import the data square.
Expand Down