Skip to content

Commit

Permalink
refactors and minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
epociask committed Jul 3, 2024
1 parent 96e0f74 commit 6d2a016
Show file tree
Hide file tree
Showing 8 changed files with 340 additions and 73 deletions.
11 changes: 1 addition & 10 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1354,17 +1354,8 @@ func (b *BatchPoster) maybePostSequencerBatch(ctx context.Context) (bool, error)
log.Info("Start to write data to eigenda: ", "data", hex.EncodeToString(sequencerMsg))
blobInfo, err = b.eigenDAWriter.Store(ctx, sequencerMsg)
if err != nil {
if config.DisableEigenDAFallbackStoreDataOnChain {
log.Warn("Falling back to storing data on chain", "err", err)
return false, errors.New("unable to post batch to EigenDA and fallback storing data on chain is disabled")
}
return false, err
}

//sequencerMsg, err = b.eigenDAWriter.Serialize(blobInfo)
// if err != nil {
// log.Warn("DaRef serialization failed", "err", err)
// return false, errors.New("DaRef serialization failed")
// }
}

data, kzgBlobs, err := b.encodeAddBatch(new(big.Int).SetUint64(batchPosition.NextSeqNum), batchPosition.MessageCount, b.building.msgCount, sequencerMsg, b.building.segments.delayedMsg, b.building.use4844, b.building.useEigenDA, blobInfo)
Expand Down
13 changes: 10 additions & 3 deletions cmd/replay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func (r *BlobPreimageReader) Initialize(ctx context.Context) error {
return nil
}

// struct for recovering data from preimage, impl interface EigenDAReader

// QueryBlob returns the blob for the given cert from the preimage oracle using the hash of the
// certificate kzg commitment for identifying the preimage.
func (dasReader *PreimageEigenDAReader) QueryBlob(ctx context.Context, cert *eigenda.EigenDABlobInfo, domain string) ([]byte, error) {
kzgCommit, err := cert.SerializeCommitment()
if err != nil {
Expand All @@ -166,7 +166,14 @@ func (dasReader *PreimageEigenDAReader) QueryBlob(ctx context.Context, cert *eig
return nil, err
}

return preimage, nil
// since the preimage is in encoded co-efficient form, we need to decode it to get the actual blob
// i.e,polynomial -> FFT -> length decode -> inverse onec -> blob
decodedBlob, err := eigenda.DecodeiFFTBlob(preimage)
if err != nil {
println("Error decoding blob: ", err)
return nil, err
}
return decodedBlob, nil
}

// To generate:
Expand Down
4 changes: 2 additions & 2 deletions deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func DeployOnL1(ctx context.Context, parentChainReader *headerreader.HeaderReade
return nil, fmt.Errorf("dummy manager deploy error: %w", err)
}

log.Info("Dummy manager deployed at ", dummyRollupManager.String())
log.Info("Dummy eigenda rollup manager deployed", "address", dummyRollupManager.String())
eigenDARollupManager = dummyRollupManager
}

Expand All @@ -264,7 +264,7 @@ func DeployOnL1(ctx context.Context, parentChainReader *headerreader.HeaderReade
return nil, fmt.Errorf("dummy svc manager deploy error: %w", err)
}

log.Info("Dummy service manager deployed at ", dummySvcManager.String())
log.Info("Dummy eigenda service manager", "address", dummySvcManager.String())
eigenDASvcManager = dummySvcManager

}
Expand Down
93 changes: 93 additions & 0 deletions eigenda/decoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package eigenda

import (
"bytes"
"encoding/binary"
"fmt"
"math"

"github.com/Layr-Labs/eigenda/encoding"

Check failure on line 9 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding; to add it:

Check failure on line 9 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding; to add it:

Check failure on line 9 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding; to add it:

Check failure on line 9 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding; to add it:

Check failure on line 9 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding; to add it:

Check failure on line 9 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding; to add it:

Check failure on line 9 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding; to add it:

Check failure on line 9 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding; to add it:

Check failure on line 9 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding; to add it:
"github.com/Layr-Labs/eigenda/encoding/fft"

Check failure on line 10 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding/fft; to add it:

Check failure on line 10 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding/fft; to add it:

Check failure on line 10 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding/fft; to add it:

Check failure on line 10 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding/fft; to add it:

Check failure on line 10 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding/fft; to add it:

Check failure on line 10 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding/fft; to add it:

Check failure on line 10 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding/fft; to add it:

Check failure on line 10 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding/fft; to add it:

Check failure on line 10 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding/fft; to add it:
"github.com/Layr-Labs/eigenda/encoding/rs"

Check failure on line 11 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding/rs; to add it:

Check failure on line 11 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding/rs; to add it:

Check failure on line 11 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding/rs; to add it:

Check failure on line 11 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding/rs; to add it:

Check failure on line 11 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding/rs; to add it:

Check failure on line 11 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding/rs; to add it:
"github.com/Layr-Labs/eigenda/encoding/utils/codec"

Check failure on line 12 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding/utils/codec; to add it:

Check failure on line 12 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (race)

no required module provides package github.com/Layr-Labs/eigenda/encoding/utils/codec; to add it:

Check failure on line 12 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding/utils/codec; to add it:

Check failure on line 12 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (defaults)

no required module provides package github.com/Layr-Labs/eigenda/encoding/utils/codec; to add it:

Check failure on line 12 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding/utils/codec; to add it:

Check failure on line 12 in eigenda/decoding.go

View workflow job for this annotation

GitHub Actions / Go Tests (challenge)

no required module provides package github.com/Layr-Labs/eigenda/encoding/utils/codec; to add it:
)

/*
These decodings are translated directly from core EigenDA client codec:
- https://github.com/Layr-Labs/eigenda/blob/44569ec461c9a1dd1191e7999a72e63bd1e7aba9/api/clients/codecs/ifft_codec.go#L27-L38
*/

func FFT(data []byte) ([]byte, error) {
dataFr, err := rs.ToFrArray(data)
if err != nil {
return nil, fmt.Errorf("error converting data to fr.Element: %w", err)
}
dataFrLen := uint64(len(dataFr))
dataFrLenPow2 := encoding.NextPowerOf2(dataFrLen)

if dataFrLenPow2 != dataFrLen {
return nil, fmt.Errorf("data length %d is not a power of 2", dataFrLen)
}

maxScale := uint8(math.Log2(float64(dataFrLenPow2)))

fs := fft.NewFFTSettings(maxScale)

dataFFTFr, err := fs.FFT(dataFr, false)
if err != nil {
return nil, fmt.Errorf("failed to perform FFT: %w", err)
}

return rs.ToByteArray(dataFFTFr, dataFrLenPow2*encoding.BYTES_PER_SYMBOL), nil
}

func DecodeiFFTBlob(data []byte) ([]byte, error) {
if len(data) == 0 {
return nil, fmt.Errorf("blob has length 0, meaning it is malformed")
}
var err error
data, err = FFT(data)
if err != nil {
return nil, fmt.Errorf("error FFTing data: %w", err)
}

return GenericDecodeBlob(data)
}

func GenericDecodeBlob(data []byte) ([]byte, error) {
if len(data) <= 32 {
return nil, fmt.Errorf("data is not of length greater than 32 bytes: %d", len(data))
}

data, err := DecodeBlob(data)
if err != nil {
return nil, err
}

return data, nil
}

func DecodeBlob(data []byte) ([]byte, error) {
if len(data) < 32 {
return nil, fmt.Errorf("blob does not contain 32 header bytes, meaning it is malformed")
}

length := binary.BigEndian.Uint32(data[2:6])

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

// get non blob header data
reader := bytes.NewReader(decodedData)
rawData := make([]byte, length)
n, err := reader.Read(rawData)
if err != nil {
return nil, fmt.Errorf("failed to copy unpadded data into final buffer, length: %d, bytes read: %d", length, n)
}
if uint32(n) != length {
return nil, fmt.Errorf("data length does not match length prefix")
}

return rawData, nil

}
11 changes: 9 additions & 2 deletions eigenda/eigenda.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ func NewEigenDA(proxyServerRpc string) (*EigenDA, error) {
func (e *EigenDA) QueryBlob(ctx context.Context, cert *EigenDABlobInfo, domainFilter string) ([]byte, error) {
log.Info("Querying blob from EigenDA")

data, err := e.client.Get(ctx, cert.ToDisperserBlobInfo(), domainFilter)
info, err := cert.ToDisperserBlobInfo()
if err != nil {
return nil, err
}

data, err := e.client.Get(ctx, info, domainFilter)
if err != nil {
return nil, err
}
Expand All @@ -71,13 +76,15 @@ func (e *EigenDA) QueryBlob(ctx context.Context, cert *EigenDABlobInfo, domainFi

// Store disperses a blob to EigenDA and returns the appropriate EigenDABlobInfo or certificate values
func (e *EigenDA) Store(ctx context.Context, data []byte) (*EigenDABlobInfo, error) {
log.Info("Dispersing blob to EigenDA")
log.Info("Dispersing blob to EigenDA", "data", hex.EncodeToString(data))
var blobInfo = &EigenDABlobInfo{}
cert, err := e.client.Put(ctx, data)
if err != nil {
return nil, err
}

log.Info("Received the following batch header from EigenDA", "batchHeader", cert.BlobVerificationProof.BatchMetadata)

blobInfo.LoadBlobInfo(cert)

return blobInfo, nil
Expand Down
Loading

0 comments on commit 6d2a016

Please sign in to comment.