From 5db3daf06abf4e706127fff1ec6bcb80eca19341 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sun, 12 May 2024 21:29:45 -0400 Subject: [PATCH 1/5] feat(op-plasma-eigenda): Add support for commitment verification upon DA reads --- commitment.go | 56 ++++++++++++++++++++++++++++++++++++++++++++ commitment_test.go | 41 ++++++++++++++++++++++++++++++++ eigenda/cert.go | 15 +++++++++++- eigenda/cert_test.go | 28 ++++++++++++++++++++++ eigenda/client.go | 5 ++-- eigenda/config.go | 1 + go.mod | 9 +++++++ go.sum | 27 +++++++++++++++++++++ 8 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 commitment_test.go diff --git a/commitment.go b/commitment.go index ad349d50..0f5c9e04 100644 --- a/commitment.go +++ b/commitment.go @@ -3,8 +3,16 @@ package plasma import ( "bytes" "errors" + "fmt" + "runtime" + "github.com/Layr-Labs/eigenda/encoding/kzg" + "github.com/Layr-Labs/eigenda/encoding/kzg/prover" + "github.com/Layr-Labs/op-plasma-eigenda/eigenda" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rlp" + + eigen_enc "github.com/Layr-Labs/eigenda/encoding" ) // ErrInvalidCommitment is returned when the commitment cannot be parsed into a known commitment type. @@ -89,6 +97,54 @@ func (c EigenDACommitment) TxData() []byte { // TODO - verify the commitment against the input blob by evaluating its polynomial representation at an arbitrary point // and asserting that the generated output proof can be successfully verified against the commitment. func (c EigenDACommitment) Verify(input []byte) error { + var cert eigenda.Cert + if err := rlp.DecodeBytes(c, &cert); err != nil { + return err + } + + blob := eigenda.EncodeToBlob(input) + + kzgConfig := &kzg.KzgConfig{ + G1Path: "./kzg/g1.point", + G2Path: "./kzg/g2.point", + G2PowerOf2Path: "./kzg/g2.point.powerOf2", + CacheDir: "./kzg/SRSTables", + SRSOrder: 3000, + SRSNumberToLoad: 3000, + NumWorker: uint64(runtime.GOMAXPROCS(0)), + } + + prover, err := prover.NewProver(kzgConfig, true) + if err != nil { + return err + } + + params := eigen_enc.ParamsFromSysPar(6, 69, uint64(len(blob))) + encoder, err := prover.GetKzgEncoder(params) + if err != nil { + return err + } + + commit, _, _, _, _, err := encoder.EncodeBytes(blob) + if err != nil { + return err + } + + x, y := cert.BlobCommitmentFields() + xCommit := &commit.X + yCommit := &commit.Y + + println(fmt.Sprintf("%+b, %+b ", commit.X.Bits(), x.Bits())) + println(fmt.Sprintf("%+b, %+b ", commit.Y.Bits(), y.Bits())) + + if x.NotEqual(xCommit) != 0 { + return fmt.Errorf("x element mismatch %s:%s %s:%s", "gen_commit", xCommit.String(), "initial_commit", x.String()) + } + + if y.NotEqual(yCommit) != 0 { + return fmt.Errorf("x element mismatch %s:%s %s:%s", "gen_commit", yCommit.String(), "initial_commit", y.String()) + } + return nil } diff --git a/commitment_test.go b/commitment_test.go new file mode 100644 index 00000000..12f58540 --- /dev/null +++ b/commitment_test.go @@ -0,0 +1,41 @@ +package plasma + +import ( + "encoding/hex" + "fmt" + "testing" + + "github.com/Layr-Labs/eigenda/api/grpc/common" + "github.com/Layr-Labs/op-plasma-eigenda/eigenda" + "github.com/ethereum/go-ethereum/rlp" + "github.com/stretchr/testify/assert" +) + +func TestVerification(t *testing.T) { + + var data = []byte("inter-subjective and not objective!") + + x, err := hex.DecodeString("0b187c5351919a9bf83271637be3bcb7b8bbb0abe0b80bb9d632ad8f6e8401e5") + assert.NoError(t, err) + + y, err := hex.DecodeString("0d41ee143f13cc2526d36189a22538f630ea31398e0af32b5877728c8fe5452e") + assert.NoError(t, err) + + c := eigenda.Cert{ + BlobCommitment: &common.G1Commitment{ + X: x, + Y: y, + }, + } + + println(fmt.Sprintf("x: %+x", x)) + println(fmt.Sprintf("y: %+x", y)) + + b, err := rlp.EncodeToBytes(c) + assert.NoError(t, err) + + var commit EigenDACommitment = b + + err = commit.Verify(data) + assert.NoError(t, err) +} diff --git a/eigenda/cert.go b/eigenda/cert.go index a8e18428..c0a3cc4f 100644 --- a/eigenda/cert.go +++ b/eigenda/cert.go @@ -1,6 +1,9 @@ package eigenda -import "github.com/Layr-Labs/eigenda/api/grpc/common" +import ( + "github.com/Layr-Labs/eigenda/api/grpc/common" + "github.com/consensys/gnark-crypto/ecc/bn254/fp" +) // EigenDA finalized blob certificate type Cert struct { @@ -11,3 +14,13 @@ type Cert struct { // Used for kzg verification when reading blob data from DA BlobCommitment *common.G1Commitment } + +func (c *Cert) BlobCommitmentFields() (*fp.Element, *fp.Element) { + xBytes, yBytes := c.BlobCommitment.X, c.BlobCommitment.Y + xElement, yElement := &fp.Element{}, &fp.Element{} + + xElement.SetBytes(xBytes) + yElement.SetBytes(yBytes) + + return xElement, yElement +} diff --git a/eigenda/cert_test.go b/eigenda/cert_test.go index 1dba556c..ccbcafbc 100644 --- a/eigenda/cert_test.go +++ b/eigenda/cert_test.go @@ -2,6 +2,7 @@ package eigenda import ( "testing" + "unsafe" eigen_da_common "github.com/Layr-Labs/eigenda/api/grpc/common" "github.com/Layr-Labs/op-plasma-eigenda/common" @@ -39,3 +40,30 @@ func TestCertEncodingDecoding(t *testing.T) { assert.True(t, equal(), "values shouldn't change") } + +func ItoBSlice(i int) []byte { + data := *(*[unsafe.Sizeof(i)]byte)(unsafe.Pointer(&i)) + return data[:] +} + +func TestCommitmentToFieldElement(t *testing.T) { + xBytes, yBytes := []byte{0x69}, []byte{0x42} + println(xBytes) + println(yBytes) + + c := Cert{ + BatchHeaderHash: []byte{0x42, 0x69}, + BlobIndex: 420, + ReferenceBlockNumber: 80085, + QuorumIDs: []uint32{666}, + BlobCommitment: &eigen_da_common.G1Commitment{ + X: xBytes, + Y: yBytes, + }, + } + + x, y := c.BlobCommitmentFields() + + assert.Equal(t, uint64(0x69), x.Uint64()) + assert.Equal(t, uint64(0x42), y.Uint64()) +} diff --git a/eigenda/client.go b/eigenda/client.go index c5f9026d..80918eca 100644 --- a/eigenda/client.go +++ b/eigenda/client.go @@ -138,13 +138,14 @@ func (m *EigenDAClient) DisperseBlob(ctx context.Context, data []byte) (*Cert, e quorumIDs[i] = blobInfo.BlobHeader.BlobQuorumParams[i].QuorumNumber } - return &Cert{ + c := &Cert{ BatchHeaderHash: blobInfo.BlobVerificationProof.BatchMetadata.BatchHeaderHash, BlobIndex: blobInfo.BlobVerificationProof.BlobIndex, ReferenceBlockNumber: blobInfo.BlobVerificationProof.BatchMetadata.BatchHeader.ReferenceBlockNumber, QuorumIDs: quorumIDs, BlobCommitment: blobInfo.BlobHeader.Commitment, - }, nil + } + return c, nil default: return nil, fmt.Errorf("EigenDA blob dispersal failed in processing with reply status %d", statusRes.Status) } diff --git a/eigenda/config.go b/eigenda/config.go index 5c263b14..8008670f 100644 --- a/eigenda/config.go +++ b/eigenda/config.go @@ -39,6 +39,7 @@ func ReadConfig(ctx *cli.Context) Config { RPC: ctx.String(RPCFlagName), StatusQueryRetryInterval: ctx.Duration(StatusQueryRetryIntervalFlagName), StatusQueryTimeout: ctx.Duration(StatusQueryTimeoutFlagName), + UseTLS: ctx.Bool(UseTlsFlagName), } } diff --git a/go.mod b/go.mod index 70b9da68..836cd6e3 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/CloudyKit/jet/v6 v6.2.0 // indirect github.com/DataDog/zstd v1.5.2 // indirect github.com/Joker/jade v1.1.3 // indirect + github.com/Layr-Labs/eigensdk-go v0.1.6-0.20240414172936-84d5bc10f72f // indirect github.com/Microsoft/go-winio v0.6.1 // indirect github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 // indirect github.com/VictoriaMetrics/fastcache v1.12.1 // indirect @@ -38,6 +39,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.7 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.7 // indirect github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 // indirect + github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.5 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.28.6 // indirect @@ -70,12 +72,14 @@ require ( github.com/fjl/memsize v0.0.2 // indirect github.com/flosch/pongo2/v4 v4.0.2 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/fxamacker/cbor/v2 v2.5.0 // indirect github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect github.com/getsentry/sentry-go v0.18.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/gofrs/flock v0.8.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect @@ -153,12 +157,17 @@ require ( github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect + github.com/urfave/cli v1.22.14 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect + github.com/x448/float16 v0.8.4 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/yosssi/ace v0.0.5 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect + go.uber.org/automaxprocs v1.5.2 // indirect + go.uber.org/multierr v1.11.0 // indirect + go.uber.org/zap v1.27.0 // indirect golang.org/x/crypto v0.21.0 // indirect golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 // indirect golang.org/x/mod v0.16.0 // indirect diff --git a/go.sum b/go.sum index 2072968d..07dc5542 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/Layr-Labs/eigenda v0.7.0-rc.1.0.20240503180411-8ec570b8c2b2 h1:tPGJ7i github.com/Layr-Labs/eigenda v0.7.0-rc.1.0.20240503180411-8ec570b8c2b2/go.mod h1:49pIPHm61bjWtJytgUKi2hnaJPnTmeE58/r2Jea4F5M= github.com/Layr-Labs/eigenda/api v0.6.2 h1:ZrHYzdkOAonql+U8TUyR5OUXgciTgI2TEZ0E4koEbBI= github.com/Layr-Labs/eigenda/api v0.6.2/go.mod h1:kVXqWM13s/1hXyv9QdHweWAbKin9MeOBbS4i8c9rLbU= +github.com/Layr-Labs/eigensdk-go v0.1.6-0.20240414172936-84d5bc10f72f h1:WI6I4iDFu3cyhKCkdFUozWpNKBIvgCEl64yHNIh7MjE= +github.com/Layr-Labs/eigensdk-go v0.1.6-0.20240414172936-84d5bc10f72f/go.mod h1:HOSNuZcwaKbP4cnNk9c1hK2B2RitcMQ36Xj2msBBBpE= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06 h1:KkH3I3sJuOLP3TjA/dfr4NAY8bghDwnXiU7cTKxQqo0= @@ -56,6 +58,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5 h1:f9RyWNtS8oH7cZ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.5/go.mod h1:h5CoMZV2VF297/VLhRhO1WF+XYWOzXo+4HsObA4HjBQ= github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 h1:6cnno47Me9bRykw9AEv9zkXE+5or7jz8TsskTTccbgc= github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1/go.mod h1:qmdkIIAC+GCLASF7R2whgNrJADz0QZPX+Seiw/i4S3o= +github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.5 h1:1i3Pq5g1NaXI/u8lTHRVMHyCc0HoZzSk2EFmiy14Hbk= +github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.5/go.mod h1:slgOMs1CQu8UVgwoFqEvCi71L4HVoZgM0r8MtcNP6Mc= github.com/aws/aws-sdk-go-v2/service/sso v1.20.5 h1:vN8hEbpRnL7+Hopy9dzmRle1xmDc7o8tmY0klsr175w= github.com/aws/aws-sdk-go-v2/service/sso v1.20.5/go.mod h1:qGzynb/msuZIE8I75DVRCUXw3o3ZyBmUvMwQ2t/BrGM= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.4 h1:Jux+gDDyi1Lruk+KHF91tK2KCuY61kzoCpvtvJJBtOE= @@ -164,6 +168,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4 github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/fxamacker/cbor/v2 v2.5.0 h1:oHsG0V/Q6E/wqTS2O1Cozzsy69nqCiguo5Q1a1ADivE= +github.com/fxamacker/cbor/v2 v2.5.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2GihuqhwdILrV+7GJel5lyPV3u1+PgzrWLc0TkE= @@ -182,6 +188,8 @@ github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -378,6 +386,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= @@ -412,13 +422,18 @@ github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2 github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= @@ -439,6 +454,8 @@ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+F github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= +github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk= +github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA= github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= @@ -447,6 +464,10 @@ github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IU github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= +github.com/wealdtech/go-merkletree v1.0.1-0.20230205101955-ec7a95ea11ca h1:oK35INPN4CiubFw7ZPQkbxm2AsSU6Tjeb9YhciZnvIM= +github.com/wealdtech/go-merkletree v1.0.1-0.20230205101955-ec7a95ea11ca/go.mod h1:bM9mDSjsti+gkjl8FjovMoUH3MPR5bwJ3+ucaYFY0Jk= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= @@ -468,6 +489,12 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.uber.org/automaxprocs v1.5.2 h1:2LxUOGiR3O6tw8ui5sZa2LAaHnsviZdVOUZw4fvbnME= +go.uber.org/automaxprocs v1.5.2/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= From d31f0eb4775b5013b39ab8d7eef06dbf47db7823 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Tue, 14 May 2024 18:33:02 -0700 Subject: [PATCH 2/5] feat(eigenda-plasma): Commitment verification on read --- .gitignore | 2 +- README.md | 12 +++- cli.go | 1 - cmd/daserver/entrypoint.go | 15 ++++- commitment.go | 62 ------------------ daclient.go | 6 -- eigenda/cert.go | 5 +- eigenda/cert_test.go | 8 --- eigenda/config.go | 54 +++++++++++++++- store/eigenda.go | 15 ++++- test/e2e_test.go | 20 +++++- {kzg => test/resources}/g1.point | Bin {kzg => test/resources}/g2.point | Bin {kzg => test/resources}/g2.point.powerOf2 | Bin verify/verifier.go | 67 ++++++++++++++++++++ commitment_test.go => verify/verify_test.go | 23 ++++--- 16 files changed, 190 insertions(+), 100 deletions(-) rename {kzg => test/resources}/g1.point (100%) rename {kzg => test/resources}/g2.point (100%) rename {kzg => test/resources}/g2.point.powerOf2 (100%) create mode 100644 verify/verifier.go rename commitment_test.go => verify/verify_test.go (57%) diff --git a/.gitignore b/.gitignore index c4daede0..ed5158a7 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ go.work /bin ## kzg cache -kzg/SRSTables/ \ No newline at end of file +test/resources/SRSTables/ \ No newline at end of file diff --git a/README.md b/README.md index 707c733e..5b6b8b1b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Introduction -This simple DA server implementation supports ephemeral storage via EigenDA. +This simple DA server implementation supports ephemeral storage via EigenDA. ## EigenDA Configuration Additional cli args are provided for targeting an EigenDA network backend: @@ -10,10 +10,14 @@ Additional cli args are provided for targeting an EigenDA network backend: - `--eigenda-status-query-timeout`: (default: 25m) Duration for which a client will wait for a blob to finalize after being sent for dispersal. - `--eigenda-status-query-retry-interval`: (default: 5s) How often a client will attempt a retry when awaiting network blob finalization. - `--eigenda-use-tls`: (default: true) Whether or not to use TLS for grpc communication with disperser. +- `eigenda-g1-path`: Directory path to g1.point file +- `eigenda-g2-path`: Directory path to g2.point file +- `eigenda-g2-power-of-tau`: Directory path to g2.point.powerOf2 file +- `eigenda-cache-path`: Directory path to dump cached SRS tables ## Running Locally 1. Compile binary: `make da-server` -2. Run binary; e.g: `./bin/da-server --addr 127.0.0.1 --port 6969 --eigenda-rpc disperser-holesky.eigenda.xyz:443 --eigenda-status-query-timeout 45m` +2. Run binary; e.g: `./bin/da-server --addr 127.0.0.1 --port 5050 --eigenda-rpc 127.0.0.1:443 --eigenda-status-query-timeout 45m --eigenda-g1-path test/resources/g1.point --eigenda-g2-path test/resources/g2.point --eigenda-g2-tau-path test/resources/g2.point.powerOf2 --eigenda-use-tls true` ## Breaking changes from existing OP-Stack @@ -51,6 +55,10 @@ Some unit tests have been introduced to assert correctness of encoding/decoding Otherwise E2E tests (`test/e2e_test.go`) exists which asserts that a commitment can be generated when inserting some arbitrary data to the server and can be read using the commitment for a key lookup via the client. These can be ran via `make e2e-test`. Please **note** that this test uses the EigenDA Holesky network which is subject to rate-limiting and slow confirmation times *(i.e, >10 minutes per blob confirmation)*. Please advise EigenDA's [inabox](https://github.com/Layr-Labs/eigenda/tree/master/inabox#readme) if you'd like to spin-up a local DA network for quicker iteration testing. +## Generating SRS +KZG commitment verification requires constructing the SRS string from the proper trusted setup values (g1, g2, g2.power_of_tau). These values can be generated locally using the [srs_setup](https://github.com/Layr-Labs/eigenda-operator-setup/blob/master/srs_setup.sh) script in the operator setup repo. + + ## Resources - [op-stack](https://github.com/ethereum-optimism/optimism) - [plasma spec](https://specs.optimism.io/experimental/plasma.html) diff --git a/cli.go b/cli.go index a1d96f23..92164bd5 100644 --- a/cli.go +++ b/cli.go @@ -32,7 +32,6 @@ func CLIFlags(envPrefix string, category string) []cli.Flag { EnvVars: plasmaEnv(envPrefix, "DA_SERVER"), Category: category, }, - // This is currently unsupported &cli.BoolFlag{ Name: VerifyOnReadFlagName, Usage: "Verify input data matches the commitments from the DA storage service", diff --git a/cmd/daserver/entrypoint.go b/cmd/daserver/entrypoint.go index 3b4d232b..3b3598a8 100644 --- a/cmd/daserver/entrypoint.go +++ b/cmd/daserver/entrypoint.go @@ -8,6 +8,7 @@ import ( plasma "github.com/Layr-Labs/op-plasma-eigenda" "github.com/Layr-Labs/op-plasma-eigenda/eigenda" plasma_store "github.com/Layr-Labs/op-plasma-eigenda/store" + "github.com/Layr-Labs/op-plasma-eigenda/verify" oplog "github.com/ethereum-optimism/optimism/op-service/log" "github.com/ethereum-optimism/optimism/op-service/opio" ) @@ -25,7 +26,7 @@ func StartDAServer(cliCtx *cli.Context) error { log := oplog.NewLogger(oplog.AppOut(cliCtx), oplog.ReadCLIConfig(cliCtx)).New("role", "eigenda_plasma_server") oplog.SetGlobalLogHandler(log.Handler()) - log.Info("Initializing EigenDA Plasma DA server...") + log.Info("Initializing EigenDA Plasma DA server with config ...") var store plasma.PlasmaStore @@ -40,13 +41,21 @@ func StartDAServer(cliCtx *cli.Context) error { } store = s3 } else if cfg.EigenDAEnabled() { - log.Info("Using EigenDA storage", "RPC", cfg.EigenDAConfig.RPC) + daCfg := cfg.EigenDAConfig + log.Info("Using EigenDA storage", "RPC", daCfg.RPC) + + v, err := verify.NewVerifier(daCfg.KzgConfig()) + if err != nil { + return err + } + eigenda, err := plasma_store.NewEigenDAStore( cliCtx.Context, eigenda.NewEigenDAClient( log, - cfg.EigenDAConfig, + daCfg, ), + v, ) if err != nil { return fmt.Errorf("failed to create EigenDA store: %w", err) diff --git a/commitment.go b/commitment.go index 0f5c9e04..02ff9557 100644 --- a/commitment.go +++ b/commitment.go @@ -3,16 +3,8 @@ package plasma import ( "bytes" "errors" - "fmt" - "runtime" - "github.com/Layr-Labs/eigenda/encoding/kzg" - "github.com/Layr-Labs/eigenda/encoding/kzg/prover" - "github.com/Layr-Labs/op-plasma-eigenda/eigenda" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/rlp" - - eigen_enc "github.com/Layr-Labs/eigenda/encoding" ) // ErrInvalidCommitment is returned when the commitment cannot be parsed into a known commitment type. @@ -94,60 +86,6 @@ func (c EigenDACommitment) TxData() []byte { return append([]byte{TxDataVersion1}, c.Encode()...) } -// TODO - verify the commitment against the input blob by evaluating its polynomial representation at an arbitrary point -// and asserting that the generated output proof can be successfully verified against the commitment. -func (c EigenDACommitment) Verify(input []byte) error { - var cert eigenda.Cert - if err := rlp.DecodeBytes(c, &cert); err != nil { - return err - } - - blob := eigenda.EncodeToBlob(input) - - kzgConfig := &kzg.KzgConfig{ - G1Path: "./kzg/g1.point", - G2Path: "./kzg/g2.point", - G2PowerOf2Path: "./kzg/g2.point.powerOf2", - CacheDir: "./kzg/SRSTables", - SRSOrder: 3000, - SRSNumberToLoad: 3000, - NumWorker: uint64(runtime.GOMAXPROCS(0)), - } - - prover, err := prover.NewProver(kzgConfig, true) - if err != nil { - return err - } - - params := eigen_enc.ParamsFromSysPar(6, 69, uint64(len(blob))) - encoder, err := prover.GetKzgEncoder(params) - if err != nil { - return err - } - - commit, _, _, _, _, err := encoder.EncodeBytes(blob) - if err != nil { - return err - } - - x, y := cert.BlobCommitmentFields() - xCommit := &commit.X - yCommit := &commit.Y - - println(fmt.Sprintf("%+b, %+b ", commit.X.Bits(), x.Bits())) - println(fmt.Sprintf("%+b, %+b ", commit.Y.Bits(), y.Bits())) - - if x.NotEqual(xCommit) != 0 { - return fmt.Errorf("x element mismatch %s:%s %s:%s", "gen_commit", xCommit.String(), "initial_commit", x.String()) - } - - if y.NotEqual(yCommit) != 0 { - return fmt.Errorf("x element mismatch %s:%s %s:%s", "gen_commit", yCommit.String(), "initial_commit", y.String()) - } - - return nil -} - func DecodeEigenDACommitment(commitment []byte) (EigenDACommitment, error) { if len(commitment) <= 3 { return nil, ErrInvalidCommitment diff --git a/daclient.go b/daclient.go index cc82d0f9..58746464 100644 --- a/daclient.go +++ b/daclient.go @@ -47,13 +47,7 @@ func (c *DAClient) GetInput(ctx context.Context, comm EigenDACommitment) ([]byte if err != nil { return nil, err } - // TODO: Implement verification - if c.verify { - if err := comm.Verify(input); err != nil { - return nil, err - } - } return input, nil } diff --git a/eigenda/cert.go b/eigenda/cert.go index c0a3cc4f..43a25378 100644 --- a/eigenda/cert.go +++ b/eigenda/cert.go @@ -15,12 +15,13 @@ type Cert struct { BlobCommitment *common.G1Commitment } +// BlobCommitmentFields transforms commitment byte arrays to bn254 field elements func (c *Cert) BlobCommitmentFields() (*fp.Element, *fp.Element) { xBytes, yBytes := c.BlobCommitment.X, c.BlobCommitment.Y xElement, yElement := &fp.Element{}, &fp.Element{} - xElement.SetBytes(xBytes) - yElement.SetBytes(yBytes) + xElement.Unmarshal(xBytes) + yElement.Unmarshal(yBytes) return xElement, yElement } diff --git a/eigenda/cert_test.go b/eigenda/cert_test.go index ccbcafbc..299e436b 100644 --- a/eigenda/cert_test.go +++ b/eigenda/cert_test.go @@ -2,7 +2,6 @@ package eigenda import ( "testing" - "unsafe" eigen_da_common "github.com/Layr-Labs/eigenda/api/grpc/common" "github.com/Layr-Labs/op-plasma-eigenda/common" @@ -41,15 +40,8 @@ func TestCertEncodingDecoding(t *testing.T) { assert.True(t, equal(), "values shouldn't change") } -func ItoBSlice(i int) []byte { - data := *(*[unsafe.Sizeof(i)]byte)(unsafe.Pointer(&i)) - return data[:] -} - func TestCommitmentToFieldElement(t *testing.T) { xBytes, yBytes := []byte{0x69}, []byte{0x42} - println(xBytes) - println(yBytes) c := Cert{ BatchHeaderHash: []byte{0x42, 0x69}, diff --git a/eigenda/config.go b/eigenda/config.go index 8008670f..85c25aa1 100644 --- a/eigenda/config.go +++ b/eigenda/config.go @@ -2,8 +2,10 @@ package eigenda import ( "errors" + "runtime" "time" + "github.com/Layr-Labs/eigenda/encoding/kzg" opservice "github.com/ethereum-optimism/optimism/op-service" "github.com/urfave/cli/v2" ) @@ -13,6 +15,11 @@ const ( StatusQueryRetryIntervalFlagName = "eigenda-status-query-retry-interval" StatusQueryTimeoutFlagName = "eigenda-status-query-timeout" UseTlsFlagName = "eigenda-use-tls" + // Kzg flags + G1PathFlagName = "eigenda-g1-path" + G2PathFlagName = "eigenda-g2-path" + G2TauFlagName = "eigenda-g2-tau-path" + CachePathFlagName = "eigenda-cache-path" ) type Config struct { @@ -30,17 +37,42 @@ type Config struct { // UseTLS specifies whether the client should use TLS as a transport layer when connecting to disperser. UseTLS bool + + // KZG vars + CacheDir string + + G1Path string + G2Path string + + G2PowerOfTauPath string +} + +func (c *Config) KzgConfig() *kzg.KzgConfig { + return &kzg.KzgConfig{ + G1Path: c.G1Path, + G2Path: c.G2Path, + G2PowerOf2Path: c.G2PowerOfTauPath, + CacheDir: c.CacheDir, + SRSOrder: 3000, + SRSNumberToLoad: 3000, + NumWorker: uint64(runtime.GOMAXPROCS(0)), + } } // NewConfig parses the Config from the provided flags or environment variables. func ReadConfig(ctx *cli.Context) Config { - return Config{ + cfg := Config{ /* Required Flags */ RPC: ctx.String(RPCFlagName), StatusQueryRetryInterval: ctx.Duration(StatusQueryRetryIntervalFlagName), StatusQueryTimeout: ctx.Duration(StatusQueryTimeoutFlagName), UseTLS: ctx.Bool(UseTlsFlagName), + G1Path: ctx.String(G1PathFlagName), + G2Path: ctx.String(G2PathFlagName), + G2PowerOfTauPath: ctx.String(G2TauFlagName), + CacheDir: ctx.String(CachePathFlagName), } + return cfg } func (m Config) Check() error { @@ -81,5 +113,25 @@ func CLIFlags(envPrefix string) []cli.Flag { Value: true, EnvVars: prefixEnvVars("EIGENDA_GRPC_USE_TLS"), }, + &cli.StringFlag{ + Name: G1PathFlagName, + Usage: "Directory path to g1.point file", + EnvVars: prefixEnvVars("EIGENDA_KZG_G1_PATH"), + }, + &cli.StringFlag{ + Name: G2PathFlagName, + Usage: "Directory path to g2.point file", + EnvVars: prefixEnvVars("EIGENDA_KZG_G2_PATH"), + }, + &cli.StringFlag{ + Name: G2TauFlagName, + Usage: "Directory path to g2.point.powerOf2 file", + EnvVars: prefixEnvVars("EIGENDA_G2_TAU_PATH"), + }, + &cli.StringFlag{ + Name: CachePathFlagName, + Usage: "Directory path to SRS tables", + EnvVars: prefixEnvVars("EIGENDA_CACHE_PATH"), + }, } } diff --git a/store/eigenda.go b/store/eigenda.go index 61d4f0ed..20c66d27 100644 --- a/store/eigenda.go +++ b/store/eigenda.go @@ -5,16 +5,19 @@ import ( "fmt" "github.com/Layr-Labs/op-plasma-eigenda/eigenda" + "github.com/Layr-Labs/op-plasma-eigenda/verify" "github.com/ethereum/go-ethereum/rlp" ) type EigenDAStore struct { - client *eigenda.EigenDAClient + client *eigenda.EigenDAClient + verifier *verify.Verifier } -func NewEigenDAStore(ctx context.Context, client *eigenda.EigenDAClient) (*EigenDAStore, error) { +func NewEigenDAStore(ctx context.Context, client *eigenda.EigenDAClient, v *verify.Verifier) (*EigenDAStore, error) { return &EigenDAStore{ - client: client, + client: client, + verifier: v, }, nil } @@ -29,6 +32,12 @@ func (e EigenDAStore) Get(ctx context.Context, key []byte) ([]byte, error) { if err != nil { return nil, fmt.Errorf("EigenDA client failed to retrieve blob: %w", err) } + + err = e.verifier.Verify(cert, eigenda.EncodeToBlob(blob)) + if err != nil { + return nil, err + } + return blob, nil } diff --git a/test/e2e_test.go b/test/e2e_test.go index bc1165fb..84a7858f 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -4,12 +4,15 @@ import ( "context" "fmt" "os" + "runtime" "testing" "time" + "github.com/Layr-Labs/eigenda/encoding/kzg" plasma "github.com/Layr-Labs/op-plasma-eigenda" "github.com/Layr-Labs/op-plasma-eigenda/eigenda" "github.com/Layr-Labs/op-plasma-eigenda/store" + "github.com/Layr-Labs/op-plasma-eigenda/verify" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait" oplog "github.com/ethereum-optimism/optimism/op-service/log" "github.com/ethereum/go-ethereum/log" @@ -49,9 +52,23 @@ func createTestSuite(t *testing.T) (TestSuite, func()) { UseTLS: true, } + kzgCfg := &kzg.KzgConfig{ + G1Path: "../kzg/g1.point", + G2Path: "../kzg/g2.point", + G2PowerOf2Path: "../kzg/g2.point.powerOf2", + CacheDir: "../kzg/SRSTables", + SRSOrder: 3000, + SRSNumberToLoad: 3000, + NumWorker: uint64(runtime.GOMAXPROCS(0)), + } + client := eigenda.NewEigenDAClient(log, testCfg) + verifier, err := verify.NewVerifier(kzgCfg) + if err != nil { + panic(err) + } - daStore, err := store.NewEigenDAStore(ctx, client) + daStore, err := store.NewEigenDAStore(ctx, client, verifier) if err != nil { panic(err) } @@ -97,7 +114,6 @@ func TestE2EPutGetLogicForEigenDAStore(t *testing.T) { t.Log("Setting input data on plasma server...") commit, err := daClient.SetInput(ts.ctx, testPreimage) - assert.NoError(t, err) // 2 - fetch pre-image data from test plasma server diff --git a/kzg/g1.point b/test/resources/g1.point similarity index 100% rename from kzg/g1.point rename to test/resources/g1.point diff --git a/kzg/g2.point b/test/resources/g2.point similarity index 100% rename from kzg/g2.point rename to test/resources/g2.point diff --git a/kzg/g2.point.powerOf2 b/test/resources/g2.point.powerOf2 similarity index 100% rename from kzg/g2.point.powerOf2 rename to test/resources/g2.point.powerOf2 diff --git a/verify/verifier.go b/verify/verifier.go new file mode 100644 index 00000000..2133bcd0 --- /dev/null +++ b/verify/verifier.go @@ -0,0 +1,67 @@ +package verify + +import ( + "fmt" + + "github.com/Layr-Labs/eigenda/encoding/rs" + + "github.com/Layr-Labs/eigenda/encoding" + "github.com/Layr-Labs/eigenda/encoding/kzg" + "github.com/Layr-Labs/eigenda/encoding/kzg/prover" + "github.com/Layr-Labs/op-plasma-eigenda/eigenda" +) + +type Verifier struct { + cfg *kzg.KzgConfig + prover *prover.Prover +} + +func NewVerifier(cfg *kzg.KzgConfig) (*Verifier, error) { + + prover, err := prover.NewProver(cfg, true) + if err != nil { + return nil, err + } + + return &Verifier{ + cfg: cfg, + prover: prover, + }, nil +} + +// Verify regenerates a commitment from the blob and asserts equivalence +// to the commitment in the certificate +// TODO: Optimize implementation by opening a point on the commitment instead +func (v *Verifier) Verify(cert eigenda.Cert, blob []byte) error { + encoder, err := v.prover.GetKzgEncoder( + encoding.ParamsFromSysPar(6, 69, uint64(len(blob))), + ) + if err != nil { + return err + } + inputFr, err := rs.ToFrArray(blob) + if err != nil { + return err + } + + polyEvals, _, err := encoder.ExtendPolyEval(inputFr) + if err != nil { + return err + } + commit, err := encoder.Commit(polyEvals) + if err != nil { + return err + } + + x, y := cert.BlobCommitmentFields() + + if commit.X.NotEqual(x) == 0 { + return fmt.Errorf("x element mismatch %s:%s %s:%s", "gen_commit", x.String(), "initial_commit", x.String()) + } + + if commit.Y.NotEqual(y) == 0 { + return fmt.Errorf("x element mismatch %s:%s %s:%s", "gen_commit", y.String(), "initial_commit", y.String()) + } + + return nil +} diff --git a/commitment_test.go b/verify/verify_test.go similarity index 57% rename from commitment_test.go rename to verify/verify_test.go index 12f58540..b278f697 100644 --- a/commitment_test.go +++ b/verify/verify_test.go @@ -1,13 +1,13 @@ -package plasma +package verify import ( "encoding/hex" - "fmt" + "runtime" "testing" "github.com/Layr-Labs/eigenda/api/grpc/common" + "github.com/Layr-Labs/eigenda/encoding/kzg" "github.com/Layr-Labs/op-plasma-eigenda/eigenda" - "github.com/ethereum/go-ethereum/rlp" "github.com/stretchr/testify/assert" ) @@ -28,14 +28,19 @@ func TestVerification(t *testing.T) { }, } - println(fmt.Sprintf("x: %+x", x)) - println(fmt.Sprintf("y: %+x", y)) + kzgConfig := &kzg.KzgConfig{ + G1Path: "../test/resources/g1.point", + G2Path: "../test/resources/g2.point", + G2PowerOf2Path: "../test/resources/g2.point.powerOf2", + CacheDir: "../test/resources/SRSTables", + SRSOrder: 3000, + SRSNumberToLoad: 3000, + NumWorker: uint64(runtime.GOMAXPROCS(0)), + } - b, err := rlp.EncodeToBytes(c) + v, err := NewVerifier(kzgConfig) assert.NoError(t, err) - var commit EigenDACommitment = b - - err = commit.Verify(data) + err = v.Verify(c, eigenda.EncodeToBlob(data)) assert.NoError(t, err) } From 31be14034b3ab74cda361878942f469c9a312a3d Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Tue, 14 May 2024 18:34:37 -0700 Subject: [PATCH 3/5] feat(eigenda-plasma): Commitment verification on read - fix typo --- eigenda/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eigenda/config.go b/eigenda/config.go index 85c25aa1..5a4274cb 100644 --- a/eigenda/config.go +++ b/eigenda/config.go @@ -24,7 +24,7 @@ const ( type Config struct { // TODO(eigenlayer): Update quorum ID command-line parameters to support passing - // and arbitrary number of quorum IDs. + // an arbitrary number of quorum IDs. // RPC is the HTTP provider URL for the Data Availability node. RPC string From 8818f5bef34ac147a3423ff2bb9eede8417df0e8 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Tue, 14 May 2024 18:36:13 -0700 Subject: [PATCH 4/5] feat(eigenda-plasma): Commitment verification on read - rm dbug stmt --- cmd/daserver/entrypoint.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/daserver/entrypoint.go b/cmd/daserver/entrypoint.go index 3b3598a8..a454ed8b 100644 --- a/cmd/daserver/entrypoint.go +++ b/cmd/daserver/entrypoint.go @@ -42,7 +42,6 @@ func StartDAServer(cliCtx *cli.Context) error { store = s3 } else if cfg.EigenDAEnabled() { daCfg := cfg.EigenDAConfig - log.Info("Using EigenDA storage", "RPC", daCfg.RPC) v, err := verify.NewVerifier(daCfg.KzgConfig()) if err != nil { From 32a7e7f111e20e21b87ea56ad080a5a7183ad851 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Wed, 15 May 2024 13:53:59 -0700 Subject: [PATCH 5/5] feat(eigenda-plasma): Commitment verification on read - update srs fetching --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5b6b8b1b..b5cdf6b7 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,8 @@ Some unit tests have been introduced to assert correctness of encoding/decoding Otherwise E2E tests (`test/e2e_test.go`) exists which asserts that a commitment can be generated when inserting some arbitrary data to the server and can be read using the commitment for a key lookup via the client. These can be ran via `make e2e-test`. Please **note** that this test uses the EigenDA Holesky network which is subject to rate-limiting and slow confirmation times *(i.e, >10 minutes per blob confirmation)*. Please advise EigenDA's [inabox](https://github.com/Layr-Labs/eigenda/tree/master/inabox#readme) if you'd like to spin-up a local DA network for quicker iteration testing. -## Generating SRS -KZG commitment verification requires constructing the SRS string from the proper trusted setup values (g1, g2, g2.power_of_tau). These values can be generated locally using the [srs_setup](https://github.com/Layr-Labs/eigenda-operator-setup/blob/master/srs_setup.sh) script in the operator setup repo. +## Downloading SRS +KZG commitment verification requires constructing the SRS string from the proper trusted setup values (g1, g2, g2.power_of_tau). These values can be downloaded locally using the [srs_setup](https://github.com/Layr-Labs/eigenda-operator-setup/blob/master/srs_setup.sh) script in the operator setup repo. ## Resources