MCPcopy Index your code
hub / github.com/celestiaorg/rsmt2d

github.com/celestiaorg/rsmt2d @v0.15.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.15.2 ↗ · + Follow
195 symbols 849 edges 14 files 87 documented · 45%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

rsmt2d

Go implementation of two dimensional Reed-Solomon Merkle tree data availability scheme.

Tests Codecov GoDoc

Example

package main

import (
    "bytes"

    "github.com/celestiaorg/rsmt2d"
)

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

    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(
        [][]byte{
            ones, twos,
            threes, fours,
        },
        codec,
        rsmt2d.NewDefaultTree,
    )
    if err != nil {
        // ComputeExtendedDataSquare failed
    }

    rowRoots, err := eds.RowRoots()
    if err != nil {
    // RowRoots failed
    }
    colRoots, err := eds.ColRoots()
    if err != nil {
    // ColRoots failed
    }

    flattened := eds.Flattened()

    // 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(
        rowRoots,
        colRoots,
    )
    if err != nil {
        // err contains information to construct a fraud proof
        // See extendeddatacrossword_test.go
    }
}

Contributing

  1. Install Go 1.24+
  2. Install golangci-lint

Helpful Commands

# Build the project
make build

# Run unit tests
make test

# Run benchmarks
make bench

# Run linter
make lint

Audits

Informal Systems audited rsmt2d v0.9.0 in Q2 of 2023. See informal-systems.pdf.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 87
Method 87
Struct 16
Interface 4
TypeAlias 1

Languages

Go100%

Modules by API surface

datasquare_test.go29 symbols
extendeddatasquare.go23 symbols
datasquare.go21 symbols
extendeddatasquare_test.go20 symbols
extendeddatacrossword_test.go17 symbols
extendeddatacrossword.go16 symbols
nmtbuffered_tree_test.go14 symbols
nmtwrapper_test.go12 symbols
tree.go11 symbols
codec_test.go11 symbols
leopard.go9 symbols
codecs.go7 symbols

For agents

$ claude mcp add rsmt2d \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page