Skip to content

Commit

Permalink
fix: suppress gosec overflow issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Sep 13, 2024
1 parent 2f28035 commit 99a6705
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
9 changes: 6 additions & 3 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -1780,7 +1780,10 @@ func (a *Aggregator) buildInputProver(

aLeaves := make([][32]byte, len(leaves))
for i, leaf := range leaves {
aLeaves[i] = l1infotree.HashLeafData(leaf.GlobalExitRoot, leaf.PreviousBlockHash, uint64(leaf.Timestamp.Unix()))
aLeaves[i] = l1infotree.HashLeafData(
leaf.GlobalExitRoot,
leaf.PreviousBlockHash,
uint64(leaf.Timestamp.Unix())) //nolint:gosec
}

for _, l2blockRaw := range batchRawData.Blocks {
Expand Down Expand Up @@ -1867,7 +1870,7 @@ func (a *Aggregator) buildInputProver(
ForkId: batchToVerify.ForkID,
BatchL2Data: batchToVerify.BatchL2Data,
L1InfoRoot: l1InfoRoot,
TimestampLimit: uint64(batchToVerify.Timestamp.Unix()),
TimestampLimit: uint64(batchToVerify.Timestamp.Unix()), //nolint:gosec
SequencerAddr: batchToVerify.Coinbase.String(),
AggregatorAddr: a.cfg.SenderAddress,
L1InfoTreeData: l1InfoTreeData,
Expand Down
2 changes: 1 addition & 1 deletion aggregator/prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:])
Expand Down
5 changes: 2 additions & 3 deletions dataavailability/datacommittee/datacommittee.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,14 @@ func collectSignatures(
var (
msgs = make(signatureMsgs, 0, len(committee.Members))
collectedSignatures uint64
failedToCollect int
failedToCollect uint64
)
for collectedSignatures < committee.RequiredSignatures {
msg := <-ch
if msg.err != nil {
log.Errorf("error when trying to get signature from %s: %s", msg.addr, msg.err)
failedToCollect++
if len(committee.Members) < failedToCollect ||
uint64(len(committee.Members)-failedToCollect) < committee.RequiredSignatures {
if len(committee.Members)-int(failedToCollect) < int(committee.RequiredSignatures) { //nolint:gosec
cancelSignatureCollection()

return nil, errors.New("too many members failed to send their signature")
Expand Down
2 changes: 1 addition & 1 deletion merkletree/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion sequencesender/sequencesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions state/encoding_batch_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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: ")
Expand Down

0 comments on commit 99a6705

Please sign in to comment.