Skip to content
This repository was archived by the owner on Jul 23, 2025. It is now read-only.

Commit 04dba8c

Browse files
committed
feat: Cert encoding byte - address PR feedback
1 parent 4a081dd commit 04dba8c

File tree

7 files changed

+66
-116
lines changed

7 files changed

+66
-116
lines changed

.devnet-alt-da/addresses.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"DisputeGameFactory": "0x8a1a5F20ADF3005022049880f799FBBF2a188cfC",
1010
"DisputeGameFactoryProxy": "0xeCb92a686D1ab066fc4E559A305FEB75DD512377",
1111
"FastPreimageOracle": "0xbc1b15C94465d383bB68F345bEba1F3fcD2af44B",
12-
"FaultDisputeGame_0": "0x86a350621ED6d036E2Af9cC68865dEf4B31C13ae",
12+
"FaultDisputeGame_0": "0x873112109C538909745B18Dc61CEbf1a167Ccc93",
1313
"FaultDisputeGame_254": "0x9218181FAb774F8DBD245C8a2544069F9A8C2A8a",
1414
"FaultDisputeGame_255": "0x401deDFb8536D84096Dd617689E770cB085ADfb7",
1515
"L1CrossDomainMessenger": "0x2CfFF1c8Df8CE2BA6CBa19699CCBa6F381734938",

.devnet-alt-da/allocs-l1.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ For `alt-da` Optimism rollups using EigenDA, the following [commitment schemas](
364364
| commitment_type (byte) | da_layer_byte | version_byte | encoding_byte | payload |
365365
| ---------------------- | ------------- | ------------ | ------------- | ----------------- |
366366
| 0x00 | | | | keccak_commitment |
367-
| 0x01 | 0x00 | 0x00 | N/A | eigenda_cert_v0 |
368-
| 0x01 | 0x00 | 0x01 | N/A | eigenda_cert_v1 |
367+
| 0x01 | 0x00 | 0x00 | | eigenda_cert_v0 |
368+
| 0x01 | 0x00 | 0x01 | | eigenda_cert_v1 |
369369
| 0x01 | 0x00 | 0x02 | 0x00 | eigenda_cert_v2 (RLP) |
370370
| 0x01 | 0x00 | 0x02 | 0x01 | eigenda_cert_v2 (ABI_verifyDACertV2) |
371371

@@ -376,8 +376,8 @@ For standard clients (i.e, `clients/standard_client/client.go`) communicating wi
376376

377377
| version_byte | encoding_byte | payload |
378378
| ------------ | ------------- | --------------- |
379-
| 0x00 | N/A | eigenda_cert_v0 |
380-
| 0x01 | N/A | eigenda_cert_v1 |
379+
| 0x00 | | eigenda_cert_v0 |
380+
| 0x01 | | eigenda_cert_v1 |
381381
| 0x02 | 0x00 | eigenda_cert_v2 (RLP) |
382382
| 0x02 | 0x01 | eigenda_cert_v2 (ABI_verifyDACertV2) |
383383

commitments/eigenda.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type CertCommitment interface {
2121
type EigenDACommitment struct {
2222
prefix EigenDACommitmentType
2323
b []byte
24-
encoding *EncodingType // Optional encoding type, used only for V2+
24+
encoding EncodingType // Optional encoding type, used only for V2+
2525
}
2626

2727
// NewEigenDACommitment creates a new commitment from the given input.
@@ -38,7 +38,7 @@ func NewEigenDACommitmentWithEncoding(input []byte, commitmentType EigenDACommit
3838
return EigenDACommitment{
3939
prefix: commitmentType,
4040
b: input,
41-
encoding: &encoding,
41+
encoding: encoding,
4242
}
4343
}
4444

@@ -50,8 +50,8 @@ func (c EigenDACommitment) CommitmentType() EigenDACommitmentType {
5050
// Encode adds a commitment type prefix self describing the commitment.
5151
func (c EigenDACommitment) Encode() []byte {
5252
// For V2+ certificates with encoding type
53-
if c.prefix >= CertV2 && c.encoding != nil {
54-
return append([]byte{byte(c.prefix), byte(*c.encoding)}, c.b...)
53+
if c.prefix >= CertV2 {
54+
return append([]byte{byte(c.prefix), byte(c.encoding)}, c.b...)
5555
}
5656

5757
// For V0/V1 certificates (backward compatibility)

commitments/mode.go

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commitments
22

33
import (
44
"fmt"
5+
"strings"
56
)
67

78
// EncodingType represents the serialization format for the certificate
@@ -44,76 +45,47 @@ func StringToCommitmentMode(s string) (CommitmentMode, error) {
4445
}
4546

4647
func StringToEncodingType(s string) (EncodingType, error) {
47-
switch s {
48-
case "rlp", "RLP", "0":
48+
switch strings.ToLower(s) {
49+
case "rlp", "0":
4950
return RLPEncoding, nil
50-
case "abi", "ABI", "1":
51+
case "abi", "1":
5152
return ABIVerifyV2CertEncoding, nil
5253
default:
5354
return RLPEncoding, fmt.Errorf("unknown encoding type: %s, using default RLP encoding", s)
5455
}
5556
}
5657

57-
// DecodeCommitmentType returns the encoding type from a certificate commitment
58-
func DecodeCommitmentType(cert []byte) (EigenDACommitmentType, EncodingType, []byte, error) {
59-
if len(cert) == 0 {
60-
return 0, 0, nil, fmt.Errorf("commitment is empty")
61-
}
62-
63-
// Extract version byte (always present)
64-
version := EigenDACommitmentType(cert[0])
65-
var encoding EncodingType
66-
var payload []byte
67-
68-
// For CertV2+, we have an encoding byte
69-
if version >= CertV2 {
70-
if len(cert) < 2 {
71-
return 0, 0, nil, fmt.Errorf("commitment too short for CertV2")
72-
}
73-
encoding = EncodingType(cert[1])
74-
payload = cert[2:] // Skip version and encoding bytes
75-
} else {
76-
// For CertV0/V1, there's no encoding byte (default to RLP)
77-
encoding = RLPEncoding
78-
payload = cert[1:] // Skip only version byte
79-
}
80-
81-
return version, encoding, payload, nil
82-
}
83-
8458
func EncodeCommitment(
8559
bytes []byte,
86-
commitmentMode CommitmentMode,
87-
commitmentType EigenDACommitmentType,
88-
encodingType EncodingType,
60+
cm CommitmentMeta,
8961
) ([]byte, error) {
90-
switch commitmentMode {
62+
switch cm.Mode {
9163
case OptimismKeccak:
9264
return Keccak256Commitment(bytes).Encode(), nil
9365

9466
case OptimismGeneric:
9567
// For V2 certificates with encoding specified, add encoding byte
96-
if commitmentType >= CertV2 {
97-
certCommit := NewEigenDACommitmentWithEncoding(bytes, commitmentType, encodingType).Encode()
68+
if cm.Version >= CertV2 {
69+
certCommit := NewEigenDACommitmentWithEncoding(bytes, cm.Version, cm.Encoding).Encode()
9870
svcCommit := EigenDASvcCommitment(certCommit).Encode()
9971
altDACommit := NewGenericCommitment(svcCommit).Encode()
10072
return altDACommit, nil
10173
}
10274

10375
// Fallback to previous behavior for V0/V1
104-
certCommit := NewEigenDACommitment(bytes, commitmentType).Encode()
76+
certCommit := NewEigenDACommitment(bytes, cm.Version).Encode()
10577
svcCommit := EigenDASvcCommitment(certCommit).Encode()
10678
altDACommit := NewGenericCommitment(svcCommit).Encode()
10779
return altDACommit, nil
10880

10981
case Standard:
11082
// For V2 certificates with encoding specified, add encoding byte
111-
if commitmentType >= CertV2 {
112-
return NewEigenDACommitmentWithEncoding(bytes, commitmentType, encodingType).Encode(), nil
83+
if cm.Version >= CertV2 {
84+
return NewEigenDACommitmentWithEncoding(bytes, cm.Version, cm.Encoding).Encode(), nil
11385
}
11486

11587
// Fallback to previous behavior for V0/V1
116-
return NewEigenDACommitment(bytes, commitmentType).Encode(), nil
88+
return NewEigenDACommitment(bytes, cm.Version).Encode(), nil
11789
}
11890

11991
return nil, fmt.Errorf("unknown commitment mode")

common/serialization.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,8 @@ func EncodeV2CertToBytes(encoding commitments.EncodingType, cert *coretypes.Eige
5656
}
5757
}
5858

59-
func interfaceToBytesJSON(data interface{}) ([]byte, error) {
60-
bytes, err := json.Marshal(data)
61-
if err != nil {
62-
return nil, err
63-
}
64-
return bytes, nil
65-
}
66-
59+
// DecodeV2CertFromBytes ... Decodes a raw DA commitment into an EigenDA V2 certificate
60+
// provided the respective encoding version
6761
func DecodeV2CertFromBytes(encoding commitments.EncodingType, commitment []byte) (*coretypes.EigenDACert, error) {
6862
switch encoding {
6963
case commitments.ABIVerifyV2CertEncoding:
@@ -76,13 +70,13 @@ func DecodeV2CertFromBytes(encoding commitments.EncodingType, commitment []byte)
7670

7771
// use json as intermediary to cast abstract type to bytes to
7872
// then deserialize into structured certificate type
79-
b, err := interfaceToBytesJSON(abiMap)
73+
bytes, err := json.Marshal(commitment)
8074
if err != nil {
8175
return nil, err
8276
}
8377

8478
var cert *coretypes.EigenDACert
85-
err = json.Unmarshal(b, &cert)
79+
err = json.Unmarshal(bytes, &cert)
8680

8781
if err != nil {
8882
return nil, fmt.Errorf("json unmarshal v2 cert: %w", err)

server/handlers.go

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,9 @@ func (svr *Server) handleHealth(w http.ResponseWriter, _ *http.Request) error {
3434
// GET ROUTES
3535
// =================================================================================================
3636

37-
// handleGetStdCommitment handles the GET request for std commitments.
38-
func (svr *Server) handleGetStdCommitment(w http.ResponseWriter, r *http.Request) error {
39-
versionByte, err := parseVersionByte(w, r)
40-
if err != nil {
41-
return fmt.Errorf("error parsing version byte: %w", err)
42-
}
43-
44-
commitmentMeta := commitments.CommitmentMeta{
45-
Mode: commitments.OptimismGeneric,
46-
Version: commitments.EigenDACommitmentType(versionByte),
47-
Encoding: commitments.RLPEncoding,
48-
}
37+
// handleGetEigenDA helper function used for processing gets for an eigenda backend type
38+
func (svr *Server) handleGetEigenDA(w http.ResponseWriter, r *http.Request,
39+
cm commitments.CommitmentMeta) error {
4940

5041
rawCommitmentHex, ok := mux.Vars(r)[routingVarNamePayloadHex]
5142
if !ok {
@@ -56,12 +47,28 @@ func (svr *Server) handleGetStdCommitment(w http.ResponseWriter, r *http.Request
5647
return fmt.Errorf("failed to decode commitment %s: %w", rawCommitmentHex, err)
5748
}
5849

59-
if versionByte >= byte(commitments.CertV2) {
60-
commitmentMeta.Encoding = commitments.EncodingType(commitment[0])
50+
if cm.Version >= commitments.CertV2 {
51+
cm.Encoding = commitments.EncodingType(commitment[0])
6152
commitment = commitment[1:]
6253
}
6354

64-
return svr.handleGetShared(r.Context(), w, commitment, commitmentMeta)
55+
return svr.handleGetShared(r.Context(), w, commitment, cm)
56+
}
57+
58+
// handleGetStdCommitment handles the GET request for std commitments.
59+
func (svr *Server) handleGetStdCommitment(w http.ResponseWriter, r *http.Request) error {
60+
versionByte, err := parseVersionByte(w, r)
61+
if err != nil {
62+
return fmt.Errorf("error parsing version byte: %w", err)
63+
}
64+
65+
meta := commitments.CommitmentMeta{
66+
Mode: commitments.Standard,
67+
Version: commitments.EigenDACommitmentType(versionByte),
68+
Encoding: commitments.RLPEncoding,
69+
}
70+
71+
return svr.handleGetEigenDA(w, r, meta)
6572
}
6673

6774
// handleGetOPKeccakCommitment handles the GET request for optimism keccak commitments.
@@ -97,27 +104,14 @@ func (svr *Server) handleGetOPGenericCommitment(w http.ResponseWriter, r *http.R
97104
return fmt.Errorf("error parsing version byte: %w", err)
98105
}
99106

100-
commitmentMeta := commitments.CommitmentMeta{
107+
meta := commitments.CommitmentMeta{
101108
Mode: commitments.OptimismGeneric,
102109
Version: commitments.EigenDACommitmentType(versionByte),
103110
Encoding: commitments.RLPEncoding,
104111
}
105112

106-
rawCommitmentHex, ok := mux.Vars(r)[routingVarNamePayloadHex]
107-
if !ok {
108-
return fmt.Errorf("commitment not found in path: %s", r.URL.Path)
109-
}
110-
commitment, err := hex.DecodeString(rawCommitmentHex)
111-
if err != nil {
112-
return fmt.Errorf("failed to decode commitment %s: %w", rawCommitmentHex, err)
113-
}
113+
return svr.handleGetEigenDA(w, r, meta)
114114

115-
if versionByte >= byte(commitments.CertV2) {
116-
commitmentMeta.Encoding = commitments.EncodingType(commitment[0])
117-
commitment = commitment[1:]
118-
}
119-
120-
return svr.handleGetShared(r.Context(), w, commitment, commitmentMeta)
121115
}
122116

123117
func (svr *Server) handleGetShared(
@@ -173,28 +167,33 @@ func (svr *Server) handleGetEigenDADispersalBackend(w http.ResponseWriter, _ *ht
173167
// POST ROUTES
174168
// =================================================================================================
175169

176-
// handlePostStdCommitment handles the POST request for std commitments.
177170
// parseEncodingQueryParamType parses the encoding query parameter
178-
func parseEncodingQueryParamType(w http.ResponseWriter, r *http.Request) (commitments.EncodingType, bool, error) {
171+
func (svr *Server) parseEncodingQueryParamType(w http.ResponseWriter, r *http.Request) (commitments.EncodingType, error) {
179172
encodingParam := r.URL.Query().Get(routingQueryParamEncoding)
180173
if encodingParam == "" {
181174
// If no encoding is provided, use default RLP encoding
182-
return commitments.RLPEncoding, false, nil
175+
return commitments.RLPEncoding, nil
176+
}
177+
178+
// if encoding param provided but historical V1 backend used then error
179+
if svr.sm.GetDispersalBackend() == common.V1EigenDABackend {
180+
183181
}
184182

185183
// Parse the encoding type
186184
encoding, err := commitments.StringToEncodingType(encodingParam)
187185
if err != nil {
188186
http.Error(w, fmt.Sprintf("Invalid encoding type: %s", encodingParam), http.StatusBadRequest)
189-
return commitments.RLPEncoding, false, err
187+
return commitments.RLPEncoding, err
190188
}
191189

192-
return encoding, true, nil
190+
return encoding, nil
193191
}
194192

193+
// handlePostStdCommitment handles the POST request for std commitments.
195194
func (svr *Server) handlePostStdCommitment(w http.ResponseWriter, r *http.Request) error {
196195
// Parse encoding type from query parameter
197-
encodingType, hasEncoding, err := parseEncodingQueryParamType(w, r)
196+
encodingType, err := svr.parseEncodingQueryParamType(w, r)
198197
if err != nil {
199198
return err
200199
}
@@ -207,11 +206,7 @@ func (svr *Server) handlePostStdCommitment(w http.ResponseWriter, r *http.Reques
207206

208207
if svr.sm.GetDispersalBackend() == common.V2EigenDABackend {
209208
// If encoding is specified and we're using V2, use CertV2
210-
if hasEncoding {
211-
commitmentMeta.Version = commitments.CertV2
212-
} else {
213-
commitmentMeta.Version = commitments.CertV1
214-
}
209+
commitmentMeta.Version = commitments.CertV2
215210
}
216211

217212
return svr.handlePostShared(w, r, nil, commitmentMeta)
@@ -227,16 +222,10 @@ func (svr *Server) handlePostOPKeccakCommitment(w http.ResponseWriter, r *http.R
227222
// return err
228223
// }
229224

230-
// Parse encoding type from query parameter
231-
encodingType, _, err := parseEncodingQueryParamType(w, r)
232-
if err != nil {
233-
return err
234-
}
235-
236225
commitmentMeta := commitments.CommitmentMeta{
237226
Mode: commitments.OptimismKeccak,
238227
Version: commitments.CertV0,
239-
Encoding: encodingType,
228+
Encoding: commitments.RLPEncoding,
240229
}
241230

242231
rawCommitmentHex, ok := mux.Vars(r)[routingVarNamePayloadHex]
@@ -254,7 +243,7 @@ func (svr *Server) handlePostOPKeccakCommitment(w http.ResponseWriter, r *http.R
254243
// handlePostOPGenericCommitment handles the POST request for optimism generic commitments.
255244
func (svr *Server) handlePostOPGenericCommitment(w http.ResponseWriter, r *http.Request) error {
256245
// Parse encoding type from query parameter
257-
encodingType, hasEncoding, err := parseEncodingQueryParamType(w, r)
246+
encodingType, err := svr.parseEncodingQueryParamType(w, r)
258247
if err != nil {
259248
return err
260249
}
@@ -266,12 +255,7 @@ func (svr *Server) handlePostOPGenericCommitment(w http.ResponseWriter, r *http.
266255
}
267256

268257
if svr.sm.GetDispersalBackend() == common.V2EigenDABackend {
269-
// If encoding is specified and we're using V2, use CertV2
270-
if hasEncoding {
271-
commitmentMeta.Version = commitments.CertV2
272-
} else {
273-
commitmentMeta.Version = commitments.CertV1
274-
}
258+
commitmentMeta.Version = commitments.CertV2
275259
}
276260

277261
return svr.handlePostShared(w, r, nil, commitmentMeta)
@@ -314,7 +298,7 @@ func (svr *Server) handlePostShared(
314298
return err
315299
}
316300

317-
responseCommit, err := commitments.EncodeCommitment(commitment, meta.Mode, meta.Version, meta.Encoding)
301+
responseCommit, err := commitments.EncodeCommitment(commitment, meta)
318302
if err != nil {
319303
err = MetaError{
320304
Err: fmt.Errorf("failed to encode commitment %v (commitment mode %v): %w", commitment, meta.Mode, err),

0 commit comments

Comments
 (0)