Skip to content

Commit

Permalink
Add commitment type flag for disabling OP commitment logic
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyknox committed Jun 10, 2024
1 parent cfac6cc commit 4f6412f
Show file tree
Hide file tree
Showing 21 changed files with 477 additions and 284 deletions.
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 EigenDAWrapperCommitment(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
}
64 changes: 64 additions & 0 deletions commitments/eigenda_commitment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package commitments

import (
"fmt"
"log"

"github.com/ethereum/go-ethereum/rlp"
)

// Define the parent and child types
type EigenDAEncodingCommitmentType byte

const (
EigenDAEncoding0Byte EigenDAEncodingCommitmentType = 0
)

type EigenDACommitment struct {
certificateEncoding0 []byte
}

var _ Commitment = (*EigenDACommitment)(nil)

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

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

func (e EigenDACommitment) MustCertV0Value() []byte {
if e.certificateEncoding0 != nil {
return e.certificateEncoding0
}
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() {
bz, err := rlp.EncodeToBytes(e.certificateEncoding0)
if err != nil {
return nil, err
}
return append([]byte{byte(EigenDAEncoding0Byte)}, bz...), 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 := EigenDAEncodingCommitmentType(bz[0])
tail := bz[1:]
switch head {
case EigenDAEncoding0Byte:
e.certificateEncoding0 = tail
default:
return fmt.Errorf("unrecognized generic commitment 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
}
90 changes: 90 additions & 0 deletions commitments/op_commitment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package commitments

import (
"fmt"
"log"
)

type OPCommitmentType byte

const (
// Keccak256Byte represents a commitment using Keccak256 hashing.
Keccak256Byte OPCommitmentType = 0
// DAServiceByte represents a commitment using a DA service.
DAServiceByte OPCommitmentType = 1
)

type OPCommitment struct {
keccak256Commitment []byte
daServiceCommitment *DAServiceOPCommitment
}

var _ Commitment = (*OPCommitment)(nil)

func Keccak256Commitment(value []byte) OPCommitment {
return OPCommitment{keccak256Commitment: value}
}

func DAServiceCommitment(value DAServiceOPCommitment) OPCommitment {
return OPCommitment{daServiceCommitment: &value}
}

func (e OPCommitment) IsKeccak256() bool {
return e.keccak256Commitment != nil
}

func (e OPCommitment) IsDAService() bool {
return e.daServiceCommitment != nil
}

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

func (e OPCommitment) MustDAServiceValue() DAServiceOPCommitment {
if e.daServiceCommitment != nil {
return *e.daServiceCommitment
}
log.Panic("OPCommitment does not contain a DAServiceCommitment value")
return DAServiceOPCommitment{} // This will never be reached, but is required for compilation.
}

func (e OPCommitment) Marshal() ([]byte, error) {
if e.IsDAService() {
bytes, err := e.MustDAServiceValue().Marshal()
if err != nil {
return nil, err
}
return append([]byte{byte(DAServiceByte)}, bytes...), nil
} else if e.IsKeccak256() {
return append([]byte{byte(Keccak256Byte)}, e.MustKeccak256Value()...), nil
} else {
return nil, fmt.Errorf("OPCommitment is neither a Keccak256 commitment nor a DA service commitment")
}
}

func (e *OPCommitment) Unmarshal(bz []byte) error {
if len(bz) < 1 {
return fmt.Errorf("OPCommitment does not contain a commitment type prefix byte")
}
head := OPCommitmentType(bz[0])
tail := bz[1:]
switch head {
case Keccak256Byte:
e.keccak256Commitment = tail
case DAServiceByte:
daServiceCommitment := DAServiceOPCommitment{}
err := daServiceCommitment.Unmarshal(tail)
if err != nil {
return err
}
e.daServiceCommitment = &daServiceCommitment
default:
return fmt.Errorf("unrecognized commitment type byte: %x", bz[0])
}
return nil
}
73 changes: 0 additions & 73 deletions eigenda/commitment.go

This file was deleted.

2 changes: 1 addition & 1 deletion operator-setup
Submodule operator-setup updated 0 files
Loading

0 comments on commit 4f6412f

Please sign in to comment.