From c68fa8c56ad73fe36b1672d9d831a73912f748aa Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sat, 8 Jun 2024 13:44:38 -0400 Subject: [PATCH 1/6] feat: Proxy client --- client/client.go | 116 +++++++++++++++++++++++++++++++++++++++++++++++ common/common.go | 17 +++++++ go.mod | 15 ++++++ go.sum | 52 +++++++++++++++++++++ operator-setup | 2 +- test/e2e_test.go | 50 +++++++++++++++++++- 6 files changed, 249 insertions(+), 3 deletions(-) create mode 100644 client/client.go diff --git a/client/client.go b/client/client.go new file mode 100644 index 00000000..3d42759e --- /dev/null +++ b/client/client.go @@ -0,0 +1,116 @@ +package client + +import ( + "bytes" + "context" + "fmt" + "io" + "net/http" + + "github.com/Layr-Labs/eigenda-proxy/common" + "github.com/Layr-Labs/eigenda-proxy/eigenda" + "github.com/ethereum/go-ethereum/rlp" +) + +type Config struct { + URL string +} + +type ProxyClient interface { + Health() error + GetData(ctx context.Context, blobInfo *common.BlobInfo, domain common.DomainType) ([]byte, error) + SetData(ctx context.Context, b []byte) (*common.BlobInfo, error) +} + +type client struct { + cfg *Config + httpClient *http.Client +} + +func New(cfg *Config) ProxyClient { + return &client{ + cfg, + http.DefaultClient, + } +} + +func (c *client) Health() error { + url := c.cfg.URL + "/health" + req, err := http.NewRequest(http.MethodGet, url, nil) + if err != nil { + return err + } + + resp, err := c.httpClient.Do(req) + if err != nil { + return err + } + + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("received bad status code: %d", resp.StatusCode) + } + + return nil +} + +func (c *client) GetData(ctx context.Context, info *common.BlobInfo, domain common.DomainType) ([]byte, error) { + b, err := rlp.EncodeToBytes(info) + if err != nil { + return nil, err + } + + b = eigenda.Commitment(b).Encode() + b = append([]byte{byte(0x1)}, b...) + + url := fmt.Sprintf("%s/get/0x%x?domain=%s", c.cfg.URL, b, domain.String()) + + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + if err != nil { + return nil, fmt.Errorf("failed to construct http request: %e", err) + } + + resp, err := c.httpClient.Do(req) + if err != nil { + return nil, err + } + + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("received unexpected response code: %d", resp.StatusCode) + } + + return io.ReadAll(resp.Body) +} + +func (c *client) SetData(ctx context.Context, b []byte) (*common.BlobInfo, error) { + body := bytes.NewReader(b) + url := fmt.Sprintf("%s/put/", c.cfg.URL) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, body) + if err != nil { + return nil, fmt.Errorf("failed to create HTTP request: %w", err) + } + req.Header.Set("Content-Type", "application/octet-stream") + resp, err := http.DefaultClient.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("failed to store data: %v", resp.StatusCode) + } + + b, err = io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + b = b[2:] + + var blob *common.BlobInfo + if err = rlp.DecodeBytes(b, &blob); err != nil { + return nil, err + } + + return blob, err +} diff --git a/common/common.go b/common/common.go index b3507d68..f53254dd 100644 --- a/common/common.go +++ b/common/common.go @@ -4,12 +4,16 @@ import ( "fmt" "strconv" "strings" + + "github.com/Layr-Labs/eigenda/api/grpc/disperser" ) var ( ErrInvalidDomainType = fmt.Errorf("invalid domain type") ) +type BlobInfo = disperser.BlobInfo + // DomainType is a enumeration type for the different data domains for which a // blob can exist between type DomainType uint8 @@ -20,6 +24,19 @@ const ( UnknownDomain ) +func (dt DomainType) String() string { + switch dt { + case BinaryDomain: + return "binary" + + case PolyDomain: + return "polynomial" + + default: + return "unknown" + } +} + func StrToDomainType(s string) DomainType { switch s { case "binary": diff --git a/go.mod b/go.mod index db31b023..f1f4c29e 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,8 @@ require ( github.com/DataDog/zstd v1.5.2 // indirect github.com/Layr-Labs/eigensdk-go v0.1.7-0.20240507215523-7e4891d5099a // indirect github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/VictoriaMetrics/fastcache v1.12.1 // indirect + github.com/andybalholm/brotli v1.1.0 // indirect github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect github.com/aws/aws-sdk-go-v2/config v1.27.11 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.17.11 // indirect @@ -35,7 +37,10 @@ require ( github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect + github.com/btcsuite/btcd v0.24.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect + github.com/btcsuite/btcd/btcutil v1.1.5 // indirect + github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cockroachdb/errors v1.11.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect @@ -49,6 +54,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/deckarep/golang-set/v2 v2.1.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect + github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3 // indirect github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240522134500-19555bdbdc95 // indirect github.com/ethereum/c-kzg-4844 v1.0.0 // indirect github.com/fjl/memsize v0.0.2 // indirect @@ -56,6 +62,7 @@ require ( github.com/fxamacker/cbor/v2 v2.5.0 // indirect github.com/gammazero/deque v0.2.0 // indirect github.com/gammazero/workerpool v1.1.3 // 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 @@ -67,8 +74,12 @@ require ( github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/websocket v1.5.1 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-bexpr v0.1.11 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect + github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 // indirect + github.com/holiman/bloomfilter/v2 v2.0.3 // indirect github.com/holiman/uint256 v1.2.4 // indirect github.com/huin/goupnp v1.3.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect @@ -114,10 +125,13 @@ require ( github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect + github.com/status-im/keycard-go v0.2.0 // indirect + github.com/stretchr/objx v0.5.2 // indirect github.com/supranational/blst v0.3.11 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect 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/wealdtech/go-merkletree v1.0.1-0.20230205101955-ec7a95ea11ca // indirect github.com/x448/float16 v0.8.4 // indirect @@ -134,6 +148,7 @@ require ( golang.org/x/sys v0.20.0 // indirect golang.org/x/term v0.20.0 // indirect golang.org/x/text v0.15.0 // indirect + golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.20.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect google.golang.org/grpc v1.59.0 // indirect diff --git a/go.sum b/go.sum index b075c655..9c5d5854 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,12 @@ github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEV github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40= github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o= +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= +github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/allegro/bigcache v1.2.1 h1:hg1sY1raCwic3Vnsvje6TT7/pnZba83LeFck5NrFKSc= +github.com/allegro/bigcache v1.2.1/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= +github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= +github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA= github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.1 h1:gTK2uhtAPtFcdRRJilZPx8uJLL2J85xK11nKtWL0wfU= @@ -76,11 +82,32 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bits-and-blooms/bitset v1.10.0 h1:ePXTeiPEazB5+opbv5fr8umg2R/1NlzgDsyepwsSr88= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= +github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= +github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A= github.com/btcsuite/btcd v0.24.0 h1:gL3uHE/IaFj6fcZSu03SvqPMSx7s/dPzfpG/atRwWdo= +github.com/btcsuite/btcd v0.24.0/go.mod h1:K4IDc1593s8jKXIF7yS7yCTSxrknB9z0STzc2j6XgE4= +github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= +github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= github.com/btcsuite/btcd/btcec/v2 v2.2.0 h1:fzn1qaOt32TuLjFlkzYSsBC35Q3KUjT1SwPxiMSCF5k= github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= +github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A= +github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE= +github.com/btcsuite/btcd/btcutil v1.1.5 h1:+wER79R5670vs/ZusMTF1yTcRYE5GUsFbdjdisflzM8= +github.com/btcsuite/btcd/btcutil v1.1.5/go.mod h1:PSZZ4UitpLBWzxGd5VGOrLnmOjtPP/a6HaFo12zMs00= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ= github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk= @@ -121,15 +148,19 @@ github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJ github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI= github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0= github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= github.com/docker/cli v25.0.3+incompatible h1:KLeNs7zws74oFuVhgZQ5ONGZiXUUdgsdy6/EsX/6284= @@ -140,6 +171,8 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3 h1:RWHKLhCrQThMfch+QJ1Z8veEq5ZO3DfIhZ7xgRP9WTc= +github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3/go.mod h1:QziizLAiF0KqyLdNJYD7O5cpDlaFMNZzlxYNcWsJUxs= github.com/ethereum-optimism/op-geth v1.101315.1-rc.4 h1:8kKEkKIpEiDA1yJfrOO473Tyz4nGgSJHpyK1I0fbPDo= github.com/ethereum-optimism/op-geth v1.101315.1-rc.4/go.mod h1:TtEUbMSmnt2jrnmxAG0n7tj6ujmcBJ+TKkmU56+NMMw= github.com/ethereum-optimism/optimism v1.7.6 h1:iwbO47lwa6vi5gQA0Lbnf/uOzmqXFHvXgmziLtVMbwM= @@ -219,8 +252,10 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3 github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-bexpr v0.1.11 h1:6DqdA/KBjurGby9yTY0bmkathya0lfwF2SeuubCI7dY= @@ -255,12 +290,16 @@ github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+ github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA= github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o= github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc= @@ -342,13 +381,17 @@ github.com/nxadm/tail v1.4.11/go.mod h1:OTaG3NK980DZzxbRq6lEuzgU+mug70nY11sMd4JX github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY= github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM= +github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= @@ -411,6 +454,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS 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.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= @@ -421,6 +465,7 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a h1:1ur3QoCqvE5fl+nylMaIr9PVV1w343YRDtsy+Rwu7XI= github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48= github.com/testcontainers/testcontainers-go v0.30.0 h1:jmn/XS22q4YRrcMwWg0pAwlClzs/abopbsBzrepyc4E= @@ -469,6 +514,7 @@ 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= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -480,11 +526,13 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -507,6 +555,8 @@ golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -528,6 +578,7 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= @@ -569,6 +620,7 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXL gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/operator-setup b/operator-setup index 10b5eeac..2a5a91f8 160000 --- a/operator-setup +++ b/operator-setup @@ -1 +1 @@ -Subproject commit 10b5eeac3ec8fd0de16bf59fa82b80812dc0a740 +Subproject commit 2a5a91f81f7ff92d28f8febbffbb889d3ca3a855 diff --git a/test/e2e_test.go b/test/e2e_test.go index 4d7f925c..6df26db0 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -8,11 +8,14 @@ import ( "testing" "time" + "github.com/Layr-Labs/eigenda-proxy/client" + "github.com/Layr-Labs/eigenda-proxy/common" "github.com/Layr-Labs/eigenda-proxy/eigenda" "github.com/Layr-Labs/eigenda-proxy/metrics" "github.com/Layr-Labs/eigenda-proxy/server" "github.com/Layr-Labs/eigenda-proxy/store" "github.com/Layr-Labs/eigenda/api/clients" + "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait" op_plasma "github.com/ethereum-optimism/optimism/op-plasma" opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" @@ -110,7 +113,7 @@ func createTestSuite(t *testing.T, useMemory bool) (TestSuite, func()) { }, kill } -func TestE2EPutGetLogicForEigenDAStore(t *testing.T) { +func TestHoleskyWithPlasmaClient(t *testing.T) { if !runTestnetIntegrationTests { t.Skip("Skipping testnet integration test") } @@ -138,7 +141,7 @@ func TestE2EPutGetLogicForEigenDAStore(t *testing.T) { require.Equal(t, testPreimage, preimage) } -func TestE2EPutGetLogicForMemoryStore(t *testing.T) { +func TestMemStoreWithPlasmaClient(t *testing.T) { if runTestnetIntegrationTests { t.Skip("Skipping non-testnet integration test") } @@ -165,3 +168,46 @@ func TestE2EPutGetLogicForMemoryStore(t *testing.T) { require.NoError(t, err) require.Equal(t, testPreimage, preimage) } + +func TestMemStoreWithProxyClient(t *testing.T) { + if runTestnetIntegrationTests { + t.Skip("Skipping non-testnet integration test") + } + + ts, kill := createTestSuite(t, true) + defer kill() + + cfg := &client.Config{ + URL: fmt.Sprintf("%s://%s:%d", transport, host, port), + } + daClient := client.New(cfg) + t.Log("Waiting for client to establish connection with plasma server...") + // wait for server to come online after starting + wait.For(ts.ctx, time.Second*1, func() (bool, error) { + err := daClient.Health() + if err != nil { + return false, nil + } + + return true, nil + }) + + // 1 - write arbitrary data to EigenDA + + var testPreimage = []byte("inter-subjective and not objective!") + + t.Log("Setting input data on proxy server...") + blobInfo, err := daClient.SetData(ts.ctx, testPreimage) + require.NoError(t, err) + + // 2 - fetch data from EigenDA for generated commitment key + t.Log("Getting input data from proxy server...") + preimage, err := daClient.GetData(ts.ctx, blobInfo, common.BinaryDomain) + require.NoError(t, err) + require.Equal(t, testPreimage, preimage) + + // 3 - fetch iFFT representation of preimage + iFFTPreimage, err := daClient.GetData(ts.ctx, blobInfo, common.PolyDomain) + require.NoError(t, err) + require.NotEqual(t, preimage, iFFTPreimage) +} From 3c8831d984079bb514da11e20001ac1867760f72 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sat, 8 Jun 2024 14:32:04 -0400 Subject: [PATCH 2/6] feat: Proxy client - domain assertion tests and holesky test --- common/common.go | 23 +++++++++++++++++ test/e2e_test.go | 64 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/common/common.go b/common/common.go index f53254dd..a9159b7a 100644 --- a/common/common.go +++ b/common/common.go @@ -110,3 +110,26 @@ func ParseBytesAmount(s string) (uint64, error) { return 0, fmt.Errorf("unsupported unit: %s", unit) } } + +func SubsetExists[P comparable](arr, sub []P) bool { + if len(sub) == 0 { + return true + } + + i := 0 + j := 0 + + for i < len(arr) { + if arr[i] == sub[j] { + j++ + if j == len(sub) { + return true + } + } else { + i -= j + j = 0 + } + i++ + } + return false +} diff --git a/test/e2e_test.go b/test/e2e_test.go index 6df26db0..3b252ac5 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -15,6 +15,7 @@ import ( "github.com/Layr-Labs/eigenda-proxy/server" "github.com/Layr-Labs/eigenda-proxy/store" "github.com/Layr-Labs/eigenda/api/clients" + "github.com/Layr-Labs/eigenda/api/clients/codecs" "github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait" op_plasma "github.com/ethereum-optimism/optimism/op-plasma" opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics" @@ -36,7 +37,7 @@ const ( transport = "http" serviceName = "eigenda_proxy" host = "127.0.0.1" - port = 6969 + port = 4200 holeskyDA = "disperser-holesky.eigenda.xyz:443" ) @@ -141,6 +142,58 @@ func TestHoleskyWithPlasmaClient(t *testing.T) { require.Equal(t, testPreimage, preimage) } +func TestHoleskyWithProxyClient(t *testing.T) { + if runTestnetIntegrationTests { + t.Skip("Skipping non-testnet integration test") + } + + ts, kill := createTestSuite(t, false) + defer kill() + + cfg := &client.Config{ + URL: fmt.Sprintf("%s://%s:%d", transport, host, port), + } + daClient := client.New(cfg) + t.Log("Waiting for client to establish connection with plasma server...") + // wait for server to come online after starting + wait.For(ts.ctx, time.Second*1, func() (bool, error) { + err := daClient.Health() + if err != nil { + return false, nil + } + + return true, nil + }) + + // 1 - write arbitrary data to EigenDA + + var testPreimage = []byte("inter-subjective and not objective!") + + t.Log("Setting input data on proxy server...") + blobInfo, err := daClient.SetData(ts.ctx, testPreimage) + require.NoError(t, err) + + // 2 - fetch data from EigenDA for generated commitment key + t.Log("Getting input data from proxy server...") + preimage, err := daClient.GetData(ts.ctx, blobInfo, common.BinaryDomain) + require.NoError(t, err) + require.Equal(t, testPreimage, preimage) + + // 3 - fetch iFFT representation of preimage + iFFTPreimage, err := daClient.GetData(ts.ctx, blobInfo, common.PolyDomain) + require.NoError(t, err) + require.NotEqual(t, preimage, iFFTPreimage) + + // 4 - Assert domain transformations + + ifftCodec := codecs.NewIFFTCodec(codecs.DefaultBlobCodec{}) + + decodedBlob, err := ifftCodec.DecodeBlob(iFFTPreimage) + require.NoError(t, err) + + require.Equal(t, decodedBlob, preimage) +} + func TestMemStoreWithPlasmaClient(t *testing.T) { if runTestnetIntegrationTests { t.Skip("Skipping non-testnet integration test") @@ -210,4 +263,13 @@ func TestMemStoreWithProxyClient(t *testing.T) { iFFTPreimage, err := daClient.GetData(ts.ctx, blobInfo, common.PolyDomain) require.NoError(t, err) require.NotEqual(t, preimage, iFFTPreimage) + + // 4 - Assert domain transformations + + ifftCodec := codecs.NewIFFTCodec(codecs.DefaultBlobCodec{}) + + decodedBlob, err := ifftCodec.DecodeBlob(iFFTPreimage) + require.NoError(t, err) + + require.Equal(t, decodedBlob, preimage) } From ed9de63cc78abf8f4f57f605776bad58fb707ae0 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sat, 8 Jun 2024 14:35:40 -0400 Subject: [PATCH 3/6] feat: Proxy client - update test flag --- test/e2e_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e_test.go b/test/e2e_test.go index 3b252ac5..4d9bcf23 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -143,8 +143,8 @@ func TestHoleskyWithPlasmaClient(t *testing.T) { } func TestHoleskyWithProxyClient(t *testing.T) { - if runTestnetIntegrationTests { - t.Skip("Skipping non-testnet integration test") + if !runTestnetIntegrationTests { + t.Skip("Skipping testnet integration test") } ts, kill := createTestSuite(t, false) From f4c466e94fb5e8891b4509fd7903b2fe8315dbcf Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sat, 8 Jun 2024 17:42:37 -0400 Subject: [PATCH 4/6] feat: Proxy client - refactors and code cleanups --- client/client.go | 38 ++++++++++++++++++++++++++------------ common/common.go | 2 +- eigenda/commitment.go | 4 ++++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/client/client.go b/client/client.go index 3d42759e..77421fdd 100644 --- a/client/client.go +++ b/client/client.go @@ -12,16 +12,24 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) +const ( + // NOTE: this will need to be updated as plasma's implementation changes + decodingOffset = 2 +) + +// TODO: Add support for custom http client option type Config struct { URL string } +// ProxyClient is an interface for communicating with the EigenDA proxy server type ProxyClient interface { Health() error - GetData(ctx context.Context, blobInfo *common.BlobInfo, domain common.DomainType) ([]byte, error) - SetData(ctx context.Context, b []byte) (*common.BlobInfo, error) + GetData(ctx context.Context, cert *common.Certificate, domain common.DomainType) ([]byte, error) + SetData(ctx context.Context, b []byte) (*common.Certificate, error) } +// client is the implementation of ProxyClient type client struct { cfg *Config httpClient *http.Client @@ -34,6 +42,8 @@ func New(cfg *Config) ProxyClient { } } +// Health indicates if server is operational; useful for event based awaits +// when integration testing func (c *client) Health() error { url := c.cfg.URL + "/health" req, err := http.NewRequest(http.MethodGet, url, nil) @@ -53,14 +63,15 @@ func (c *client) Health() error { return nil } -func (c *client) GetData(ctx context.Context, info *common.BlobInfo, domain common.DomainType) ([]byte, error) { - b, err := rlp.EncodeToBytes(info) +// GetData fetches blob data associated with a DA certificate +func (c *client) GetData(ctx context.Context, cert *common.Certificate, domain common.DomainType) ([]byte, error) { + b, err := rlp.EncodeToBytes(cert) if err != nil { return nil, err } - b = eigenda.Commitment(b).Encode() - b = append([]byte{byte(0x1)}, b...) + // encode prefix bytes + b = eigenda.GenericPrefix(eigenda.Commitment(b).Encode()) url := fmt.Sprintf("%s/get/0x%x?domain=%s", c.cfg.URL, b, domain.String()) @@ -69,6 +80,7 @@ func (c *client) GetData(ctx context.Context, info *common.BlobInfo, domain comm return nil, fmt.Errorf("failed to construct http request: %e", err) } + req.Header.Set("Content-Type", "application/octet-stream") resp, err := c.httpClient.Do(req) if err != nil { return nil, err @@ -83,10 +95,10 @@ func (c *client) GetData(ctx context.Context, info *common.BlobInfo, domain comm return io.ReadAll(resp.Body) } -func (c *client) SetData(ctx context.Context, b []byte) (*common.BlobInfo, error) { - body := bytes.NewReader(b) +// SetData writes raw byte data to DA and returns the respective certificate +func (c *client) SetData(ctx context.Context, b []byte) (*common.Certificate, error) { url := fmt.Sprintf("%s/put/", c.cfg.URL) - req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, body) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(b)) if err != nil { return nil, fmt.Errorf("failed to create HTTP request: %w", err) } @@ -105,10 +117,12 @@ func (c *client) SetData(ctx context.Context, b []byte) (*common.BlobInfo, error return nil, err } - b = b[2:] + if len(b) < decodingOffset { + return nil, fmt.Errorf("read certificate is of invalid length: %d", len(b)) + } - var blob *common.BlobInfo - if err = rlp.DecodeBytes(b, &blob); err != nil { + var blob *common.Certificate + if err = rlp.DecodeBytes(b[decodingOffset:], &blob); err != nil { return nil, err } diff --git a/common/common.go b/common/common.go index a9159b7a..dd8a4193 100644 --- a/common/common.go +++ b/common/common.go @@ -12,7 +12,7 @@ var ( ErrInvalidDomainType = fmt.Errorf("invalid domain type") ) -type BlobInfo = disperser.BlobInfo +type Certificate = disperser.BlobInfo // DomainType is a enumeration type for the different data domains for which a // blob can exist between diff --git a/eigenda/commitment.go b/eigenda/commitment.go index a88f71eb..2775719e 100644 --- a/eigenda/commitment.go +++ b/eigenda/commitment.go @@ -36,6 +36,10 @@ func (c Commitment) Encode() []byte { return append([]byte{byte(EigenDA), byte(EigenV0)}, c...) } +func GenericPrefix(b []byte) []byte { + return append([]byte{byte(op_plasma.GenericCommitmentType)}, b...) +} + func StringToCommit(key string) (Commitment, error) { comm, err := hexutil.Decode(key) if err != nil { From fad7859d8c23d6c6f8bd47bb2bf864c3745cfecf Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sat, 8 Jun 2024 17:44:11 -0400 Subject: [PATCH 5/6] feat: Proxy client - alias blob info to certificate --- store/eigenda.go | 3 +-- store/memory.go | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/store/eigenda.go b/store/eigenda.go index 1318f165..93a7bc02 100644 --- a/store/eigenda.go +++ b/store/eigenda.go @@ -7,7 +7,6 @@ import ( "github.com/Layr-Labs/eigenda-proxy/common" "github.com/Layr-Labs/eigenda-proxy/verify" "github.com/Layr-Labs/eigenda/api/clients" - "github.com/Layr-Labs/eigenda/api/grpc/disperser" "github.com/ethereum/go-ethereum/rlp" ) @@ -31,7 +30,7 @@ func NewEigenDAStore(ctx context.Context, client *clients.EigenDAClient, v *veri // Get fetches a blob from DA using certificate fields and verifies blob // against commitment to ensure data is valid and non-tampered. func (e EigenDAStore) Get(ctx context.Context, key []byte, domain common.DomainType) ([]byte, error) { - var cert disperser.BlobInfo + var cert common.Certificate err := rlp.DecodeBytes(key, &cert) if err != nil { return nil, fmt.Errorf("failed to decode DA cert to RLP format: %w", err) diff --git a/store/memory.go b/store/memory.go index 906b3c10..ee3c7731 100644 --- a/store/memory.go +++ b/store/memory.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" + "github.com/Layr-Labs/eigenda-proxy/common" eigendacommon "github.com/Layr-Labs/eigenda-proxy/common" "github.com/Layr-Labs/eigenda-proxy/verify" "github.com/Layr-Labs/eigenda/api/clients/codecs" @@ -104,7 +105,7 @@ func (e *MemStore) Get(ctx context.Context, commit []byte, domain eigendacommon. e.RLock() defer e.RUnlock() - var cert disperser.BlobInfo + var cert common.Certificate err := rlp.DecodeBytes(commit, &cert) if err != nil { return nil, fmt.Errorf("failed to decode DA cert to RLP format: %w", err) @@ -160,7 +161,7 @@ func (e *MemStore) Put(ctx context.Context, value []byte) ([]byte, error) { mockBatchHeaderHash := crypto.Keccak256Hash(entropy) // only filling out commitment fields for now - cert := &disperser.BlobInfo{ + cert := &common.Certificate{ BlobHeader: &disperser.BlobHeader{ Commitment: &grpccommon.G1Commitment{ X: commitment.X.Marshal(), From b6c518fbb80418d1915a0f07b08477f64decb6f8 Mon Sep 17 00:00:00 2001 From: Ethen Pociask Date: Sun, 9 Jun 2024 17:33:15 -0400 Subject: [PATCH 6/6] feat: Proxy client - address PR feedback --- client/client.go | 6 +++--- common/common.go | 23 ----------------------- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/client/client.go b/client/client.go index 77421fdd..ed354550 100644 --- a/client/client.go +++ b/client/client.go @@ -121,10 +121,10 @@ func (c *client) SetData(ctx context.Context, b []byte) (*common.Certificate, er return nil, fmt.Errorf("read certificate is of invalid length: %d", len(b)) } - var blob *common.Certificate - if err = rlp.DecodeBytes(b[decodingOffset:], &blob); err != nil { + var cert *common.Certificate + if err = rlp.DecodeBytes(b[decodingOffset:], &cert); err != nil { return nil, err } - return blob, err + return cert, err } diff --git a/common/common.go b/common/common.go index dd8a4193..97a27655 100644 --- a/common/common.go +++ b/common/common.go @@ -110,26 +110,3 @@ func ParseBytesAmount(s string) (uint64, error) { return 0, fmt.Errorf("unsupported unit: %s", unit) } } - -func SubsetExists[P comparable](arr, sub []P) bool { - if len(sub) == 0 { - return true - } - - i := 0 - j := 0 - - for i < len(arr) { - if arr[i] == sub[j] { - j++ - if j == len(sub) { - return true - } - } else { - i -= j - j = 0 - } - i++ - } - return false -}