Skip to content

Commit

Permalink
Add commitment mode parameter and commitment type system
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyknox committed Jun 14, 2024
1 parent 322002e commit c88e1b4
Show file tree
Hide file tree
Showing 29 changed files with 539 additions and 408 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ jobs:
run: |
make test
- name: Run Optimism Test
run: |
make optimism-test
gosec:
runs-on: ubuntu-latest
env:
Expand All @@ -60,7 +56,7 @@ jobs:
with:
args: ./...

holesky-test:
e2e-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -70,14 +66,13 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21
go-version: 1.21

- name: Install project dependencies
run: |
go mod download
- name: Run holesky tests
- name: Run E2E Tests
env:
SIGNER_PRIVATE_KEY: ${{ secrets.SIGNER_PRIVATE_KEY }}
run: |
SIGNER_PRIVATE_KEY=$SIGNER_PRIVATE_KEY make holesky-test
SIGNER_PRIVATE_KEY=$SIGNER_PRIVATE_KEY make e2e-test
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,4 @@ go.work
.env

## kzg cache
e2e/resources/kzg/SRSTables/

## Vscode
/.vscode
test/resources/SRSTables/
16 changes: 5 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ clean:
rm bin/eigenda-proxy

test:
go test -v ./... -parallel 4
go test -v ./...

optimism-test:
OPTIMISM=true go test -timeout 1m -v ./e2e -deploy-config ../.devnet/devnetL1.json

holesky-test:
TESTNET=true go test -timeout 50m -v ./e2e -parallel 4
e2e-test: submodules
go test -timeout 50m -v ./test/e2e_test.go -testnet-integration

.PHONY: lint
lint:
Expand All @@ -48,7 +45,7 @@ lint:
@golangci-lint run

gosec:
@echo "Running security scan with gosec..."
@echo "$(GREEN) Running security scan with gosec...$(COLOR_END)"
gosec ./...

submodules:
Expand All @@ -59,10 +56,7 @@ srs:
cd operator-setup && ./srs_setup.sh; \
fi

op-devnet-allocs:
@echo "Generating devnet allocs..."
@./scripts/op-devnet-allocs.sh

.PHONY: \
op-batcher \
clean \
test
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ An ephemeral memory store backend can be used for faster feedback testing when p
## Running Locally

1. Compile binary: `make eigenda-proxy`
2. Run binary; e.g: `./bin/eigenda-proxy --addr 127.0.0.1 --port 5050 --eigenda-rpc 127.0.0.1:443 --eigenda-status-query-timeout 45m --eigenda-g1-path e2e/resources/kzg/g1.point --eigenda-g2-tau-path e2e/resources/kzg/g2.point.powerOf2 --eigenda-use-tls true`
2. Run binary; e.g: `./bin/eigenda-proxy --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-tau-path test/resources/g2.point.powerOf2 --eigenda-use-tls true`

**Env File**
An env file can be provided to the binary for runtime process ingestion; e.g:
Expand Down Expand Up @@ -67,17 +67,14 @@ The `raw commitment` for EigenDA is encoding certificate and kzg fields.

## Testing

### Unit
Unit tests can be ran via invoking `make test`.
Some unit tests have been introduced to assert the correctness of:

### Holesky
A holesky integration test can be ran using `make holesky-test` to assert proper dispersal/retrieval against a public network. Please **note** that 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 faster iteration testing.
* DA Certificate encoding/decoding logic
* commitment verification logic

Unit tests can be ran via `make test`.

### Optimism
An E2E test exists which spins up a local OP sequencer instance using the [op-e2e](https://github.com/ethereum-optimism/optimism/tree/develop/op-e2e) framework for asserting correct interaction behaviors with batch submission and state derivation. These tests can be ran via `make optimism-test`.

**NOTE:**
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 faster iteration testing.

## Downloading Mainnet SRS

Expand Down
35 changes: 10 additions & 25 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"io"
"net/http"

"github.com/Layr-Labs/eigenda-proxy/common"
"github.com/Layr-Labs/eigenda-proxy/eigenda"
"github.com/ethereum/go-ethereum/rlp"
"github.com/Layr-Labs/eigenda-proxy/server"
)

const (
Expand All @@ -25,8 +23,8 @@ type Config struct {
// ProxyClient is an interface for communicating with the EigenDA proxy server
type ProxyClient interface {
Health() error
GetData(ctx context.Context, cert *common.Certificate, domain common.DomainType) ([]byte, error)
SetData(ctx context.Context, b []byte) (*common.Certificate, error)
GetData(ctx context.Context, cert []byte, domain server.DomainType, commitmentType server.CommitmentType) ([]byte, error)
SetData(ctx context.Context, b []byte, commitmentType server.CommitmentType) ([]byte, error)
}

// client is the implementation of ProxyClient
Expand Down Expand Up @@ -64,16 +62,8 @@ func (c *client) Health() error {
}

// 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
}

// 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())
func (c *client) GetData(ctx context.Context, comm []byte, domain server.DomainType, commitmentType server.CommitmentType) ([]byte, error) {
url := fmt.Sprintf("%s/get/0x%x?domain=%s&commitment_mode=%s", c.cfg.URL, comm, domain.String(), commitmentType)

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
Expand All @@ -96,8 +86,8 @@ func (c *client) GetData(ctx context.Context, cert *common.Certificate, domain c
}

// 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)
func (c *client) SetData(ctx context.Context, b []byte, commitmentType server.CommitmentType) ([]byte, error) {
url := fmt.Sprintf("%s/put/?commitment_mode=%s", c.cfg.URL, commitmentType)
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)
Expand All @@ -117,14 +107,9 @@ func (c *client) SetData(ctx context.Context, b []byte) (*common.Certificate, er
return nil, err
}

if len(b) < decodingOffset {
return nil, fmt.Errorf("read certificate is of invalid length: %d", len(b))
}

var cert *common.Certificate
if err = rlp.DecodeBytes(b[decodingOffset:], &cert); err != nil {
return nil, err
if len(b) == 0 {
return nil, fmt.Errorf("read certificate is empty")
}

return cert, err
return b, err
}
2 changes: 1 addition & 1 deletion cmd/server/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"

"github.com/Layr-Labs/eigenda-proxy/metrics"
"github.com/Layr-Labs/eigenda-proxy/server"
"github.com/urfave/cli/v2"

"github.com/Layr-Labs/eigenda-proxy/server"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/opio"
)
Expand Down
67 changes: 67 additions & 0 deletions commitments/da_service_op_commitment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package commitments

import (
"fmt"
"log"
)

type DAServiceOPCommitmentType byte

const (
EigenDAByte DAServiceOPCommitmentType = 0
)

// DAServiceOPCommitment represents a value of one of two possible types (Keccak256Commitment or DAServiceCommitment).
type DAServiceOPCommitment struct {
eigendaCommitment *EigenDACommitment
}

var _ Commitment = (*DAServiceOPCommitment)(nil)

func OptimismEigenDACommitment(value EigenDACommitment) DAServiceOPCommitment {
return DAServiceOPCommitment{eigendaCommitment: &value}
}

func (e DAServiceOPCommitment) IsEigenDA() bool {
return e.eigendaCommitment != nil
}

func (e DAServiceOPCommitment) MustEigenDAValue() EigenDACommitment {
if e.eigendaCommitment != nil {
return *e.eigendaCommitment
}
log.Panic("CommitmentEither does not contain a Keccak256Commitment value")
return EigenDACommitment{} // This will never be reached, but is required for compilation.
}

func (e DAServiceOPCommitment) Marshal() ([]byte, error) {
if e.IsEigenDA() {
eigenDABytes, err := e.MustEigenDAValue().Marshal()
if err != nil {
return nil, err
}
return append([]byte{byte(EigenDAByte)}, eigenDABytes...), nil
} else {
return nil, fmt.Errorf("DAServiceOPCommitment is neither a keccak256 commitment or a DA service commitment")
}
}

func (e *DAServiceOPCommitment) Unmarshal(bz []byte) error {
if len(bz) < 1 {
return fmt.Errorf("OP commitment does not contain generic commitment type prefix byte")
}
head := DAServiceOPCommitmentType(bz[0])
tail := bz[1:]
switch head {
case EigenDAByte:
eigendaCommitment := EigenDACommitment{}
err := eigendaCommitment.Unmarshal(tail)
if err != nil {
return err
}
e.eigendaCommitment = &eigendaCommitment
default:
return fmt.Errorf("unrecognized generic commitment type byte: %x", bz[0])
}
return nil
}
58 changes: 58 additions & 0 deletions commitments/eigenda_commitment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package commitments

import (
"fmt"
"log"
)

// Define the parent and child types
type CertEncodingVersion byte

const (
CertEncodingV0 CertEncodingVersion = 0
)

type EigenDACommitment struct {
certV0 []byte
}

var _ Commitment = (*EigenDACommitment)(nil)

func EigenDACertV0(value []byte) EigenDACommitment {
return EigenDACommitment{certV0: value}
}

func (e EigenDACommitment) IsCertV0() bool {
return e.certV0 != nil
}

func (e EigenDACommitment) MustCertV0Value() []byte {
if e.certV0 != nil {
return e.certV0
}
log.Panic("CommitmentEither does not contain a Keccak256Commitment value")
return nil // This will never be reached, but is required for compilation.
}

func (e EigenDACommitment) Marshal() ([]byte, error) {
if e.IsCertV0() {
return append([]byte{byte(CertEncodingV0)}, e.certV0...), nil
} else {
return nil, fmt.Errorf("EigenDADAServiceOPCommitment is of unknown type")
}
}

func (e *EigenDACommitment) Unmarshal(bz []byte) error {
if len(bz) < 1 {
return fmt.Errorf("OP commitment does not contain eigenda commitment encoding version prefix byte")
}
head := CertEncodingVersion(bz[0])
tail := bz[1:]
switch head {
case CertEncodingV0:
e.certV0 = tail
default:
return fmt.Errorf("unrecognized EigenDA commitment encoding type byte: %x", bz[0])
}
return nil
}
6 changes: 6 additions & 0 deletions commitments/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package commitments

type Commitment interface {
Marshal() ([]byte, error)
Unmarshal([]byte) error
}
Loading

0 comments on commit c88e1b4

Please sign in to comment.