Skip to content

Commit

Permalink
fix: exclude G115 gosec linter rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Sep 13, 2024
1 parent 99a6705 commit 3dc1b8a
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ linters-settings:
goconst:
min-len: 3
min-occurrences: 3
gosec:
excludes:
- G115 # Potential integer overflow when converting between integer types

issues:
whole-files: true
Expand Down
10 changes: 5 additions & 5 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()), //nolint:gosec
uint64(a.currentStreamBatch.Timestamp.Unix()),
a.currentStreamBatch.Coinbase,
forcedBlockhashL1,
)
Expand Down Expand Up @@ -639,7 +639,7 @@ func (a *Aggregator) handleReceivedDataStream(
}

l2TxRaw := state.L2TxRaw{
EfficiencyPercentage: uint8(l2Tx.EffectiveGasPricePercentage), //nolint:gosec
EfficiencyPercentage: uint8(l2Tx.EffectiveGasPricePercentage),
TxAlreadyEncoded: false,
Tx: tx,
}
Expand Down Expand Up @@ -1783,7 +1783,7 @@ func (a *Aggregator) buildInputProver(
aLeaves[i] = l1infotree.HashLeafData(
leaf.GlobalExitRoot,
leaf.PreviousBlockHash,
uint64(leaf.Timestamp.Unix())) //nolint:gosec
uint64(leaf.Timestamp.Unix()))
}

for _, l2blockRaw := range batchRawData.Blocks {
Expand Down Expand Up @@ -1824,7 +1824,7 @@ func (a *Aggregator) buildInputProver(
l1InfoTreeData[l2blockRaw.IndexL1InfoTree] = &prover.L1Data{
GlobalExitRoot: l1InfoTreeLeaf.GlobalExitRoot.Bytes(),
BlockhashL1: l1InfoTreeLeaf.PreviousBlockHash.Bytes(),
MinTimestamp: uint32(l1InfoTreeLeaf.Timestamp.Unix()), //nolint:gosec
MinTimestamp: uint32(l1InfoTreeLeaf.Timestamp.Unix()),
SmtProof: protoProof,
}
}
Expand Down Expand Up @@ -1870,7 +1870,7 @@ func (a *Aggregator) buildInputProver(
ForkId: batchToVerify.ForkID,
BatchL2Data: batchToVerify.BatchL2Data,
L1InfoRoot: l1InfoRoot,
TimestampLimit: uint64(batchToVerify.Timestamp.Unix()), //nolint:gosec
TimestampLimit: uint64(batchToVerify.Timestamp.Unix()),
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) //nolint:gosec
v[j] = uint64(u64)
j++
}
bigSR := fea2scalar(v[:])
Expand Down
2 changes: 1 addition & 1 deletion bridgesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (p *processor) Reorg(ctx context.Context, firstReorgedBlock uint64) error {
}
exitTreeRollback := func() {}
if firstDepositCountReorged != -1 {
if exitTreeRollback, err = p.exitTree.Reorg(tx, uint32(firstDepositCountReorged)); err != nil { //nolint:gosec
if exitTreeRollback, err = p.exitTree.Reorg(tx, uint32(firstDepositCountReorged)); err != nil {
tx.Rollback()
exitTreeRollback()

Expand Down
4 changes: 2 additions & 2 deletions dataavailability/datacommittee/datacommittee.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (d *Backend) Init() error {
if committee != nil {
d.committeeMembers = committee.Members
if len(committee.Members) > 0 {
selectedCommitteeMember = rand.Intn(len(committee.Members)) //nolint:gosec
selectedCommitteeMember = rand.Intn(len(committee.Members))

Check failure on line 94 in dataavailability/datacommittee/datacommittee.go

View workflow job for this annotation

GitHub Actions / lint

G404: Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand) (gosec)
}
}
d.selectedCommitteeMember = selectedCommitteeMember
Expand Down Expand Up @@ -270,7 +270,7 @@ func collectSignatures(
if msg.err != nil {
log.Errorf("error when trying to get signature from %s: %s", msg.addr, msg.err)
failedToCollect++
if len(committee.Members)-int(failedToCollect) < int(committee.RequiredSignatures) { //nolint:gosec
if len(committee.Members)-int(failedToCollect) < int(committee.RequiredSignatures) {
cancelSignatureCollection()

return nil, errors.New("too many members failed to send their signature")
Expand Down
8 changes: 4 additions & 4 deletions l1infotree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewL1InfoTree(height uint8, initialLeaves [][32]byte) (*L1InfoTree, error)
mt := &L1InfoTree{
zeroHashes: generateZeroHashes(height),
height: height,
count: uint32(len(initialLeaves)), //nolint:gosec
count: uint32(len(initialLeaves)),
}
var err error
mt.siblings, mt.currentRoot, err = mt.initSiblings(initialLeaves)
Expand All @@ -42,7 +42,7 @@ func (mt *L1InfoTree) ResetL1InfoTree(initialLeaves [][32]byte) (*L1InfoTree, er
newMT := &L1InfoTree{
zeroHashes: generateZeroHashes(defaultTreeHeight),
height: defaultTreeHeight,
count: uint32(len(initialLeaves)), //nolint:gosec
count: uint32(len(initialLeaves)),
}
var err error
newMT.siblings, newMT.currentRoot, err = newMT.initSiblings(initialLeaves)
Expand Down Expand Up @@ -108,7 +108,7 @@ func (mt *L1InfoTree) ComputeMerkleProof(gerIndex uint32, leaves [][32]byte) ([]
if len(leaves)%2 == 1 {
leaves = append(leaves, mt.zeroHashes[h])
}
if index >= uint32(len(leaves)) { //nolint:gosec
if index >= uint32(len(leaves)) {
siblings = append(siblings, mt.zeroHashes[h])
} else {
if index%2 == 1 { // If it is odd
Expand Down Expand Up @@ -177,7 +177,7 @@ func (mt *L1InfoTree) AddLeaf(index uint32, leaf [32]byte) (common.Hash, error)
// initSiblings returns the siblings of the node at the given index.
// it is used to initialize the siblings array in the beginning.
func (mt *L1InfoTree) initSiblings(initialLeaves [][32]byte) ([][32]byte, common.Hash, error) {
if mt.count != uint32(len(initialLeaves)) { //nolint:gosec
if mt.count != uint32(len(initialLeaves)) {
return nil, [32]byte{}, fmt.Errorf("error: mt.count and initialLeaves length mismatch")
}
if mt.count == 0 {
Expand Down
2 changes: 1 addition & 1 deletion l1infotreesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (p *processor) Reorg(ctx context.Context, firstReorgedBlock uint64) error {
}
var rollbackL1InfoTree func()
if firstReorgedL1InfoTreeIndex != -1 {
rollbackL1InfoTree, err = p.l1InfoTree.Reorg(tx, uint32(firstReorgedL1InfoTreeIndex)) //nolint:gosec
rollbackL1InfoTree, err = p.l1InfoTree.Reorg(tx, uint32(firstReorgedL1InfoTreeIndex))
if err != nil {
tx.Rollback()
rollbackL1InfoTree()
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)) //nolint:gosec
b2.Lsh(b2, uint(wordLength*i))
result = result.Add(result, b2)
}

Expand Down
12 changes: 6 additions & 6 deletions 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()) //nolint:gosec
currentTime := uint64(time.Now().Unix())

elapsed, waitTime := s.marginTimeElapsed(lastL2BlockTimestamp, currentTime, timeMargin)

Expand Down Expand Up @@ -834,11 +834,11 @@ func (s *SequenceSender) entryTypeToString(entryType datastream.EntryType) strin
func (s *SequenceSender) handleReceivedDataStream(
entry *datastreamer.FileEntry, client *datastreamer.StreamClient, server *datastreamer.StreamServer,
) error {
dsType := datastream.EntryType(entry.Type) //nolint:gosec
dsType := datastream.EntryType(entry.Type)

var prevEntryType datastream.EntryType
if s.prevStreamEntry != nil {
prevEntryType = datastream.EntryType(s.prevStreamEntry.Type) //nolint:gosec
prevEntryType = datastream.EntryType(s.prevStreamEntry.Type)
}

switch dsType {
Expand Down Expand Up @@ -1218,7 +1218,7 @@ func (s *SequenceSender) addNewBlockTx(l2Tx *datastream.Transaction) {
}

l2TxRaw := state.L2TxRaw{
EfficiencyPercentage: uint8(l2Tx.EffectiveGasPricePercentage), //nolint:gosec
EfficiencyPercentage: uint8(l2Tx.EffectiveGasPricePercentage),
TxAlreadyEncoded: false,
Tx: tx,
}
Expand Down Expand Up @@ -1272,9 +1272,9 @@ func (s *SequenceSender) marginTimeElapsed(
var timeDiff int64
if l2BlockTimestamp >= currentTime {
// L2 block timestamp is above currentTime, negative timeDiff. We do in this way to avoid uint64 overflow
timeDiff = int64(-(l2BlockTimestamp - currentTime)) //nolint:gosec
timeDiff = int64(-(l2BlockTimestamp - currentTime))
} else {
timeDiff = int64(currentTime - l2BlockTimestamp) //nolint:gosec
timeDiff = int64(currentTime - l2BlockTimestamp)
}

// Check if the time difference is less than timeMargin (L1BlockTimestampMargin)
Expand Down
8 changes: 4 additions & 4 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 //nolint:gosec
endPos := uint64(offset) + length + rLength + sLength + vLength + EfficiencyPercentageByteLength
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 //nolint:gosec
dataStart := uint64(offset) + length
txInfo := txsData[offset:dataStart]
rData := txsData[dataStart : dataStart+rLength]
sData := txsData[dataStart+rLength : dataStart+rLength+sLength]
Expand Down Expand Up @@ -344,7 +344,7 @@ func DecodeTxRLP(txsData []byte, offset int) (int, *L2TxRaw, error) {
EfficiencyPercentage: efficiencyPercentage,
}

return int(endPos), l2Tx, err //nolint:gosec
return int(endPos), l2Tx, err
}

// It returns the length of data from the param offset
Expand All @@ -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) //nolint:gosec
pos64 := uint64(offset)
lengthInByteOfSize := num - f7
if (pos64 + headerByteLength + lengthInByteOfSize) > txDataLength {
log.Debug("error not enough data: ")
Expand Down
6 changes: 3 additions & 3 deletions tree/appendonlytree.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (t *AppendOnlyTree) GetIndexByRoot(ctx context.Context, root common.Hash) (
defer tx.Rollback()

index, err := t.getIndexByRoot(tx, root)
return uint32(index), err //nolint:gosec
return uint32(index), err
}

// GetLastIndexAndRoot returns the last index and root added to the tree
Expand All @@ -131,7 +131,7 @@ func (t *AppendOnlyTree) GetLastIndexAndRoot(ctx context.Context) (uint32, commo
if i == -1 {
return 0, common.Hash{}, ErrNotFound
}
return uint32(i), root, nil //nolint:gosec
return uint32(i), root, nil
}

func (t *AppendOnlyTree) initLastLeftCacheAndLastDepositCount(ctx context.Context) error {
Expand Down Expand Up @@ -203,7 +203,7 @@ func (t *AppendOnlyTree) Reorg(tx kv.RwTx, firstReorgedIndex uint32) (func(), er
return func() {}, nil
}
// Clean root table
for i := firstReorgedIndex; i <= uint32(t.lastIndex); i++ { //nolint:gosec
for i := firstReorgedIndex; i <= uint32(t.lastIndex); i++ {
if err := tx.Delete(t.rootTable, dbCommon.Uint64ToBytes(uint64(i))); err != nil {
return func() {}, err
}
Expand Down
2 changes: 1 addition & 1 deletion tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (t *Tree) getLastIndexAndRootWithTx(tx kv.Tx) (int64, common.Hash, error) {
if lastIndexBytes == nil {
return -1, common.Hash{}, nil
}
return int64(dbCommon.BytesToUint64(lastIndexBytes)), common.Hash(rootBytes), nil //nolint:gosec
return int64(dbCommon.BytesToUint64(lastIndexBytes)), common.Hash(rootBytes), nil
}

func (t *Tree) GetLeaf(ctx context.Context, index uint32, root common.Hash) (common.Hash, error) {
Expand Down

0 comments on commit 3dc1b8a

Please sign in to comment.