Go implementation of two dimensional Reed-Solomon Merkle tree data availability scheme.
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
}
}This repository follows the Go version policy for Celestia libraries. Agents and contributors should keep it when they change go.mod or CI.
go.modrequires1.N.0, where1.Nis the oldest Go release that is still supported (todaygo 1.26.0). Do not raise it further unless a dependency needs it, and do not add atoolchainline. A library'sgodirective is the minimum for every module that imports it, so a higher value forces celestia-app, celestia-core and celestia-node to upgrade Go.- CI runs the tests on both supported Go releases (today 1.26 and 1.27). The job on the
go.modversion catches code that needs a newer release. - Coverage is uploaded from the newest Go release only. Go releases split code into coverage blocks differently, so mixing them moves the percentage without any change in tests.
- Fuzzing runs on the newest Go release. Under Go 1.26, a fuzz target that reaches the end of its
-fuzztimebudget fails with "context deadline exceeded" (golang/go#75804). - When Go releases a new major version, raise
go.modto the new oldest supported release (1.N+1.0) and move the CI versions up by one.
Applications (celestia-app, celestia-core, celestia-node) follow a different rule: they pin go.mod, CI and Docker images to one exact patch release of Go.
PR titles follow conventional commits and must start the subject with [high], [medium], or [low] to indicate the review thoroughness needed. For example: fix!: [high] correct repair of byzantine rows or docs: [low] clarify codec usage. Include the same tag in the PR description and explain why you chose it.
[high]: Deep review for consensus, security, or other changes with significant risk, e.g. erasure coding/codecs, extended data square construction, repair, or root computation.[medium]: Standard review for code changes with limited impact and well-understood behavior.[low]: Focused review for straightforward docs, tests, or tooling changes with low risk.
Choose the higher level when unsure. A small diff can still need deep review. CI checks the title format; reviewers should confirm the chosen level. Dependabot defaults to [high] for Go dependencies and [medium] for GitHub Actions. The required review policy documents how the tier sets the number of independent approvals.
# Build the project
make build
# Run unit tests
make test
# Run benchmarks
make bench
# Run each fuzz target for 30s (override with FUZZTIME=5m)
make fuzz
# Run linter
make lintmake fuzz runs each native Go fuzz target for FUZZTIME (default 30s). The
fuzz workflow runs every target for 60s on pull
requests and pushes, and for 10m nightly. A crashing input can describe an
exploitable bug, so outside pull requests the workflow prints only PASS or
FAIL. Outside pull requests, a failing target files a PROTOCO Linear issue (or comments on
the open one) with the output and the complete crashing corpus file. This needs
the LINEAR_API_KEY repository secret. To reproduce, save that file as
testdata/fuzz/<target>/<name> and run go test -run '^<target>$' .. Keep crash
details out of public PRs and issues.
Informal Systems audited rsmt2d v0.9.0 in Q2 of 2023. See informal-systems.pdf.