@@ -3,6 +3,7 @@ package altda
33import (
44 "bytes"
55 "context"
6+ "encoding/json"
67 "errors"
78 "fmt"
89 "io"
@@ -21,16 +22,17 @@ var ErrInvalidInput = errors.New("invalid input")
2122// See https://github.com/ethereum-optimism/specs/issues/434
2223var ErrAltDADown = errors .New ("alt DA is down: failover to eth DA" )
2324
24- // InvalidCommitmentError is returned when the altda commitment is invalid
25- // and should be dropped from the derivation pipeline.
26- // Validity conditions for altda commitments are altda-layer-specific, so are done in da-servers .
27- // They should be returned as 418 (I'M A TEAPOT) errors, with a body containing the reason .
25+ // InvalidCommitmentError is returned when the eigenda-proxy returns a 418 TEAPOT error,
26+ // which signifies that the cert in the altda commitment is invalid and should be dropped
27+ // from the derivation pipeline .
28+ // This error should be contained in the response body of the 418 TEAPOT error .
2829type InvalidCommitmentError struct {
29- Reason string
30+ StatusCode int
31+ Msg string
3032}
3133
3234func (e InvalidCommitmentError ) Error () string {
33- return fmt .Sprintf ("Invalid AltDA Commitment: %v " , e .Reason )
35+ return fmt .Sprintf ("Invalid AltDA Commitment: cert verification failed with status code %v: %v " , e .StatusCode , e . Msg )
3436}
3537
3638// DAClient is an HTTP client to communicate with a DA storage service.
@@ -76,11 +78,19 @@ func (c *DAClient) GetInput(ctx context.Context, comm CommitmentData, l1Inclusio
7678 if resp .StatusCode == http .StatusTeapot {
7779 defer resp .Body .Close ()
7880 // Limit the body to 1000 bytes to prevent being DDoSed with a large error message.
79- bytesLimitedBody := http .MaxBytesReader (nil , resp .Body , 1000 )
80- // We discard the error as it only contains the reason for invalidity.
81- // We might read a partial or missing reason, but the commitment should still be skipped.
82- invalidCommitmentReason , _ := io .ReadAll (bytesLimitedBody )
83- return nil , InvalidCommitmentError {Reason : string (invalidCommitmentReason )}
81+ bytesLimitedBody := io .LimitReader (resp .Body , 1000 )
82+ bodyBytes , _ := io .ReadAll (bytesLimitedBody )
83+
84+ var invalidCommitmentErr InvalidCommitmentError
85+ // We assume that the body of the 418 TEAPOT error is a JSON object,
86+ // which was introduced in https://github.com/Layr-Labs/eigenda-proxy/pull/406
87+ // If it isn't because an older version of the proxy is used, then we just set the Msg field to the body bytes.
88+ if err := json .Unmarshal (bodyBytes , & invalidCommitmentErr ); err != nil {
89+ fmt .Println ("DAClient.GetInput: Failed to decode 418 HTTP error body into an InvalidCommitmentError: " +
90+ "consider updating proxy to a more recent version that contains https://github.com/Layr-Labs/eigenda-proxy/pull/406: " , err )
91+ invalidCommitmentErr .Msg = string (bodyBytes )
92+ }
93+ return nil , invalidCommitmentErr
8494 }
8595 if resp .StatusCode != http .StatusOK {
8696 return nil , fmt .Errorf ("failed to get preimage: %v" , resp .StatusCode )
0 commit comments