Skip to content

Commit

Permalink
add features to allow da node to load only 28 g2 points
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Feb 6, 2024
1 parent 06788ff commit 340cae9
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 9 deletions.
17 changes: 17 additions & 0 deletions core/encoding/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
PreloadEncoderFlagName = "kzg.preload-encoder"
CacheEncodedBlobsFlagName = "cache-encoded-blobs"
SRSLoadingNumberFlagName = "kzg.srs-load"
G1PowerOf2PathFlagName = "kzg.g1-power-of-2-path"
G2PowerOf2PathFlagName = "kzg.g2-power-of-2-path"
)

func CLIFlags(envPrefix string) []cli.Flag {
Expand Down Expand Up @@ -77,6 +79,18 @@ func CLIFlags(envPrefix string) []cli.Flag {
Required: false,
EnvVar: common.PrefixEnvVar(envPrefix, "PRELOAD_ENCODER"),
},
cli.StringFlag{
Name: G1PowerOf2PathFlagName,
Usage: "Path to G1 SRS points that are on power of 2",
Required: false,
EnvVar: common.PrefixEnvVar(envPrefix, "G1_POWER_OF_2_PATH"),
},
cli.StringFlag{
Name: G2PowerOf2PathFlagName,
Usage: "Path to G2 SRS points that are on power of 2",
Required: false,
EnvVar: common.PrefixEnvVar(envPrefix, "G2_POWER_OF_2_PATH"),
},
}
}

Expand All @@ -90,6 +104,9 @@ func ReadCLIConfig(ctx *cli.Context) EncoderConfig {
cfg.NumWorker = ctx.GlobalUint64(NumWorkerFlagName)
cfg.Verbose = ctx.GlobalBool(VerboseFlagName)
cfg.PreloadEncoder = ctx.GlobalBool(PreloadEncoderFlagName)
cfg.G1PowerOf2Path = ctx.GlobalString(G1PowerOf2PathFlagName)
cfg.G2PowerOf2Path = ctx.GlobalString(G2PowerOf2PathFlagName)

return EncoderConfig{
KzgConfig: cfg,
CacheEncodedBlobs: ctx.GlobalBoolT(CacheEncodedBlobsFlagName),
Expand Down
2 changes: 1 addition & 1 deletion inabox/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func (env *Config) generateOperatorVars(ind int, name, key, churnerUrl, logPath,
NODE_EXPIRATION_POLL_INTERVAL: "10",
NODE_G1_PATH: "",
NODE_G2_PATH: "",
NODE_G2_POWER_OF_2_PATH: "",
NODE_CACHE_PATH: "",
NODE_SRS_ORDER: "",
NODE_SRS_LOAD: "",
Expand All @@ -315,7 +316,6 @@ func (env *Config) generateOperatorVars(ind int, name, key, churnerUrl, logPath,
}

env.applyDefaults(&v, "NODE", "opr", ind)

return v

}
Expand Down
4 changes: 4 additions & 0 deletions inabox/deploy/env_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ type OperatorVars struct {

NODE_G2_PATH string

NODE_G1_POWER_OF_2_PATH string

NODE_G2_POWER_OF_2_PATH string

NODE_CACHE_PATH string

NODE_SRS_ORDER string
Expand Down
Binary file added inabox/resources/kzg/g2.point.powerOf2
Binary file not shown.
1 change: 1 addition & 0 deletions inabox/templates/testconfig-anvil-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
CHAIN_ID: 40525
G1_PATH: resources/kzg/g1.point
G2_PATH: resources/kzg/g2.point
G2_POWER_OF_2_PATH: resources/kzg/g2.point.powerOf2
CACHE_PATH: resources/kzg/SRSTables
SRS_ORDER: 3000
SRS_LOAD: 2900
Expand Down
1 change: 1 addition & 0 deletions inabox/templates/testconfig-anvil-nochurner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
CHAIN_ID: 40525
G1_PATH: resources/kzg/g1.point
G2_PATH: resources/kzg/g2.point
G2_POWER_OF_2_PATH: resources/kzg/g2.point.powerOf2
CACHE_PATH: resources/kzg/SRSTables
SRS_ORDER: 3000
SRS_LOAD: 2900
Expand Down
1 change: 1 addition & 0 deletions inabox/templates/testconfig-anvil-nograph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
CHAIN_ID: 40525
G1_PATH: resources/kzg/g1.point
G2_PATH: resources/kzg/g2.point
G2_POWER_OF_2_PATH: resources/kzg/g2.point.powerOf2
CACHE_PATH: resources/kzg/SRSTables
SRS_ORDER: 3000
SRS_LOAD: 2900
Expand Down
1 change: 1 addition & 0 deletions inabox/templates/testconfig-anvil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
CHAIN_ID: 40525
G1_PATH: resources/kzg/g1.point
G2_PATH: resources/kzg/g2.point
G2_POWER_OF_2_PATH: resources/kzg/g2.point.powerOf2
CACHE_PATH: resources/kzg/SRSTables
SRS_ORDER: 3000
SRS_LOAD: 2900
Expand Down
1 change: 1 addition & 0 deletions inabox/templates/testconfig-docker-anvil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ services:
CHAIN_ID: 40525
G1_PATH: /data/kzg/g1.point
G2_PATH: /data/kzg/g2.point
G2_POWER_OF_2_PATH: resources/kzg/g2.point.powerOf2
CACHE_PATH: /data/kzg/SRSTables
SRS_ORDER: 3000
SRS_LOAD: 2000
Expand Down
1 change: 1 addition & 0 deletions inabox/templates/testconfig-geth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ services:
CHAIN_ID: 40525
G1_PATH: resources/kzg/g1.point
G2_PATH: resources/kzg/g2.point
G2_POWER_OF_2_PATH: resources/kzg/g2.point.powerOf2
CACHE_PATH: resources/kzg/SRSTables
SRS_ORDER: 3000
SRS_LOAD: 3000
Expand Down
21 changes: 21 additions & 0 deletions pkg/encoding/kzgEncoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
type KzgConfig struct {
G1Path string
G2Path string
G1PowerOf2Path string
G2PowerOf2Path string
CacheDir string
NumWorker uint64
SRSOrder uint64 // Order is the total size of SRS
Expand Down Expand Up @@ -153,6 +155,25 @@ func ReadG2Point(n uint64, g *KzgConfig) (bls.G2Point, error) {
return g2point[0], nil
}

// Read g2 points from power of 2 file
func ReadG2PointOnPowerOf2(exponent uint64, g *KzgConfig) (bls.G2Point, error) {

power := uint64(math.Pow(2, float64(exponent)))
if power > g.SRSOrder {
return bls.G2Point{}, fmt.Errorf("requested power %v is larger than SRSOrder %v", power, g.SRSOrder)
}

if len(g.G2PowerOf2Path) == 0 {
return bls.G2Point{}, fmt.Errorf("G2PathPowerOf2 path is empty")
}

g2point, err := utils.ReadG2PointSection(g.G2PowerOf2Path, exponent, exponent+1, 1)
if err != nil {
return bls.G2Point{}, err
}
return g2point[0], nil
}

func (g *KzgEncoderGroup) PreloadAllEncoders() error {
paramsAll, err := GetAllPrecomputedSrsMap(g.CacheDir)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions pkg/encoding/kzgEncoder/encoder_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ func setupSuite(t *testing.T) func(t *testing.T) {
log.Println("Setting up suite")

kzgConfig = &kzgRs.KzgConfig{
G1Path: "../../../inabox/resources/kzg/g1.point",
G2Path: "../../../inabox/resources/kzg/g2.point",
CacheDir: "../../../inabox/resources/kzg/SRSTables",
SRSOrder: 3000,
SRSNumberToLoad: 2900,
NumWorker: uint64(runtime.GOMAXPROCS(0)),
G1Path: "../../../inabox/resources/kzg/g1.point",
G2Path: "../../../inabox/resources/kzg/g2.point",
G2PowerOf2Path: "../../../inabox/resources/kzg/g2.point.powerOf2",
CacheDir: "../../../inabox/resources/kzg/SRSTables",
SRSOrder: 3000,
SRSNumberToLoad: 2900,
NumWorker: uint64(runtime.GOMAXPROCS(0)),
}

numNode = uint64(4)
Expand Down
13 changes: 11 additions & 2 deletions pkg/encoding/kzgEncoder/multiframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/gob"
"errors"
"fmt"
"math"

rs "github.com/Layr-Labs/eigenda/pkg/encoding/encoder"
kzg "github.com/Layr-Labs/eigenda/pkg/kzg"
Expand Down Expand Up @@ -199,10 +200,18 @@ func (group *KzgEncoderGroup) UniversalVerify(params rs.EncodingParams, samples
lhsG1 := bls.LinCombG1(proofs, randomsFr)

// lhs g2
G2atD, err := ReadG2Point(D, group.KzgConfig)
exponent := uint64(math.Log2(float64(D)))
G2atD, err := ReadG2PointOnPowerOf2(exponent, group.KzgConfig)

if err != nil {
return err
// then try to access if there is a full list of g2 srs
G2atD, err = ReadG2Point(D, group.KzgConfig)
if err != nil {
return err
}
fmt.Println("Acessed the entire G2")
}

lhsG2 := &G2atD

// rhs g2
Expand Down

0 comments on commit 340cae9

Please sign in to comment.