From eb9e6f5a7d2aacc8fdfd864ffc4d92603535876c Mon Sep 17 00:00:00 2001 From: Samuel Laferriere Date: Tue, 17 Sep 2024 20:55:10 -0700 Subject: [PATCH 1/2] fix: negative confDepth bug in verifier --- server/config.go | 12 ++++++++++-- verify/cert.go | 24 ++++++++---------------- verify/verifier.go | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/server/config.go b/server/config.go index 2f0afc33..a90b3a16 100644 --- a/server/config.go +++ b/server/config.go @@ -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? + if cfg.EthConfirmationDepth < 0 { + cfg.ClientConfig.WaitForFinalization = true + cfg.EthConfirmationDepth = 0 + } return cfg } @@ -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, }, diff --git a/verify/cert.go b/verify/cert.go index 94a2e88c..36244cd0 100644 --- a/verify/cert.go +++ b/verify/cert.go @@ -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 } @@ -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 big.NewInt(int64(max(uint64(blockNumber-cv.ethConfirmationDepth), 0))), nil } diff --git a/verify/verifier.go b/verify/verifier.go index adee653b..e19e302e 100644 --- a/verify/verifier.go +++ b/verify/verifier.go @@ -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" ) @@ -26,7 +26,7 @@ type Config struct { type Verifier struct { verifyCert bool - kzgVerifier *verifier.Verifier + kzgVerifier *kzgverifier.Verifier cv *CertVerifier } @@ -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 } From 233e19f90264c287344830e4f94f19b20bf8b32c Mon Sep 17 00:00:00 2001 From: Samuel Laferriere Date: Tue, 17 Sep 2024 21:18:04 -0700 Subject: [PATCH 2/2] fix: lint --- verify/cert.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/verify/cert.go b/verify/cert.go index 36244cd0..163fcd8a 100644 --- a/verify/cert.go +++ b/verify/cert.go @@ -109,5 +109,5 @@ func (cv *CertVerifier) getConfDeepBlockNumber() (*big.Int, error) { if err != nil { return nil, fmt.Errorf("failed to get latest block number: %w", err) } - return big.NewInt(int64(max(uint64(blockNumber-cv.ethConfirmationDepth), 0))), nil + return new(big.Int).SetUint64(max(blockNumber-cv.ethConfirmationDepth, 0)), nil }