Go implementation of two dimensional Reed-Solomon Merkle tree data availability scheme.
package main
import (
"bytes"
"github.com/celestiaorg/rsmt2d"
)
func main() {
// Size of each share, in bytes
bufferSize := 64
// 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)
// Compute parity shares
eds, err := rsmt2d.ComputeExtendedDataSquare(
[][]byte{
ones, twos,
threes, fours,
},
codec,
rsmt2d.NewDefaultTree,
)
if err != nil {
// ComputeExtendedDataSquare failed
}
// Save all shares in flattened form.
flattened := make([][]byte, 0, eds.Width()*eds.Width())
for i := uint(0); i < eds.Width(); i++ {
flattened = append(flattened, eds.Row(i)...)
}
// Delete some shares, just enough so that repairing is possible.
flattened[0], flattened[2], flattened[3] = nil, nil, nil
flattened[4], flattened[5], flattened[6], flattened[7] = nil, nil, nil, nil
flattened[8], flattened[9], flattened[10] = nil, nil, nil
flattened[12], flattened[13] = nil, nil
// Re-import the data square.
eds, err = rsmt2d.ImportExtendedDataSquare(flattened, codec, rsmt2d.NewDefaultTree)
if err != nil {
// ImportExtendedDataSquare failed
}
// Repair square.
err := eds.Repair(
eds.RowRoots(),
eds.ColRoots(),
)
if err != nil {
// err contains information to construct a fraud proof
// See extendeddatacrossword_test.go
}
}
# Run unit tests
go test ./...
# Run benchmarks
go test -benchmem -bench=.
# Run linter
golangci-lint run