From 02631155dcfb66764b09a5bc34dba38cc7d386fd Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 16 Jul 2020 01:00:03 +0200 Subject: [PATCH] Add block gas limit verification Signed-off-by: Jakub Sztandera --- chain/sync.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/chain/sync.go b/chain/sync.go index 260d50adc..1ed7a3507 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -950,15 +950,24 @@ func (syncer *Syncer) checkBlockMessages(ctx context.Context, b *types.FullBlock return xerrors.Errorf("failed to load base state tree: %w", err) } + pl := vm.PricelistByEpoch(baseTs.Height()) + var sumGasLimit int64 checkMsg := func(msg types.ChainMsg) error { m := msg.VMMessage() // Phase 1: syntactic validation, as defined in the spec - minGas := vm.PricelistByEpoch(baseTs.Height()).OnChainMessage(msg.ChainLength()) + minGas := pl.OnChainMessage(msg.ChainLength()) if err := m.ValidForBlockInclusion(minGas.Total()); err != nil { return err } + // ValidForBlockInclusion checks if any single message does not exceed BlockGasLimit + // So below is overflow safe + sumGasLimit += m.GasLimit + if sumGasLimit > build.BlockGasLimit { + return xerrors.Errorf("block gas limit exceeded") + } + // Phase 2: (Partial) semantic validation: // the sender exists and is an account actor, and the nonces make sense if _, ok := nonces[m.From]; !ok {