Skip to content

Commit

Permalink
Update how FFT and IFFT are referred to
Browse files Browse the repository at this point in the history
Signed-off-by: litt3 <[email protected]>
  • Loading branch information
litt3 committed Jan 13, 2025
1 parent cf1cd80 commit 53893d8
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 124 deletions.
12 changes: 12 additions & 0 deletions api/clients/codecs/polynomial_form.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package codecs

// PolynomialForm is an enum that represents the different ways that a blob polynomial may be represented
type PolynomialForm uint

const (
// Eval is short for "evaluation form". The field elements represent the evaluation at the polynomial's expanded
// roots of unity
Eval PolynomialForm = iota
// Coeff is short for "coefficient form". The field elements represent the coefficients of the polynomial
Coeff
)
24 changes: 8 additions & 16 deletions api/clients/v2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,20 @@ import (
"github.com/Layr-Labs/eigenda/api/clients/codecs"
)

// VerificationMode is an enum that represents the different ways that a blob may be encoded/decoded between
// the client and the disperser.
type VerificationMode uint

const (
// TODO: write good docs here for IFFT and NoIFFT (I need to update my understanding to be able to write this)
IFFT VerificationMode = iota
NoIFFT
)

// EigenDAClientConfig contains configuration values for EigenDAClient
type EigenDAClientConfig struct {
// The blob encoding version to use when writing and reading blobs
BlobEncodingVersion codecs.BlobEncodingVersion

// If PointVerificationMode is IFFT, then the client codec will do an IFFT on blobs before they are dispersed, and
// will do an FFT on blobs after receiving them. This makes it possible to open points on the KZG commitment to prove
// that the field elements correspond to the commitment.
// BlobPolynomialForm is the form that the blob polynomial is commited to and dispersed in, as well as the form the
// blob polynomial will be received in from the relay.
//
// If PointVerificationMode is NoIFFT, the blob must be supplied in its entirety, to perform a verification
// that any part of the data matches the KZG commitment.
PointVerificationMode VerificationMode
// The chosen form dictates how the KZG commitment made to the blob can be used. If the polynomial is in Coeff form
// when committed to, then it will be possible to open points on the KZG commitment to prove that the field elements
// correspond to the commitment. If the polynomial is in Eval form when committed to, then it will not be possible
// to create a commitment opening: the blob will need to be supplied in its entirety to perform a verification that
// any part of the data matches the KZG commitment.
BlobPolynomialForm codecs.PolynomialForm

// The timeout duration for relay calls
RelayTimeout time.Duration
Expand Down
27 changes: 18 additions & 9 deletions api/clients/v2/eigenda_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/Layr-Labs/eigenda/api/clients/codecs"
core "github.com/Layr-Labs/eigenda/core/v2"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/consensys/gnark-crypto/ecc/bn254"
)

// EigenDAClient provides the ability to get blobs from the relay subsystem, and to send new blobs to the disperser.
Expand All @@ -21,6 +22,7 @@ type EigenDAClient struct {
config *EigenDAClientConfig
codec codecs.BlobCodec
relayClient RelayClient
g1Srs []bn254.G1Affine
}

// BuildEigenDAClient builds an EigenDAClient from config structs.
Expand Down Expand Up @@ -59,17 +61,17 @@ func NewEigenDAClient(
}, nil
}

// GetBlob iteratively attempts to retrieve a given blob with key blobKey from the relays listed in the blobCertificate.
// GetBlob iteratively attempts to retrieve a given blob with key blobKey from supplied relays.
//
// The relays are attempted in random order.
//
// The returned blob is decoded.
// IMPORTANT: The returned blob is NOT decoded and NOT verified
func (c *EigenDAClient) GetBlob(
ctx context.Context,
blobKey core.BlobKey,
blobCertificate core.BlobCertificate) ([]byte, error) {
relayKeys []core.RelayKey) ([]byte, error) {

relayKeyCount := len(blobCertificate.RelayKeys)
relayKeyCount := len(relayKeys)

if relayKeyCount == 0 {
return nil, errors.New("relay key count is zero")
Expand All @@ -82,7 +84,7 @@ func (c *EigenDAClient) GetBlob(

// iterate over relays in random order, until we are able to get the blob from someone
for _, val := range indices {
relayKey := blobCertificate.RelayKeys[val]
relayKey := relayKeys[val]

data, err := c.getBlobWithTimeout(ctx, relayKey, blobKey)

Expand Down Expand Up @@ -111,6 +113,8 @@ func (c *EigenDAClient) GetBlob(
return nil, fmt.Errorf("unable to retrieve blob from any relay. relay count: %d", relayKeyCount)
}

func (c *EigenDAClient) VerifyBlobCommitment(blob []byte)

// getBlobWithTimeout attempts to get a blob from a given relay, and times out based on config.RelayTimeout
func (c *EigenDAClient) getBlobWithTimeout(
ctx context.Context,
Expand Down Expand Up @@ -148,12 +152,17 @@ func createCodec(config *EigenDAClientConfig) (codecs.BlobCodec, error) {
return nil, fmt.Errorf("create low level codec: %w", err)
}

switch config.PointVerificationMode {
case NoIFFT:
switch config.BlobPolynomialForm {
case codecs.Eval:
// a blob polynomial is already in Eval form after being encoded. Therefore, we use the NoIFFTCodec, which
// doesn't do any further conversion.
return codecs.NewNoIFFTCodec(lowLevelCodec), nil
case IFFT:
case codecs.Coeff:
// a blob polynomial starts in Eval form after being encoded. Therefore, we use the IFFT codec to transform
// the blob into Coeff form after initial encoding. This codec also transforms the Coeff form received from the
// relay back into Eval form when decoding.
return codecs.NewIFFTCodec(lowLevelCodec), nil
default:
return nil, fmt.Errorf("unsupported point verification mode: %d", config.PointVerificationMode)
return nil, fmt.Errorf("unsupported polynomial form: %d", config.BlobPolynomialForm)
}
}
Loading

0 comments on commit 53893d8

Please sign in to comment.