From 1197155181eea2746dccb76e4cccd1f99711e6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Fri, 13 Sep 2024 15:25:28 +0200 Subject: [PATCH] fix: suppress gosec overflow issues --- aggregator/aggregator.go | 2 +- aggregator/prover/prover.go | 2 +- merkletree/split.go | 2 +- sequencesender/sequencesender.go | 2 +- state/encoding_batch_v2.go | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/aggregator/aggregator.go b/aggregator/aggregator.go index 8040e237..125bb97d 100644 --- a/aggregator/aggregator.go +++ b/aggregator/aggregator.go @@ -553,7 +553,7 @@ func (a *Aggregator) handleReceivedDataStream( oldDBBatch.Batch.AccInputHash, a.currentStreamBatch.BatchL2Data, a.currentStreamBatch.L1InfoRoot, - uint64(a.currentStreamBatch.Timestamp.Unix()), + uint64(a.currentStreamBatch.Timestamp.Unix()), //nolint:gosec a.currentStreamBatch.Coinbase, forcedBlockhashL1, ) diff --git a/aggregator/prover/prover.go b/aggregator/prover/prover.go index a0a782f3..c1fc51d5 100644 --- a/aggregator/prover/prover.go +++ b/aggregator/prover/prover.go @@ -424,7 +424,7 @@ func GetStateRootFromProof(proof string) (common.Hash, error) { if err != nil { log.Fatal(err) } - v[j] = uint64(u64) + v[j] = uint64(u64) //nolint:gosec j++ } bigSR := fea2scalar(v[:]) diff --git a/merkletree/split.go b/merkletree/split.go index e264807a..a2c56cd3 100644 --- a/merkletree/split.go +++ b/merkletree/split.go @@ -39,7 +39,7 @@ func h4ToScalar(h4 []uint64) *big.Int { for i := 1; i < 4; i++ { b2 := new(big.Int).SetUint64(h4[i]) - b2.Lsh(b2, uint(wordLength*i)) + b2.Lsh(b2, uint(wordLength*i)) //nolint:gosec result = result.Add(result, b2) } diff --git a/sequencesender/sequencesender.go b/sequencesender/sequencesender.go index 1a0dcdbb..c1d58b36 100644 --- a/sequencesender/sequencesender.go +++ b/sequencesender/sequencesender.go @@ -530,7 +530,7 @@ func (s *SequenceSender) tryToSendSequence(ctx context.Context) { // Sanity check: Wait also until current time is L1BlockTimestampMargin seconds above the // timestamp of the last L2 block in the sequence for { - currentTime := uint64(time.Now().Unix()) + currentTime := uint64(time.Now().Unix()) //nolint:gosec elapsed, waitTime := s.marginTimeElapsed(lastL2BlockTimestamp, currentTime, timeMargin) diff --git a/state/encoding_batch_v2.go b/state/encoding_batch_v2.go index 9d7d76c6..98c81dee 100644 --- a/state/encoding_batch_v2.go +++ b/state/encoding_batch_v2.go @@ -305,13 +305,13 @@ func DecodeTxRLP(txsData []byte, offset int) (int, *L2TxRaw, error) { if err != nil { return 0, nil, fmt.Errorf("can't get RLP length (offset=%d): %w", offset, err) } - endPos := uint64(offset) + length + rLength + sLength + vLength + EfficiencyPercentageByteLength + endPos := uint64(offset) + length + rLength + sLength + vLength + EfficiencyPercentageByteLength //nolint:gosec if endPos > uint64(len(txsData)) { return 0, nil, fmt.Errorf("can't get tx because not enough data (endPos=%d lenData=%d): %w", endPos, len(txsData), ErrInvalidBatchV2) } fullDataTx := txsData[offset:endPos] - dataStart := uint64(offset) + length + dataStart := uint64(offset) + length //nolint:gosec txInfo := txsData[offset:dataStart] rData := txsData[dataStart : dataStart+rLength] sData := txsData[dataStart+rLength : dataStart+rLength+sLength] @@ -360,7 +360,7 @@ func decodeRLPListLengthFromOffset(txsData []byte, offset int) (uint64, error) { length := num - c0 if length > shortRlp { // If rlp is bigger than length 55 // n is the length of the rlp data without the header (1 byte) for example "0xf7" - pos64 := uint64(offset) + pos64 := uint64(offset) //nolint:gosec lengthInByteOfSize := num - f7 if (pos64 + headerByteLength + lengthInByteOfSize) > txDataLength { log.Debug("error not enough data: ")