Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: negative confDepth bug in verifier #131

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,15 @@ func ReadConfig(ctx *cli.Context) Config {
FallbackTargets: ctx.StringSlice(FallbackTargets),
CacheTargets: ctx.StringSlice(CacheTargets),
}
cfg.ClientConfig.WaitForFinalization = (cfg.EthConfirmationDepth < 0)
// the eigenda client can only wait for 0 confirmations or finality
// the da-proxy has a more fine-grained notion of confirmation depth
// we use -1 to let the da client wait for finality, and then need to set the confirmation depth
// for the da-proxy to 0 (because negative confirmation depth doesn't mean anything and leads to errors)
// TODO: should the eigenda-client implement this feature for us instead?
samlaf marked this conversation as resolved.
Show resolved Hide resolved
if cfg.EthConfirmationDepth < 0 {
cfg.ClientConfig.WaitForFinalization = true
cfg.EthConfirmationDepth = 0
}

return cfg
}
Expand Down Expand Up @@ -457,7 +465,7 @@ func CLIFlags() []cli.Flag {
},
&cli.Int64Flag{
Name: EthConfirmationDepthFlagName,
Usage: "The number of Ethereum blocks of confirmation that the DA batch submission tx must have before it is assumed by the proxy to be final. The value of `0` indicates that the proxy shouldn't wait for any confirmations.",
Usage: "The number of Ethereum blocks to wait before considering a submitted blob's DA batch submission confirmed. `0` means wait for inclusion only. `-1` means wait for finality.",
EnvVars: prefixEnvVars("ETH_CONFIRMATION_DEPTH"),
Value: -1,
},
Expand Down
24 changes: 8 additions & 16 deletions verify/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ func NewCertVerifier(cfg *Config, l log.Logger) (*CertVerifier, error) {
}

// verifies on-chain batch ID for equivalence to certificate batch header fields
func (cv *CertVerifier) VerifyBatch(header *binding.IEigenDAServiceManagerBatchHeader,
id uint32, recordHash [32]byte, confirmationNumber uint32) error {
blockNumber, err := cv.getContextBlock()
func (cv *CertVerifier) VerifyBatch(
header *binding.IEigenDAServiceManagerBatchHeader, id uint32, recordHash [32]byte, confirmationNumber uint32,
) error {
blockNumber, err := cv.getConfDeepBlockNumber()
if err != nil {
return err
}
Expand Down Expand Up @@ -103,19 +104,10 @@ func (cv *CertVerifier) VerifyMerkleProof(inclusionProof []byte, root []byte,
}

// fetches a block number provided a subtraction of a user defined conf depth from latest block
func (cv *CertVerifier) getContextBlock() (*big.Int, error) {
var blockNumber *big.Int
blockHeader, err := cv.ethClient.BlockByNumber(context.Background(), nil)
func (cv *CertVerifier) getConfDeepBlockNumber() (*big.Int, error) {
blockNumber, err := cv.ethClient.BlockNumber(context.Background())
if err != nil {
return nil, err
}

if cv.ethConfirmationDepth == 0 {
return blockHeader.Number(), nil
return nil, fmt.Errorf("failed to get latest block number: %w", err)
}

blockNumber = new(big.Int)
blockNumber.Sub(blockHeader.Number(), big.NewInt(int64(cv.ethConfirmationDepth-1))) // #nosec G115

return blockNumber, nil
return new(big.Int).SetUint64(max(blockNumber-cv.ethConfirmationDepth, 0)), nil
}
6 changes: 3 additions & 3 deletions verify/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/Layr-Labs/eigenda/api/grpc/common"
"github.com/Layr-Labs/eigenda/encoding/kzg"
"github.com/Layr-Labs/eigenda/encoding/kzg/verifier"
kzgverifier "github.com/Layr-Labs/eigenda/encoding/kzg/verifier"
"github.com/Layr-Labs/eigenda/encoding/rs"
)

Expand All @@ -26,7 +26,7 @@ type Config struct {

type Verifier struct {
verifyCert bool
kzgVerifier *verifier.Verifier
kzgVerifier *kzgverifier.Verifier
cv *CertVerifier
}

Expand All @@ -41,7 +41,7 @@ func NewVerifier(cfg *Config, l log.Logger) (*Verifier, error) {
}
}

kzgVerifier, err := verifier.NewVerifier(cfg.KzgConfig, false)
kzgVerifier, err := kzgverifier.NewVerifier(cfg.KzgConfig, false)
if err != nil {
return nil, err
}
Expand Down
Loading