Skip to content

Commit

Permalink
Add GetPolynomialForm method
Browse files Browse the repository at this point in the history
Signed-off-by: litt3 <102969658+litt3@users.noreply.github.com>
  • Loading branch information
litt3 committed Jan 14, 2025
1 parent 85c558a commit 366627c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 4 additions & 6 deletions api/clients/codecs/blob_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ const (
func EncodePayload(payload []byte) []byte {
payloadHeader := make([]byte, 32)
// first byte is always 0 to ensure the payloadHeader is a valid bn254 element
// encode version byte
payloadHeader[1] = byte(DefaultBlobEncoding)
payloadHeader[1] = byte(DefaultBlobEncoding) // encode version byte

// encode payload length as uint32
binary.BigEndian.PutUint32(
payloadHeader[2:6],
uint32(len(payload))) // uint32 should be more than enough to store the length (approx 4gb)

// encode payload modulo bn254
// the resulting bytes are subsequently treated as the evaluation of a polynomial
// the resulting bytes subsequently may be treated as the evaluation of a polynomial
polynomialEval := codec.ConvertByPaddingEmptyByte(payload)

encodedPayload := append(payloadHeader, polynomialEval...)
Expand All @@ -56,10 +55,9 @@ func DecodePayload(encodedPayload []byte) ([]byte, error) {
payloadLength := binary.BigEndian.Uint32(encodedPayload[2:6])

// decode raw data modulo bn254
decodedData := codec.RemoveEmptyByteFromPaddedBytes(encodedPayload[32:])
nonPaddedData := codec.RemoveEmptyByteFromPaddedBytes(encodedPayload[32:])

// get non blob header data
reader := bytes.NewReader(decodedData)
reader := bytes.NewReader(nonPaddedData)
payload := make([]byte, payloadLength)
readLength, err := reader.Read(payload)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions api/clients/eigenda_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
type IEigenDAClient interface {
GetBlob(ctx context.Context, batchHeaderHash []byte, blobIndex uint32) ([]byte, error)
PutBlob(ctx context.Context, txData []byte) (*grpcdisperser.BlobInfo, error)
GetPolynomialForm() codecs.PolynomialForm
Close() error
}

Expand Down Expand Up @@ -131,6 +132,14 @@ func NewEigenDAClient(log log.Logger, config EigenDAClientConfig) (*EigenDAClien
}, nil
}

// GetPolynomialForm returns the form of polynomials, as they are distributed in the system
//
// The polynomial form indicates how blobs must be constructed before dispersal, and how received blobs ought to be
// interpreted.
func (m *EigenDAClient) GetPolynomialForm() codecs.PolynomialForm {
return m.PolynomialForm
}

// GetBlob retrieves a blob from the EigenDA service using the provided context,
// batch header hash, and blob index. If decode is set to true, the function
// decodes the retrieved blob data. If set to false it returns the encoded blob
Expand Down

0 comments on commit 366627c

Please sign in to comment.