Skip to content

Commit ab4005c

Browse files
authored
Merge branch 'master' into rp/errors
2 parents bbacca8 + 1e85aab commit ab4005c

File tree

9 files changed

+71
-141
lines changed

9 files changed

+71
-141
lines changed

NOTICE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rsmt2d
2+
Copyright 2018 and onwards Mustafa Al-Bassam

codecs.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ const (
99
// uses 8-bit leopard for shards less than or equal to 256. The Leopard
1010
// codec uses 16-bit leopard for shards greater than 256.
1111
Leopard = "Leopard"
12-
// RSGF8 stands for Reed-Solomon Galois Field 8-bit mode. This codec uses
13-
// https://pkg.go.dev/github.com/vivint/infectious.
14-
RSGF8 = "RSGF8"
1512
)
1613

1714
type Codec interface {

extendeddatacrossword_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func TestRepairExtendedDataSquare(t *testing.T) {
2727
codec Codec
2828
}{
2929
{"leopard", bufferSize, NewLeoRSCodec()},
30-
{"infectiousGF8", bufferSize, NewRSGF8Codec()},
3130
}
3231

3332
for _, test := range tests {
@@ -96,7 +95,6 @@ func TestValidFraudProof(t *testing.T) {
9695
codec Codec
9796
}{
9897
{"leopard", bufferSize, NewLeoRSCodec()},
99-
{"infectiousGF8", bufferSize, NewRSGF8Codec()},
10098
}
10199

102100
for _, test := range tests {
@@ -150,7 +148,6 @@ func TestCannotRepairSquareWithBadRoots(t *testing.T) {
150148
codec Codec
151149
}{
152150
{"leopard", bufferSize, NewLeoRSCodec()},
153-
{"infectiousGF8", bufferSize, NewRSGF8Codec()},
154151
}
155152

156153
for _, test := range tests {

extendeddatasquare.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ func (eds *ExtendedDataSquare) erasureExtendRow(codec Codec, i uint) error {
161161
if err != nil {
162162
return err
163163
}
164-
if err := eds.setRowSlice(i, eds.originalDataWidth, shares[len(shares)-int(eds.originalDataWidth):]); err != nil {
165-
return err
166-
}
167-
return nil
164+
return eds.setRowSlice(i, eds.originalDataWidth, shares[len(shares)-int(eds.originalDataWidth):])
168165
}
169166

170167
func (eds *ExtendedDataSquare) erasureExtendCol(codec Codec, i uint) error {
@@ -175,10 +172,7 @@ func (eds *ExtendedDataSquare) erasureExtendCol(codec Codec, i uint) error {
175172
if err != nil {
176173
return err
177174
}
178-
if err := eds.setColSlice(eds.originalDataWidth, i, shares[len(shares)-int(eds.originalDataWidth):]); err != nil {
179-
return err
180-
}
181-
return nil
175+
return eds.setColSlice(eds.originalDataWidth, i, shares[len(shares)-int(eds.originalDataWidth):])
182176
}
183177

184178
func (eds *ExtendedDataSquare) deepCopy(codec Codec) (ExtendedDataSquare, error) {

extendeddatasquare_test.go

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,81 @@
11
package rsmt2d
22

33
import (
4+
"bytes"
45
"crypto/rand"
56
"encoding/json"
67
"fmt"
78
"reflect"
89
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
const SHARD_SIZE = 64
15+
16+
var (
17+
zeros = bytes.Repeat([]byte{0}, SHARD_SIZE)
18+
ones = bytes.Repeat([]byte{1}, SHARD_SIZE)
19+
twos = bytes.Repeat([]byte{2}, SHARD_SIZE)
20+
threes = bytes.Repeat([]byte{3}, SHARD_SIZE)
21+
fours = bytes.Repeat([]byte{4}, SHARD_SIZE)
22+
fives = bytes.Repeat([]byte{5}, SHARD_SIZE)
23+
eights = bytes.Repeat([]byte{8}, SHARD_SIZE)
24+
elevens = bytes.Repeat([]byte{11}, SHARD_SIZE)
25+
thirteens = bytes.Repeat([]byte{13}, SHARD_SIZE)
26+
fifteens = bytes.Repeat([]byte{15}, SHARD_SIZE)
927
)
1028

1129
func TestComputeExtendedDataSquare(t *testing.T) {
12-
codec := NewRSGF8Codec()
13-
result, err := ComputeExtendedDataSquare([][]byte{
14-
{1}, {2},
15-
{3}, {4},
16-
}, codec, NewDefaultTree)
17-
if err != nil {
18-
panic(err)
30+
codec := NewLeoRSCodec()
31+
32+
type testCase struct {
33+
name string
34+
data [][]byte
35+
want [][][]byte
1936
}
20-
if !reflect.DeepEqual(result.squareRow, [][][]byte{
21-
{{1}, {2}, {7}, {13}},
22-
{{3}, {4}, {13}, {31}},
23-
{{5}, {14}, {19}, {41}},
24-
{{9}, {26}, {47}, {69}},
25-
}) {
26-
t.Errorf("NewExtendedDataSquare failed for 2x2 square with chunk size 1")
37+
testCases := []testCase{
38+
{
39+
name: "1x1",
40+
// NOTE: data must contain byte slices that are a multiple of 64
41+
// bytes.
42+
// See https://github.com/catid/leopard/blob/22ddc7804998d31c8f1a2617ee720e063b1fa6cd/README.md?plain=1#L27
43+
// See https://github.com/klauspost/reedsolomon/blob/fd3e6910a7e457563469172968f456ad9b7696b6/README.md?plain=1#L403
44+
data: [][]byte{ones},
45+
want: [][][]byte{
46+
{ones, ones},
47+
{ones, ones},
48+
},
49+
},
50+
{
51+
name: "2x2",
52+
data: [][]byte{
53+
ones, twos,
54+
threes, fours,
55+
},
56+
want: [][][]byte{
57+
{ones, twos, zeros, threes},
58+
{threes, fours, eights, fifteens},
59+
{twos, elevens, thirteens, fours},
60+
{zeros, thirteens, fives, eights},
61+
},
62+
},
63+
}
64+
65+
for _, tc := range testCases {
66+
t.Run(tc.name, func(t *testing.T) {
67+
result, err := ComputeExtendedDataSquare(tc.data, codec, NewDefaultTree)
68+
assert.NoError(t, err)
69+
assert.Equal(t, tc.want, result.squareRow)
70+
})
2771
}
2872
}
2973

3074
func TestMarshalJSON(t *testing.T) {
31-
codec := NewRSGF8Codec()
75+
codec := NewLeoRSCodec()
3276
result, err := ComputeExtendedDataSquare([][]byte{
33-
{1}, {2},
34-
{3}, {4},
77+
ones, twos,
78+
threes, fours,
3579
}, codec, NewDefaultTree)
3680
if err != nil {
3781
panic(err)
@@ -53,10 +97,10 @@ func TestMarshalJSON(t *testing.T) {
5397
}
5498

5599
func TestImmutableRoots(t *testing.T) {
56-
codec := NewRSGF8Codec()
100+
codec := NewLeoRSCodec()
57101
result, err := ComputeExtendedDataSquare([][]byte{
58-
{1}, {2},
59-
{3}, {4},
102+
ones, twos,
103+
threes, fours,
60104
}, codec, NewDefaultTree)
61105
if err != nil {
62106
panic(err)
@@ -76,10 +120,10 @@ func TestImmutableRoots(t *testing.T) {
76120
}
77121

78122
func TestEDSRowColImmutable(t *testing.T) {
79-
codec := NewRSGF8Codec()
123+
codec := NewLeoRSCodec()
80124
result, err := ComputeExtendedDataSquare([][]byte{
81-
{1}, {2},
82-
{3}, {4},
125+
ones, twos,
126+
threes, fours,
83127
}, codec, NewDefaultTree)
84128
if err != nil {
85129
panic(err)

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.19
55
require (
66
github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4
77
github.com/stretchr/testify v1.7.0
8-
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3
98
)
109

1110
require (

go.sum

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
2222
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2323
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
2424
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
25-
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3 h1:zMsHhfK9+Wdl1F7sIKLyx3wrOFofpb3rWFbA4HgcK5k=
26-
github.com/vivint/infectious v0.0.0-20200605153912-25a574ae18a3/go.mod h1:R0Gbuw7ElaGSLOZUSwBm/GgVwMd30jWxBDdAyMOeTuc=
2725
gitlab.com/NebulousLabs/errors v0.0.0-20171229012116-7ead97ef90b8/go.mod h1:ZkMZ0dpQyWwlENaeZVBiQRjhMEZvk6VTXquzl3FOFP8=
2826
gitlab.com/NebulousLabs/errors v0.0.0-20200929122200-06c536cf6975 h1:L/ENs/Ar1bFzUeKx6m3XjlmBgIUlykX9dzvp5k9NGxc=
2927
gitlab.com/NebulousLabs/errors v0.0.0-20200929122200-06c536cf6975/go.mod h1:ZkMZ0dpQyWwlENaeZVBiQRjhMEZvk6VTXquzl3FOFP8=
@@ -38,7 +36,6 @@ golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0 h1:cu5kTvlzcw1Q5S9f5ip1/cpi
3836
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3937
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4038
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
41-
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4239
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4340
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
4441
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

infectiousRSGF8.go

Lines changed: 0 additions & 98 deletions
This file was deleted.

rsmt2d_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func TestEdsRepairRoundtripSimple(t *testing.T) {
1717
codec rsmt2d.Codec
1818
}{
1919
{"leopard", bufferSize, rsmt2d.NewLeoRSCodec()},
20-
{"infectiousGF8", bufferSize, rsmt2d.NewRSGF8Codec()},
2120
}
2221

2322
for _, tt := range tests {
@@ -84,7 +83,6 @@ func TestEdsRepairTwice(t *testing.T) {
8483
codec rsmt2d.Codec
8584
}{
8685
{"leopard", bufferSize, rsmt2d.NewLeoRSCodec()},
87-
{"infectiousGF8", bufferSize, rsmt2d.NewRSGF8Codec()},
8886
}
8987

9088
for _, tt := range tests {

0 commit comments

Comments
 (0)