Skip to content

Commit

Permalink
fix: linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Sep 13, 2024
1 parent f9e7097 commit 0c64d39
Show file tree
Hide file tree
Showing 32 changed files with 105 additions and 106 deletions.
22 changes: 12 additions & 10 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (a *Aggregator) handleReorg(reorgData synchronizer.ReorgExecutionResult) {
"Halting the aggregator due to a L1 reorg. " +
"Reorged data has been deleted, so it is safe to manually restart the aggregator.",
)
time.Sleep(10 * time.Second) //nolint:gomnd
time.Sleep(10 * time.Second) //nolint:mnd
}
}

Expand Down Expand Up @@ -403,7 +403,7 @@ func (a *Aggregator) handleRollbackBatches(rollbackData synchronizer.RollbackBat
a.halted.Store(true)
for {
log.Errorf("Halting the aggregator due to an error handling rollback batches event: %v", err)
time.Sleep(10 * time.Second) //nolint:gomnd
time.Sleep(10 * time.Second) //nolint:mnd
}
}
}
Expand Down Expand Up @@ -638,7 +638,7 @@ func (a *Aggregator) handleReceivedDataStream(
}

l2TxRaw := state.L2TxRaw{
EfficiencyPercentage: uint8(l2Tx.EffectiveGasPricePercentage),
EfficiencyPercentage: uint8(l2Tx.EffectiveGasPricePercentage), //nolint:gosec
TxAlreadyEncoded: false,
Tx: tx,
}
Expand Down Expand Up @@ -1765,7 +1765,7 @@ func (a *Aggregator) buildInputProver(
forcedBlockhashL1 := common.Hash{}
l1InfoRoot := batchToVerify.L1InfoRoot.Bytes()
if !isForcedBatch {
tree, err := l1infotree.NewL1InfoTree(32, [][32]byte{}) //nolint:gomnd
tree, err := l1infotree.NewL1InfoTree(32, [][32]byte{}) //nolint:mnd
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1818,7 +1818,7 @@ func (a *Aggregator) buildInputProver(
l1InfoTreeData[l2blockRaw.IndexL1InfoTree] = &prover.L1Data{
GlobalExitRoot: l1InfoTreeLeaf.GlobalExitRoot.Bytes(),
BlockhashL1: l1InfoTreeLeaf.PreviousBlockHash.Bytes(),
MinTimestamp: uint32(l1InfoTreeLeaf.Timestamp.Unix()),
MinTimestamp: uint32(l1InfoTreeLeaf.Timestamp.Unix()), //nolint:gosec
SmtProof: protoProof,
}
}
Expand Down Expand Up @@ -1877,10 +1877,12 @@ func (a *Aggregator) buildInputProver(
return inputProver, nil
}

func getWitness(batchNumber uint64, URL string, fullWitness bool) ([]byte, error) {
var witness string
var response rpc.Response
var err error
func getWitness(batchNumber uint64, url string, fullWitness bool) ([]byte, error) {
var (
witness string
response rpc.Response
err error
)

witnessType := "trimmed"
if fullWitness {
Expand All @@ -1889,7 +1891,7 @@ func getWitness(batchNumber uint64, URL string, fullWitness bool) ([]byte, error

log.Infof("Requesting witness for batch %d of type %s", batchNumber, witnessType)

response, err = rpc.JSONRPCCall(URL, "zkevm_getBatchWitness", batchNumber, witnessType)
response, err = rpc.JSONRPCCall(url, "zkevm_getBatchWitness", batchNumber, witnessType)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions aggregator/profitabilitychecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func NewTxProfitabilityCheckerBase(

// IsProfitable checks pol collateral with min reward
func (pc *TxProfitabilityCheckerBase) IsProfitable(ctx context.Context, polCollateral *big.Int) (bool, error) {
//if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// ok, err := isConsolidatedBatchAppeared(ctx, pc.State, pc.IntervalAfterWhichBatchSentAnyway)
// if err != nil {
// return false, err
// }
// if ok {
// return true, nil
// }
//}
// }
return polCollateral.Cmp(pc.MinReward) >= 0, nil
}

Expand All @@ -64,20 +64,20 @@ func NewTxProfitabilityCheckerAcceptAll(state stateInterface, interval time.Dura

// IsProfitable validate batch anyway and don't check anything
func (pc *TxProfitabilityCheckerAcceptAll) IsProfitable(ctx context.Context, polCollateral *big.Int) (bool, error) {
//if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// if pc.IntervalAfterWhichBatchSentAnyway != 0 {
// ok, err := isConsolidatedBatchAppeared(ctx, pc.State, pc.IntervalAfterWhichBatchSentAnyway)
// if err != nil {
// return false, err
// }
// if ok {
// return true, nil
// }
//}
// }
return true, nil
}

// TODO: now it's impossible to check, when batch got consolidated, bcs it's not saved
//func isConsolidatedBatchAppeared(ctx context.Context, state stateInterface,
// func isConsolidatedBatchAppeared(ctx context.Context, state stateInterface,
// intervalAfterWhichBatchConsolidatedAnyway time.Duration) (bool, error) {
// batch, err := state.GetLastVerifiedBatch(ctx, nil)
// if err != nil {
Expand All @@ -89,4 +89,4 @@ func (pc *TxProfitabilityCheckerAcceptAll) IsProfitable(ctx context.Context, pol
// }
//
// return false, err
//}
// }
14 changes: 7 additions & 7 deletions aggregator/prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,13 @@ func fea2scalar(v []uint64) *big.Int {
return big.NewInt(0)
}
res := new(big.Int).SetUint64(v[0])
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[1]), 32)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[2]), 64)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[3]), 96)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[4]), 128)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[5]), 160)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[6]), 192)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[7]), 224)) //nolint:gomnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[1]), 32)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[2]), 64)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[3]), 96)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[4]), 128)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[5]), 160)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[6]), 192)) //nolint:mnd
res.Add(res, new(big.Int).Lsh(new(big.Int).SetUint64(v[7]), 224)) //nolint:mnd

return res
}
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 {
if exitTreeRollback, err = p.exitTree.Reorg(tx, uint32(firstDepositCountReorged)); err != nil { //nolint:gosec
tx.Rollback()
exitTreeRollback()

Expand Down
2 changes: 1 addition & 1 deletion config/types/duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDurationUnmarshal(t *testing.T) {
err = json.Unmarshal(input, &d)

if testCase.expectedResult != nil {
require.Equal(t, (*testCase.expectedResult).Nanoseconds(), d.Nanoseconds())
require.Equal(t, testCase.expectedResult.Nanoseconds(), d.Nanoseconds())
}

if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions dataavailability/datacommittee/datacommittee.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,15 @@ func collectSignatures(
var (
msgs = make(signatureMsgs, 0, len(committee.Members))
collectedSignatures uint64
failedToCollect uint64
failedToCollect int
)
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)-int(failedToCollect) < int(committee.RequiredSignatures) {
if len(committee.Members) < failedToCollect ||
uint64(len(committee.Members)-failedToCollect) < committee.RequiredSignatures {
cancelSignatureCollection()

return nil, errors.New("too many members failed to send their signature")
Expand Down Expand Up @@ -304,7 +305,7 @@ func requestSignatureFromMember(ctx context.Context, signedSequence daTypes.Sign
// request
c := client.New(member.URL)
log.Infof("sending request to sign the sequence to %s at %s", member.Addr.Hex(), member.URL)
//funcSign must call something like that c.SignSequenceBanana(ctx, signedSequence)
// funcSign must call something like that c.SignSequenceBanana(ctx, signedSequence)
signature, err := funcSign(c)

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions etherman/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ var (
ErrGasRequiredExceedsAllowance = errors.New("gas required exceeds allowance")
// ErrContentLengthTooLarge content length is too large
ErrContentLengthTooLarge = errors.New("content length too large")
//ErrTimestampMustBeInsideRange Timestamp must be inside range
// ErrTimestampMustBeInsideRange Timestamp must be inside range
ErrTimestampMustBeInsideRange = errors.New("timestamp must be inside range")
//ErrInsufficientAllowance insufficient allowance
// ErrInsufficientAllowance insufficient allowance
ErrInsufficientAllowance = errors.New("insufficient allowance")
// ErrBothGasPriceAndMaxFeeGasAreSpecified both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified
ErrBothGasPriceAndMaxFeeGasAreSpecified = errors.New(
Expand Down
6 changes: 3 additions & 3 deletions hex/hex.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func DecodeUint64(str string) uint64 {

// EncodeUint64 encodes a number as a hex string with 0x prefix.
func EncodeUint64(i uint64) string {
enc := make([]byte, 2, 10) //nolint:gomnd
enc := make([]byte, 2, 10) //nolint:mnd
copy(enc, "0x")

return string(strconv.AppendUint(enc, i, Base))
Expand All @@ -83,9 +83,9 @@ func DecodeNibble(in byte) uint64 {
case in >= '0' && in <= '9':
return uint64(in - '0')
case in >= 'A' && in <= 'F':
return uint64(in - 'A' + 10) //nolint:gomnd
return uint64(in - 'A' + 10) //nolint:mnd
case in >= 'a' && in <= 'f':
return uint64(in - 'a' + 10) //nolint:gomnd
return uint64(in - 'a' + 10) //nolint:mnd
default:
return BadNibble
}
Expand Down
2 changes: 1 addition & 1 deletion l1infotree/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func generateZeroHashes(height uint8) [][32]byte {
// HashLeafData calculates the keccak hash of the leaf values.
func HashLeafData(ger, prevBlockHash common.Hash, minTimestamp uint64) [32]byte {
var res [32]byte
t := make([]byte, 8) //nolint:gomnd
t := make([]byte, 8) //nolint:mnd
binary.BigEndian.PutUint64(t, minTimestamp)
copy(res[:], keccak256.Hash(ger.Bytes(), prevBlockHash.Bytes(), t))

Expand Down
15 changes: 7 additions & 8 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)),
count: uint32(len(initialLeaves)), //nolint:gosec
}
var err error
mt.siblings, mt.currentRoot, err = mt.initSiblings(initialLeaves)
Expand All @@ -30,8 +30,7 @@ func NewL1InfoTree(height uint8, initialLeaves [][32]byte) (*L1InfoTree, error)

return nil, err
}
log.Debug("Initial count: ", mt.count)
log.Debug("Initial root: ", mt.currentRoot)
log.Debugf("Initial count: %d, Initial root %s", mt.count, mt.currentRoot)

return mt, nil
}
Expand All @@ -43,7 +42,7 @@ func (mt *L1InfoTree) ResetL1InfoTree(initialLeaves [][32]byte) (*L1InfoTree, er
newMT := &L1InfoTree{
zeroHashes: generateZeroHashes(defaultTreeHeight),
height: defaultTreeHeight,
count: uint32(len(initialLeaves)),
count: uint32(len(initialLeaves)), //nolint:gosec
}
var err error
newMT.siblings, newMT.currentRoot, err = newMT.initSiblings(initialLeaves)
Expand Down Expand Up @@ -109,10 +108,10 @@ 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)) {
if index >= uint32(len(leaves)) { //nolint:gosec
siblings = append(siblings, mt.zeroHashes[h])
} else {
if index%2 == 1 { //If it is odd
if index%2 == 1 { // If it is odd
siblings = append(siblings, leaves[index-1])
} else { // It is even
siblings = append(siblings, leaves[index+1])
Expand All @@ -130,7 +129,7 @@ func (mt *L1InfoTree) ComputeMerkleProof(gerIndex uint32, leaves [][32]byte) ([]
}
// Find the index of the leaf in the next level of the tree.
// Divide the index by 2 to find the position in the upper level
index = uint32(float64(index) / 2) //nolint:gomnd
index = uint32(float64(index) / 2) //nolint:mnd
ns = nsi
leaves = hashes
}
Expand Down Expand Up @@ -178,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)) {
if mt.count != uint32(len(initialLeaves)) { //nolint:gosec
return nil, [32]byte{}, fmt.Errorf("error: mt.count and initialLeaves length mismatch")
}
if mt.count == 0 {
Expand Down
18 changes: 10 additions & 8 deletions l1infotreesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type storeLeaf struct {
// Hash as expected by the tree
func (l *storeLeaf) Hash() ethCommon.Hash {
var res [32]byte
t := make([]byte, 8) //nolint:gomnd
t := make([]byte, 8) //nolint:mnd
binary.BigEndian.PutUint64(t, l.Timestamp)
copy(res[:], keccak256.Hash(l.GlobalExitRoot().Bytes(), l.ParentHash.Bytes(), t))

Expand Down 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))
rollbackL1InfoTree, err = p.l1InfoTree.Reorg(tx, uint32(firstReorgedL1InfoTreeIndex)) //nolint:gosec
if err != nil {
tx.Rollback()
rollbackL1InfoTree()
Expand Down Expand Up @@ -376,16 +376,18 @@ func (p *processor) ProcessBlock(ctx context.Context, b sync.Block) error {
l1InfoTreeLeavesToAdd := []tree.Leaf{}
rollupExitTreeLeavesToAdd := []tree.Leaf{}
if len(b.Events) > 0 {
var initialL1InfoIndex uint32
var l1InfoLeavesAdded uint32
var (
initialL1InfoIndex uint32
l1InfoLeavesAdded uint32
)
lastIndex, err := p.getLastIndex(tx)
if errors.Is(err, ErrNotFound) {
switch {
case errors.Is(err, ErrNotFound):
initialL1InfoIndex = 0
} else if err != nil {
case err != nil:
rollback()

return err
} else {
default:
initialL1InfoIndex = lastIndex + 1
}
for _, e := range b.Events {
Expand Down
2 changes: 1 addition & 1 deletion log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewLogger(cfg Config) (*zap.SugaredLogger, *zap.AtomicLevel, error) {
defer logger.Sync() //nolint:errcheck

// skip 2 callers: one for our wrapper methods and one for the package functions
withOptions := logger.WithOptions(zap.AddCallerSkip(2)) //nolint:gomnd
withOptions := logger.WithOptions(zap.AddCallerSkip(2)) //nolint:mnd
return withOptions.Sugar(), &level, nil
}

Expand Down
2 changes: 1 addition & 1 deletion log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestLog(t *testing.T) {
cfg := Config{
Environment: EnvironmentDevelopment,
Level: "debug",
Outputs: []string{"stderr"}, //[]string{"stdout", "test.log"}
Outputs: []string{"stderr"}, // []string{"stdout", "test.log"}
}

Init(cfg)
Expand Down
6 changes: 3 additions & 3 deletions merkletree/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ func HashContractBytecode(code []byte) ([]uint64, error) {
)

// add 0x01
code = append(code, 0x01) //nolint:gomnd
code = append(code, 0x01) //nolint:mnd

// add padding
for len(code)%(56) != 0 {
code = append(code, 0x00) //nolint:gomnd
code = append(code, 0x00) //nolint:mnd
}

code[len(code)-1] = code[len(code)-1] | 0x80 //nolint:gomnd
code[len(code)-1] = code[len(code)-1] | 0x80 //nolint:mnd

numHashes := int(math.Ceil(float64(len(code)) / float64(maxBytesToAdd)))

Expand Down
20 changes: 10 additions & 10 deletions merkletree/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ const wordLength = 64

// scalar2fea splits a *big.Int into array of 32bit uint64 values.
func scalar2fea(value *big.Int) []uint64 {
val := make([]uint64, 8) //nolint:gomnd
mask, _ := new(big.Int).SetString("FFFFFFFF", 16) //nolint:gomnd
val := make([]uint64, 8) //nolint:mnd
mask, _ := new(big.Int).SetString("FFFFFFFF", 16) //nolint:mnd
val[0] = new(big.Int).And(value, mask).Uint64()
val[1] = new(big.Int).And(new(big.Int).Rsh(value, 32), mask).Uint64() //nolint:gomnd
val[2] = new(big.Int).And(new(big.Int).Rsh(value, 64), mask).Uint64() //nolint:gomnd
val[3] = new(big.Int).And(new(big.Int).Rsh(value, 96), mask).Uint64() //nolint:gomnd
val[4] = new(big.Int).And(new(big.Int).Rsh(value, 128), mask).Uint64() //nolint:gomnd
val[5] = new(big.Int).And(new(big.Int).Rsh(value, 160), mask).Uint64() //nolint:gomnd
val[6] = new(big.Int).And(new(big.Int).Rsh(value, 192), mask).Uint64() //nolint:gomnd
val[7] = new(big.Int).And(new(big.Int).Rsh(value, 224), mask).Uint64() //nolint:gomnd
val[1] = new(big.Int).And(new(big.Int).Rsh(value, 32), mask).Uint64() //nolint:mnd
val[2] = new(big.Int).And(new(big.Int).Rsh(value, 64), mask).Uint64() //nolint:mnd
val[3] = new(big.Int).And(new(big.Int).Rsh(value, 96), mask).Uint64() //nolint:mnd
val[4] = new(big.Int).And(new(big.Int).Rsh(value, 128), mask).Uint64() //nolint:mnd
val[5] = new(big.Int).And(new(big.Int).Rsh(value, 160), mask).Uint64() //nolint:mnd
val[6] = new(big.Int).And(new(big.Int).Rsh(value, 192), mask).Uint64() //nolint:mnd
val[7] = new(big.Int).And(new(big.Int).Rsh(value, 224), mask).Uint64() //nolint:mnd
return val
}

Expand Down Expand Up @@ -69,7 +69,7 @@ func StringToh4(str string) ([]uint64, error) {
func scalarToh4(s *big.Int) []uint64 {
b := ScalarToFilledByteSlice(s)

r := make([]uint64, 4) //nolint:gomnd
r := make([]uint64, 4) //nolint:mnd

f, _ := hex.DecodeHex("0xFFFFFFFFFFFFFFFF")
fbe := binary.BigEndian.Uint64(f)
Expand Down
Loading

0 comments on commit 0c64d39

Please sign in to comment.