From 23ca62779a23cfc61188e23596e07fa33578264f Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Wed, 29 Nov 2023 21:33:46 +0530 Subject: [PATCH 1/2] Validate that sequencer MaxTxDataSize and batch poster MaxSize are below sequencer inbox requirements --- cmd/nitro/nitro.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/cmd/nitro/nitro.go b/cmd/nitro/nitro.go index 393f23c52b..527da6a976 100644 --- a/cmd/nitro/nitro.go +++ b/cmd/nitro/nitro.go @@ -14,6 +14,7 @@ import ( "os/signal" "path/filepath" "reflect" + "regexp" "strings" "syscall" "time" @@ -50,6 +51,7 @@ import ( "github.com/offchainlabs/nitro/cmd/util/confighelpers" "github.com/offchainlabs/nitro/execution/gethexec" _ "github.com/offchainlabs/nitro/nodeInterface" + "github.com/offchainlabs/nitro/solgen/go/bridgegen" "github.com/offchainlabs/nitro/solgen/go/precompilesgen" "github.com/offchainlabs/nitro/staker" "github.com/offchainlabs/nitro/staker/validatorwallet" @@ -488,6 +490,42 @@ func mainImpl() int { log.Error("failed to create node", "err", err) return 1 } + + // Validate sequencer's MaxTxDataSize and batchPoster's MaxSize params + config := liveNodeConfig.Get() + executionRevertedRegexp := regexp.MustCompile("(?i)execution reverted") + seqInboxMaxDataSize := 117964 + if config.Node.ParentChainReader.Enable { + seqInbox, err := bridgegen.NewSequencerInbox(rollupAddrs.SequencerInbox, l1Client) + if err != nil { + log.Error("failed to create sequencer inbox for validating sequencer's MaxTxDataSize and batchposter's MaxSize", "err", err) + return 1 + } + res, err := seqInbox.MaxDataSize(&bind.CallOpts{Context: ctx}) + seqInboxMaxDataSize = int(res.Int64()) + if err != nil && !executionRevertedRegexp.MatchString(err.Error()) { + log.Error("error fetching MaxDataSize from sequencer inbox", "err", err) + return 1 + } + } + // If sequencer is enabled, validate MaxTxDataSize to be at least 5kB below the batch poster MaxSize, and at least 15kB below the sequencer inbox’s max data size. + if config.Execution.Sequencer.Enable { + seqMaxTxDataSize := config.Execution.Sequencer.MaxTxDataSize + batchPosterMaxSize := config.Node.BatchPoster.MaxSize + if seqMaxTxDataSize > batchPosterMaxSize-5000 || seqMaxTxDataSize > seqInboxMaxDataSize-15000 { + log.Error("sequencer's MaxTxDataSize too large") + return 1 + } + } + // If batchPoster is enabled, validate MaxSize to be at least 10kB below the sequencer inbox’s max data size if the data availability service is not enabled. + if config.Node.BatchPoster.Enable && !config.Node.DataAvailability.Enable { + batchPosterMaxSize := config.Node.BatchPoster.MaxSize + if batchPosterMaxSize > seqInboxMaxDataSize-10000 { + log.Error("batchPoster's MaxSize is too large") + return 1 + } + } + liveNodeConfig.SetOnReloadHook(func(oldCfg *NodeConfig, newCfg *NodeConfig) error { if err := genericconf.InitLog(newCfg.LogType, log.Lvl(newCfg.LogLevel), &newCfg.FileLogging, pathResolver(nodeConfig.Persistent.LogDir)); err != nil { return fmt.Errorf("failed to re-init logging: %w", err) From a378c577f7a3ecfb580e69752be6c713c3fa790a Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Mon, 4 Dec 2023 20:02:09 +0530 Subject: [PATCH 2/2] address PR comments --- cmd/nitro/nitro.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cmd/nitro/nitro.go b/cmd/nitro/nitro.go index 527da6a976..c113d08976 100644 --- a/cmd/nitro/nitro.go +++ b/cmd/nitro/nitro.go @@ -491,9 +491,10 @@ func mainImpl() int { return 1 } - // Validate sequencer's MaxTxDataSize and batchPoster's MaxSize params + // Validate sequencer's MaxTxDataSize and batchPoster's MaxSize params. config := liveNodeConfig.Get() executionRevertedRegexp := regexp.MustCompile("(?i)execution reverted") + // SequencerInbox's maxDataSize is defaulted to 117964 which is 90% of Geth's 128KB tx size limit, leaving ~13KB for proving. seqInboxMaxDataSize := 117964 if config.Node.ParentChainReader.Enable { seqInbox, err := bridgegen.NewSequencerInbox(rollupAddrs.SequencerInbox, l1Client) @@ -508,20 +509,20 @@ func mainImpl() int { return 1 } } - // If sequencer is enabled, validate MaxTxDataSize to be at least 5kB below the batch poster MaxSize, and at least 15kB below the sequencer inbox’s max data size. - if config.Execution.Sequencer.Enable { - seqMaxTxDataSize := config.Execution.Sequencer.MaxTxDataSize - batchPosterMaxSize := config.Node.BatchPoster.MaxSize - if seqMaxTxDataSize > batchPosterMaxSize-5000 || seqMaxTxDataSize > seqInboxMaxDataSize-15000 { - log.Error("sequencer's MaxTxDataSize too large") + // If batchPoster is enabled, validate MaxSize to be at least 10kB below the sequencer inbox’s maxDataSize if the data availability service is not enabled. + // The 10kB gap is because its possible for the batch poster to exceed its MaxSize limit and produce batches of slightly larger size. + if config.Node.BatchPoster.Enable && !config.Node.DataAvailability.Enable { + if config.Node.BatchPoster.MaxSize > seqInboxMaxDataSize-10000 { + log.Error("batchPoster's MaxSize is too large") return 1 } } - // If batchPoster is enabled, validate MaxSize to be at least 10kB below the sequencer inbox’s max data size if the data availability service is not enabled. - if config.Node.BatchPoster.Enable && !config.Node.DataAvailability.Enable { - batchPosterMaxSize := config.Node.BatchPoster.MaxSize - if batchPosterMaxSize > seqInboxMaxDataSize-10000 { - log.Error("batchPoster's MaxSize is too large") + // If sequencer is enabled, validate MaxTxDataSize to be at least 5kB below the batch poster's MaxSize to allow space for headers and such. + // And since batchposter's MaxSize is to be at least 10kB below the sequencer inbox’s maxDataSize, this leads to another condition of atlest 15kB below the sequencer inbox’s maxDataSize. + if config.Execution.Sequencer.Enable { + if config.Execution.Sequencer.MaxTxDataSize > config.Node.BatchPoster.MaxSize-5000 || + config.Execution.Sequencer.MaxTxDataSize > seqInboxMaxDataSize-15000 { + log.Error("sequencer's MaxTxDataSize too large") return 1 } }