Skip to content

Commit 85a6c16

Browse files
committed
fix: cert validation err
1 parent 0d04655 commit 85a6c16

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

daserver/celestia.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/ethereum/go-ethereum/log"
3939
"github.com/ethereum/go-ethereum/metrics"
4040
"github.com/offchainlabs/nitro/arbutil"
41+
"github.com/offchainlabs/nitro/daprovider"
4142
"github.com/spf13/pflag"
4243

4344
blobstreamx "github.com/succinctlabs/sp1-blobstream/bindings"
@@ -629,7 +630,7 @@ func (c *CelestiaDA) Read(ctx context.Context, certificate *cert.CelestiaDACertV
629630
headerDataHash := [32]byte{}
630631
copy(headerDataHash[:], header.DataHash)
631632
if headerDataHash != certificate.DataRoot {
632-
return nil, fmt.Errorf("data Root mismatch, header.DataHash=%v, blobPointer.DataRoot=%v", header.DataHash, hex.EncodeToString(certificate.DataRoot[:]))
633+
return nil, certificateValidationError("data root mismatch")
633634
}
634635

635636
// Fetch blob with retry
@@ -678,34 +679,34 @@ func (c *CelestiaDA) Read(ctx context.Context, certificate *cert.CelestiaDACertV
678679
startRow := certificate.Start / odsSize
679680

680681
if certificate.Start >= odsSize*odsSize {
681-
return nil, fmt.Errorf("startIndexOds >= odsSize*odsSize, startIndexOds=%v, odsSize*odsSize=%v", certificate.Start, odsSize*odsSize)
682+
return nil, certificateValidationError("start index out of bounds")
682683
}
683684

684685
if certificate.Start+certificate.SharesLength < 1 {
685-
return nil, fmt.Errorf("startIndexOds+blobPointer.SharesLength < 1, startIndexOds+blobPointer.SharesLength=%v", certificate.Start+certificate.SharesLength)
686+
return nil, certificateValidationError("share range underflow")
686687
}
687688

688689
endIndexOds := certificate.Start + certificate.SharesLength - 1
689690
if endIndexOds >= odsSize*odsSize {
690-
return nil, fmt.Errorf("endIndexOds >= odsSize*odsSize, endIndexOds=%v, odsSize*odsSize=%v", endIndexOds, odsSize*odsSize)
691+
return nil, certificateValidationError("share range out of bounds")
691692
}
692693

693694
endRow := endIndexOds / odsSize
694695

695696
if endRow >= odsSize || startRow >= odsSize {
696-
return nil, fmt.Errorf("endRow >= odsSize || startRow >= odsSize, endRow=%v, startRow=%v, odsSize=%v", endRow, startRow, odsSize)
697+
return nil, certificateValidationError("row index out of bounds")
697698
}
698699

699700
startColumn := certificate.Start % odsSize
700701
endColumn := endIndexOds % odsSize
701702

702703
if startRow == endRow && startColumn > endColumn {
703-
return nil, fmt.Errorf("start and end row are the same and startColumn >= endColumn, startColumn=%v, endColumn+1=%v", startColumn, endColumn+1)
704+
return nil, certificateValidationError("invalid share range ordering")
704705
}
705706

706707
if uint64(sharesLength) != certificate.SharesLength || sharesLength == 0 {
707708
celestiaFailureCounter.Inc(1)
708-
return nil, fmt.Errorf("share length mismatch, sharesLength=%v, blobPointer.SharesLength=%v", sharesLength, certificate.SharesLength)
709+
return nil, certificateValidationError("share length mismatch")
709710
}
710711

711712
rows := [][][]byte{}
@@ -1170,6 +1171,10 @@ func isTransientError(err error) bool {
11701171
return false
11711172
}
11721173

1174+
func certificateValidationError(reason string) error {
1175+
return &daprovider.CertificateValidationError{Reason: fmt.Sprintf("certificate validation failed: %s", reason)}
1176+
}
1177+
11731178
func (c *CelestiaDA) generateCelestiaProof(ctx context.Context, certificate *cert.CelestiaDACertV1) ([]byte, error) {
11741179
if c.Cfg.ValidatorConfig.EthClient == "" || c.Cfg.ValidatorConfig.BlobstreamAddr == "" {
11751180
return nil, fmt.Errorf("no celestia prover config")

0 commit comments

Comments
 (0)