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

Feat/api blob proofs #312

Merged
merged 13 commits into from
Dec 5, 2024
73 changes: 73 additions & 0 deletions cmd/api/handler/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import (
"context"
"encoding/base64"
"encoding/hex"
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v3/pkg/da"
"github.com/celestiaorg/go-square/v2/share"
"net/http"
"time"

"github.com/celenium-io/celestia-indexer/pkg/types"
"github.com/celestiaorg/go-square/v2"
sdk "github.com/dipdup-net/indexer-sdk/pkg/storage"

"github.com/celenium-io/celestia-indexer/cmd/api/handler/responses"
"github.com/celenium-io/celestia-indexer/internal/storage"
testsuite "github.com/celenium-io/celestia-indexer/internal/test_suite"
"github.com/celenium-io/celestia-indexer/pkg/node"
"github.com/celestiaorg/celestia-app/v3/pkg/proof"
"github.com/labstack/echo/v4"
)

Expand All @@ -27,6 +32,7 @@ type NamespaceHandler struct {
address storage.IAddress
blob node.DalApi
state storage.IState
node node.Api
indexerName string
}

Expand All @@ -38,6 +44,7 @@ func NewNamespaceHandler(
state storage.IState,
indexerName string,
blob node.DalApi,
node node.Api,
) *NamespaceHandler {
return &NamespaceHandler{
namespace: namespace,
Expand All @@ -47,6 +54,7 @@ func NewNamespaceHandler(
blob: blob,
state: state,
indexerName: indexerName,
node: node,
}
}

Expand Down Expand Up @@ -733,3 +741,68 @@ func (handler *NamespaceHandler) Rollups(c echo.Context) error {

return returnArray(c, response)
}

// BlobProofs godoc
//
// @Summary Get blob inclusion proofs
// @Description Returns blob inclusion proofs
// @Tags namespace
// @ID get-blob-proof
// @Param request body postBlobRequest true "Request body containing height, commitment and namespace hash"
// @Accept json
// @Produce json
// @Success 200 {object} responses.BlobLog
// @Failure 400 {object} Error
// @Router /blob/proofs [get]
func (handler *NamespaceHandler) BlobProofs(c echo.Context) error {
req, err := bindAndValidate[postBlobRequest](c)
if err != nil {
return badRequestError(c, err)
}

block, err := handler.node.Block(c.Request().Context(), req.Height)
if err != nil {
return handleError(c, err, handler.namespace)
}

dataSquare, err := square.Construct(
block.Block.Data.Txs.ToSliceOfBytes(),
appconsts.SquareSizeUpperBound(0),
appconsts.SubtreeRootThreshold(0),
)

if err != nil {
return internalServerError(c, err)
}

startBlobIndex, endBlobIndex, err := responses.GetBlobShareIndexes(dataSquare, req.Hash, req.Commitment)
if err != nil {
return internalServerError(c, err)
}
blobSharesRange := share.Range{
Start: startBlobIndex,
End: endBlobIndex,
}

eds, err := da.ExtendShares(share.ToBytes(dataSquare))
if err != nil {
return internalServerError(c, err)
}

namespaceBytes, err := base64.StdEncoding.DecodeString(req.Hash)
if err != nil {
return internalServerError(c, err)
}

namespace, err := share.NewNamespaceFromBytes(namespaceBytes)
if err != nil {
return internalServerError(c, err)
}

proofs, err := proof.NewShareInclusionProofFromEDS(eds, namespace, blobSharesRange)
if err != nil {
return handleError(c, err, handler.namespace)
}

return c.JSON(http.StatusOK, proofs.ShareProofs)
}
131 changes: 130 additions & 1 deletion cmd/api/handler/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/json"
"github.com/celestiaorg/celestia-app/v3/pkg/proof"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -25,6 +26,7 @@ import (
nodeTypes "github.com/celenium-io/celestia-indexer/pkg/node/types"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/suite"
tendermintTypes "github.com/tendermint/tendermint/types"
"go.uber.org/mock/gomock"
)

Expand All @@ -40,6 +42,62 @@ var (
}
testNamespaceId = "0000000000000000000000000000000000000000fc7443b155920156"
testNamespaceBase64 = "AAAAAAAAAAAAAAAAAAAAAAAAAAAA/HRDsVWSAVY="
testTxBytes = []byte{
0xa, 0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8, 0xce, 0x81, 0x5f, 0x87,
0x6c, 0x12, 0x4d, 0x48, 0x35, 0x95, 0x22, 0xf0, 0x85, 0x4d, 0x95, 0xd8, 0x7, 0x2e, 0xaf, 0xf0, 0xd3, 0x7d, 0x55,
0xbd, 0x11, 0x3, 0x20, 0x91, 0x1d, 0xd2, 0xad, 0x74, 0x3f, 0xf2, 0x37, 0xd4, 0x11, 0x64, 0x8a, 0xf, 0xe3, 0x2c,
0x6d, 0x74, 0xee, 0xc0, 0x60, 0x71, 0x6a, 0x2a, 0x74, 0x35, 0x2f, 0x6b, 0x1c, 0x43, 0x5b, 0x5d, 0x67, 0x0, 0xa8,
0xba, 0x1e, 0x76, 0xb4, 0xd8, 0x56, 0xb, 0xee, 0x8c, 0x3, 0x9c, 0x91, 0xd8, 0x8b, 0x48, 0x60, 0xca, 0xe7, 0x9b,
0x5, 0xd4, 0xb2, 0xd6, 0x56, 0xf0, 0xd3, 0x8d, 0x78, 0x56, 0xa2, 0xdd, 0x1a, 0x4, 0x42, 0x4c, 0x4f, 0x42}
)

// NamespaceTestSuite -
Expand All @@ -51,6 +109,7 @@ type NamespaceTestSuite struct {
address *mock.MockIAddress
state *mock.MockIState
blobReceiver *nodeMock.MockDalApi
node *nodeMock.MockApi
echo *echo.Echo
handler *NamespaceHandler
ctrl *gomock.Controller
Expand All @@ -67,7 +126,17 @@ func (s *NamespaceTestSuite) SetupSuite() {
s.rollups = mock.NewMockIRollup(s.ctrl)
s.state = mock.NewMockIState(s.ctrl)
s.blobReceiver = nodeMock.NewMockDalApi(s.ctrl)
s.handler = NewNamespaceHandler(s.namespaces, s.blobLogs, s.rollups, s.address, s.state, testIndexerName, s.blobReceiver)
s.node = nodeMock.NewMockApi(s.ctrl)
s.handler = NewNamespaceHandler(
s.namespaces,
s.blobLogs,
s.rollups,
s.address,
s.state,
testIndexerName,
s.blobReceiver,
s.node,
)
}

// TearDownSuite -
Expand Down Expand Up @@ -790,3 +859,63 @@ func (s *NamespaceTestSuite) TestBlobs() {
s.Require().EqualValues(testAddress, blob.Signer)
s.Require().EqualValues(testNamespace.Hash(), blob.Namespace)
}

func (s *NamespaceTestSuite) TestBlobProofs() {
commitment := "hozWHUsckMXdBhBO15TLrib4rOtpgNu/Hyu225gjFLI="
namespaceBase64 := "AAAAAAAAAAAAAAAAAAAAAAAAAAAAVklBAAAAAAA="
blockHeight := pkgTypes.Level(2892352)
txs := [][]byte{testTxBytes}

proofReq := map[string]any{
"hash": namespaceBase64,
"height": blockHeight,
"commitment": commitment,
}
stream := new(bytes.Buffer)
err := json.NewEncoder(stream).Encode(proofReq)
s.Require().NoError(err)

req := httptest.NewRequest(http.MethodPost, "/", stream)
rec := httptest.NewRecorder()
c := s.echo.NewContext(req, rec)
c.SetPath("/blob/proofs")

req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)

s.node.EXPECT().
Block(gomock.Any(), blockHeight).
Return(pkgTypes.ResultBlock{
Block: &pkgTypes.Block{
Data: pkgTypes.Data{
Txs: tendermintTypes.ToTxs(txs),
},
},
}, nil)

s.Require().NoError(s.handler.BlobProofs(c))
s.Require().Equal(http.StatusOK, rec.Code)

var proofs []*proof.NMTProof
err = json.NewDecoder(rec.Body).Decode(&proofs)
s.Require().NoError(err)
s.Require().EqualValues(2, len(proofs))
s.Require().EqualValues(1, proofs[0].Start)
s.Require().EqualValues(2, proofs[0].End)
s.Require().EqualValues(1, proofs[1].End)
s.Require().EqualValues(
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABJKmGf0yBpvzj9FXhOZbyVHBq1LBKP5eI34r38GvSPZ9",
base64.StdEncoding.EncodeToString(proofs[0].Nodes[0]),
)
s.Require().EqualValues(
"/////////////////////////////////////////////////////////////////////////////55b1xq+xbf5Olhxqwf4N8vvgExxFkjtgX4j/uCbESK9",
base64.StdEncoding.EncodeToString(proofs[0].Nodes[1]),
)
s.Require().EqualValues(
"//////////////////////////////////////7//////////////////////////////////////plEqgR/c4IAVkNdYRWOYOAESD4whneKR54Dz5Dfe4p2",
base64.StdEncoding.EncodeToString(proofs[1].Nodes[0]),
)
s.Require().EqualValues(
"/////////////////////////////////////////////////////////////////////////////9DUGO+QswnUItJQnpHTEz6nj13KfN9iuS9pG2tYF5tI",
base64.StdEncoding.EncodeToString(proofs[1].Nodes[1]),
)
}
83 changes: 82 additions & 1 deletion cmd/api/handler/responses/ods.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
package responses

import (
"bytes"
"encoding/base64"

"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
"github.com/celestiaorg/go-square/namespace"
"github.com/celestiaorg/go-square/shares"
"github.com/celestiaorg/go-square/v2/inclusion"
"github.com/celestiaorg/go-square/v2/share"
"github.com/pkg/errors"
"github.com/tendermint/tendermint/crypto/merkle"

_ "github.com/celestiaorg/go-square/v2/share"
"github.com/celestiaorg/rsmt2d"
)

Expand Down Expand Up @@ -88,3 +95,77 @@ func getNamespaceType(ns namespace.Namespace) NamespaceKind {
return DefaultNamespace
}
}

type sequence struct {
ns share.Namespace
shareVersion uint8
startShareIdx int
endShareIdx int
data []byte
sequenceLen uint32
signer []byte
}

func GetBlobShareIndexes(
shares []share.Share,
base64namespace string,
base64commitment string,
) (blobStartIndex, blobEndIndex int, err error) {
if len(shares) == 0 {
return 0, 0, errors.New("invalid shares length")

}
sequences := make([]sequence, 0)
namespaceBytes, err := base64.StdEncoding.DecodeString(base64namespace)
if err != nil {
return 0, 0, errors.Wrap(err, "decoding base64 namespace")
}

for shareIndex, s := range shares {
if !(s.Version() <= 1) {
return 0, 0, errors.New("unsupported share version")
}

if s.IsPadding() {
continue
}

if !bytes.Equal(s.Namespace().Bytes(), namespaceBytes) {
continue
}

if s.IsSequenceStart() {
sequences = append(sequences, sequence{
ns: s.Namespace(),
shareVersion: s.Version(),
startShareIdx: shareIndex,
endShareIdx: shareIndex,
data: s.RawData(),
sequenceLen: s.SequenceLen(),
signer: share.GetSigner(s),
})
} else {
if len(sequences) == 0 {
return 0, 0, errors.New("continuation share without a s start share")
}
aopoltorzhicky marked this conversation as resolved.
Show resolved Hide resolved
prev := &sequences[len(sequences)-1]
prev.data = append(prev.data, s.RawData()...)
prev.endShareIdx = shareIndex
}
}
for _, s := range sequences {
s.data = s.data[:s.sequenceLen]
blob, err := share.NewBlob(s.ns, s.data, s.shareVersion, s.signer)
if err != nil {
return 0, 0, errors.Wrap(err, "creating blob")
}
commitment, err := inclusion.CreateCommitment(blob, merkle.HashFromByteSlices, appconsts.SubtreeRootThreshold(0))
if err != nil {
return 0, 0, errors.Wrap(err, "creating commitment")
}
if base64.StdEncoding.EncodeToString(commitment) == base64commitment {
return s.startShareIdx, s.endShareIdx + 1, err
}
}
return 0, 0, err
}
Loading
Loading