From f53b9033cdeb0e7a0d783060671b169bc529ea20 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Fri, 25 Oct 2024 09:36:05 -0500 Subject: [PATCH] golangci-lint: --fix nolintlint issues --- .../ccipreader/ccipreader_test.go | 4 ++-- core/capabilities/ccip/ccipevm/encodingUtilsAbi.json | 1 + core/capabilities/ccip/ccipevm/rmncrypto.go | 7 +++++-- core/capabilities/integration_tests/framework/don.go | 1 - .../integration_tests/framework/ethereum.go | 1 - core/capabilities/integration_tests/keystone/setup.go | 2 +- core/chains/evm/client/simulated_backend_client.go | 9 ++++++--- core/chains/evm/txmgr/client.go | 2 +- core/cmd/shell_local.go | 1 - core/services/llo/mercurytransmitter/orm.go | 4 ++-- core/services/ocrcommon/adapters.go | 2 +- .../relay/evm/capabilities/testutils/backend.go | 11 +++++++++-- core/services/relay/evm/evm.go | 2 +- .../evm/mercury/v1/reportcodec/report_codec_test.go | 2 +- core/services/relay/relay.go | 2 +- core/store/migrate/migrate.go | 2 -- core/store/migrate/migrations/0036_external_job_id.go | 1 - core/utils/utils.go | 2 -- 18 files changed, 31 insertions(+), 25 deletions(-) create mode 100644 core/capabilities/ccip/ccipevm/encodingUtilsAbi.json diff --git a/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go b/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go index ff5d62205d0..cae5cc90ab8 100644 --- a/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go +++ b/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go @@ -79,7 +79,7 @@ func TestCCIPReader_CommitReportsGTETimestamp(t *testing.T) { tokenA := common.HexToAddress("123") const numReports = 5 - for i := 0; i < numReports; i++ { + for i := uint8(0); i < numReports; i++ { _, err := s.contract.EmitCommitReportAccepted(s.auth, ccip_reader_tester.OffRampCommitReport{ PriceUpdates: ccip_reader_tester.InternalPriceUpdates{ TokenPriceUpdates: []ccip_reader_tester.InternalTokenPriceUpdate{ @@ -100,7 +100,7 @@ func TestCCIPReader_CommitReportsGTETimestamp(t *testing.T) { SourceChainSelector: uint64(chainS1), MinSeqNr: 10, MaxSeqNr: 20, - MerkleRoot: [32]byte{uint8(i) + 1}, //nolint:gosec // this won't overflow + MerkleRoot: [32]byte{i + 1}, OnRampAddress: common.LeftPadBytes(onRampAddress.Bytes(), 32), }, }, diff --git a/core/capabilities/ccip/ccipevm/encodingUtilsAbi.json b/core/capabilities/ccip/ccipevm/encodingUtilsAbi.json new file mode 100644 index 00000000000..4ebb363bffe --- /dev/null +++ b/core/capabilities/ccip/ccipevm/encodingUtilsAbi.json @@ -0,0 +1 @@ +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DoNotDeploy","type":"error"},{"inputs":[{"internalType":"bytes32","name":"rmnReportVersion","type":"bytes32"},{"components":[{"internalType":"uint256","name":"destChainId","type":"uint256"},{"internalType":"uint64","name":"destChainSelector","type":"uint64"},{"internalType":"address","name":"rmnRemoteContractAddress","type":"address"},{"internalType":"address","name":"offrampAddress","type":"address"},{"internalType":"bytes32","name":"rmnHomeContractConfigDigest","type":"bytes32"},{"components":[{"internalType":"uint64","name":"sourceChainSelector","type":"uint64"},{"internalType":"bytes","name":"onRampAddress","type":"bytes"},{"internalType":"uint64","name":"minSeqNr","type":"uint64"},{"internalType":"uint64","name":"maxSeqNr","type":"uint64"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"internalType":"struct Internal.MerkleRoot[]","name":"destLaneUpdates","type":"tuple[]"}],"internalType":"struct RMNRemote.Report","name":"rmnReport","type":"tuple"}],"name":"_rmnReport","outputs":[],"stateMutability":"nonpayable","type":"function"}] \ No newline at end of file diff --git a/core/capabilities/ccip/ccipevm/rmncrypto.go b/core/capabilities/ccip/ccipevm/rmncrypto.go index 1b97f5cc3bb..37b909dabe2 100644 --- a/core/capabilities/ccip/ccipevm/rmncrypto.go +++ b/core/capabilities/ccip/ccipevm/rmncrypto.go @@ -3,6 +3,7 @@ package ccipevm import ( "bytes" "context" + _ "embed" "errors" "fmt" "math/big" @@ -18,8 +19,10 @@ import ( // encodingUtilsAbi is the ABI for the EncodingUtils contract. // Should be imported when gethwrappers are moved from ccip repo to core. -// nolint:lll -const encodingUtilsAbiRaw = `[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DoNotDeploy","type":"error"},{"inputs":[{"internalType":"bytes32","name":"rmnReportVersion","type":"bytes32"},{"components":[{"internalType":"uint256","name":"destChainId","type":"uint256"},{"internalType":"uint64","name":"destChainSelector","type":"uint64"},{"internalType":"address","name":"rmnRemoteContractAddress","type":"address"},{"internalType":"address","name":"offrampAddress","type":"address"},{"internalType":"bytes32","name":"rmnHomeContractConfigDigest","type":"bytes32"},{"components":[{"internalType":"uint64","name":"sourceChainSelector","type":"uint64"},{"internalType":"bytes","name":"onRampAddress","type":"bytes"},{"internalType":"uint64","name":"minSeqNr","type":"uint64"},{"internalType":"uint64","name":"maxSeqNr","type":"uint64"},{"internalType":"bytes32","name":"merkleRoot","type":"bytes32"}],"internalType":"struct Internal.MerkleRoot[]","name":"destLaneUpdates","type":"tuple[]"}],"internalType":"struct RMNRemote.Report","name":"rmnReport","type":"tuple"}],"name":"_rmnReport","outputs":[],"stateMutability":"nonpayable","type":"function"}]` +// +//go:embed encodingUtilsAbi.json +var encodingUtilsAbiRaw string + const addressEncodeAbiRaw = `[{"name":"method","type":"function","inputs":[{"name": "", "type": "address"}]}]` var ( diff --git a/core/capabilities/integration_tests/framework/don.go b/core/capabilities/integration_tests/framework/don.go index 1cb38c1bf71..01e987e66b0 100644 --- a/core/capabilities/integration_tests/framework/don.go +++ b/core/capabilities/integration_tests/framework/don.go @@ -137,7 +137,6 @@ func (d *DON) Initialise() { if len(d.externalCapabilities) > 0 { id := d.capabilitiesRegistry.setupDON(d.config, d.externalCapabilities) - //nolint:gosec // disable G115 d.config.DON.ID = uint32(id) } } diff --git a/core/capabilities/integration_tests/framework/ethereum.go b/core/capabilities/integration_tests/framework/ethereum.go index 47558dacfcb..12e8392610c 100644 --- a/core/capabilities/integration_tests/framework/ethereum.go +++ b/core/capabilities/integration_tests/framework/ethereum.go @@ -33,7 +33,6 @@ type EthBlockchain struct { func NewEthBlockchain(t *testing.T, initialEth int, blockTimeProcessingTime time.Duration) *EthBlockchain { transactOpts := testutils.MustNewSimTransactor(t) // config contract deployer and owner genesisData := core.GenesisAlloc{transactOpts.From: {Balance: assets.Ether(initialEth).ToInt()}} - //nolint:gosec // disable G115 backend := cltest.NewSimulatedBackend(t, genesisData, uint32(ethconfig.Defaults.Miner.GasCeil)) gethlog.SetDefault(gethlog.NewLogger(gethlog.NewTerminalHandlerWithLevel(os.Stderr, gethlog.LevelWarn, true))) backend.Commit() diff --git a/core/capabilities/integration_tests/keystone/setup.go b/core/capabilities/integration_tests/keystone/setup.go index f90b582d0ee..28729fd4b5d 100644 --- a/core/capabilities/integration_tests/keystone/setup.go +++ b/core/capabilities/integration_tests/keystone/setup.go @@ -126,7 +126,7 @@ func newReport(t *testing.T, feedID [32]byte, price *big.Int, timestamp int64) [ v3Codec := reportcodec.NewReportCodec(feedID, logger.TestLogger(t)) raw, err := v3Codec.BuildReport(ctx, v3.ReportFields{ BenchmarkPrice: price, - //nolint:gosec // disable G115 + Timestamp: uint32(timestamp), Bid: big.NewInt(0), Ask: big.NewInt(0), diff --git a/core/chains/evm/client/simulated_backend_client.go b/core/chains/evm/client/simulated_backend_client.go index a831f38d10d..c3c67a1c2c9 100644 --- a/core/chains/evm/client/simulated_backend_client.go +++ b/core/chains/evm/client/simulated_backend_client.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "math" "math/big" "strings" "testing" @@ -18,10 +19,9 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rpc" - "github.com/smartcontractkit/chainlink-common/pkg/utils/hex" - "github.com/smartcontractkit/chainlink-common/pkg/assets" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/hex" commonclient "github.com/smartcontractkit/chainlink/v2/common/client" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" @@ -319,9 +319,12 @@ func (c *SimulatedBackendClient) SubscribeToHeads( case h := <-ch: var head *evmtypes.Head if h != nil { + if h.Time > math.MaxInt64 { + c.t.Fatalf("time overflows int64: %d", h.Time) + } head = &evmtypes.Head{ Difficulty: h.Difficulty, - Timestamp: time.Unix(int64(h.Time), 0), //nolint:gosec + Timestamp: time.Unix(int64(h.Time), 0), //nolint:gosec // G115 false positive Number: h.Number.Int64(), Hash: h.Hash(), ParentHash: h.ParentHash, diff --git a/core/chains/evm/txmgr/client.go b/core/chains/evm/txmgr/client.go index dfaa4e6bfd8..851946ce125 100644 --- a/core/chains/evm/txmgr/client.go +++ b/core/chains/evm/txmgr/client.go @@ -121,7 +121,7 @@ func (c *evmTxmClient) SequenceAt(ctx context.Context, addr common.Address, bloc if nonce > math.MaxInt64 { return 0, fmt.Errorf("overflow for nonce: %d", nonce) } - //nolint:gosec // disable G115 + return evmtypes.Nonce(nonce), err } diff --git a/core/cmd/shell_local.go b/core/cmd/shell_local.go index 3fca9d6ad09..c18af08a64b 100644 --- a/core/cmd/shell_local.go +++ b/core/cmd/shell_local.go @@ -685,7 +685,6 @@ func (s *Shell) RebroadcastTransactions(c *cli.Context) (err error) { nonces[i] = evmtypes.Nonce(beginningNonce + i) } if gasPriceWei <= math.MaxInt64 { - //nolint:gosec // disable G115 return s.errorOut(ec.ForceRebroadcast(ctx, nonces, gas.EvmFee{GasPrice: assets.NewWeiI(int64(gasPriceWei))}, address, uint64(overrideGasLimit))) } return s.errorOut(fmt.Errorf("integer overflow conversion error. GasPrice: %v", gasPriceWei)) diff --git a/core/services/llo/mercurytransmitter/orm.go b/core/services/llo/mercurytransmitter/orm.go index ed8c8843f4c..045161395b5 100644 --- a/core/services/llo/mercurytransmitter/orm.go +++ b/core/services/llo/mercurytransmitter/orm.go @@ -72,7 +72,7 @@ func (o *orm) Insert(ctx context.Context, transmissions []*Transmission) error { DonID: o.donID, ServerURL: t.ServerURL, ConfigDigest: t.ConfigDigest, - SeqNr: int64(t.SeqNr), //nolint + SeqNr: int64(t.SeqNr), //nolint:gosec // G115 false positive Report: t.Report.Report, LifecycleStage: string(t.Report.Info.LifeCycleStage), ReportFormat: uint32(t.Report.Info.ReportFormat), @@ -162,7 +162,7 @@ func (o *orm) Get(ctx context.Context, serverURL string) ([]*Transmission, error } transmission.Sigs = append(transmission.Sigs, ocrtypes.AttributedOnchainSignature{ Signature: sig, - Signer: commontypes.OracleID(signers[i]), //nolint + Signer: commontypes.OracleID(signers[i]), //nolint:gosec // G115 false positive }) } diff --git a/core/services/ocrcommon/adapters.go b/core/services/ocrcommon/adapters.go index 33e4971bc82..cbb2af04576 100644 --- a/core/services/ocrcommon/adapters.go +++ b/core/services/ocrcommon/adapters.go @@ -112,7 +112,7 @@ func MarshalMultichainPublicKey(ost map[string]ocrtypes.OnchainPublicKey) (ocrty if length < 0 || length > math.MaxUint16 { return nil, fmt.Errorf("pubKey doesn't fit into uint16") } - if err = binary.Write(buf, binary.LittleEndian, uint16(length)); err != nil { //nolint:gosec + if err = binary.Write(buf, binary.LittleEndian, uint16(length)); err != nil { //nolint:gosec // G115 false positive return nil, err } _, _ = buf.Write(pubKey) diff --git a/core/services/relay/evm/capabilities/testutils/backend.go b/core/services/relay/evm/capabilities/testutils/backend.go index ef5761b3e4c..3cd003e3edf 100644 --- a/core/services/relay/evm/capabilities/testutils/backend.go +++ b/core/services/relay/evm/capabilities/testutils/backend.go @@ -3,6 +3,7 @@ package testutils import ( "context" "encoding/json" + "math" "math/big" "testing" "time" @@ -56,9 +57,15 @@ func NewEVMBackendTH(t *testing.T) *EVMBackendTH { contractsOwner.From: {Balance: assets.Ether(100000).ToInt()}, } chainID := testutils.SimulatedChainID - gasLimit := uint32(ethconfig.Defaults.Miner.GasCeil) //nolint:gosec + if ethconfig.Defaults.Miner.GasCeil > math.MaxUint32 { + t.Fatalf("gas ceiling overflows uint32: %d", ethconfig.Defaults.Miner.GasCeil) + } + gasLimit := uint32(ethconfig.Defaults.Miner.GasCeil) backend := cltest.NewSimulatedBackend(t, genesisData, gasLimit) - blockTime := time.UnixMilli(int64(backend.Blockchain().CurrentHeader().Time)) //nolint:gosec + if backend.Blockchain().CurrentHeader().Time > math.MaxInt64 { + t.Fatalf("header time overflows int64: %d", backend.Blockchain().CurrentHeader().Time) + } + blockTime := time.UnixMilli(int64(backend.Blockchain().CurrentHeader().Time)) err = backend.AdjustTime(time.Since(blockTime) - 24*time.Hour) require.NoError(t, err) backend.Commit() diff --git a/core/services/relay/evm/evm.go b/core/services/relay/evm/evm.go index 19be4b670b3..efed5057076 100644 --- a/core/services/relay/evm/evm.go +++ b/core/services/relay/evm/evm.go @@ -85,7 +85,7 @@ func init() { } } -var _ commontypes.Relayer = &Relayer{} //nolint:staticcheck +var _ commontypes.Relayer = &Relayer{} // The current PluginProvider interface does not support an error return. This was fine up until CCIP. // CCIP is the first product to introduce the idea of incomplete implementations of a provider based on diff --git a/core/services/relay/evm/mercury/v1/reportcodec/report_codec_test.go b/core/services/relay/evm/mercury/v1/reportcodec/report_codec_test.go index b24e69ce387..f42df86ec6e 100644 --- a/core/services/relay/evm/mercury/v1/reportcodec/report_codec_test.go +++ b/core/services/relay/evm/mercury/v1/reportcodec/report_codec_test.go @@ -157,7 +157,7 @@ func (r *ReportCodec) ValidFromBlockNumFromReport(report ocrtypes.Report) (int64 if n > math.MaxInt64 { return 0, fmt.Errorf("ValidFromBlockNum=%d overflows max int64", n) } - return int64(n), nil //nolint:gosec // G115 + return int64(n), nil //nolint:gosec // G115 false positive } func Test_ReportCodec_ValidFromBlockNumFromReport(t *testing.T) { diff --git a/core/services/relay/relay.go b/core/services/relay/relay.go index 913923a9b2f..0b1293c8d79 100644 --- a/core/services/relay/relay.go +++ b/core/services/relay/relay.go @@ -37,7 +37,7 @@ type ServerAdapter struct { } // NewServerAdapter returns a new ServerAdapter. -func NewServerAdapter(r types.Relayer) *ServerAdapter { //nolint:staticcheck +func NewServerAdapter(r types.Relayer) *ServerAdapter { return &ServerAdapter{Relayer: r} } diff --git a/core/store/migrate/migrate.go b/core/store/migrate/migrate.go index 7c3d3deaaf0..c8d4a0e9621 100644 --- a/core/store/migrate/migrate.go +++ b/core/store/migrate/migrate.go @@ -105,8 +105,6 @@ func ensureMigrated(ctx context.Context, db *sql.DB, p *goose.Provider, provider } // insert records for existing migrations - //nolint - sql := fmt.Sprintf(`INSERT INTO %s (version_id, is_applied) VALUES ($1, true);`, providerTableName) return sqlutil.TransactDataSource(ctx, sqlxDB, nil, func(tx sqlutil.DataSource) error { for _, name := range names { diff --git a/core/store/migrate/migrations/0036_external_job_id.go b/core/store/migrate/migrations/0036_external_job_id.go index e8012da5e78..2e69a161132 100644 --- a/core/store/migrate/migrations/0036_external_job_id.go +++ b/core/store/migrate/migrations/0036_external_job_id.go @@ -31,7 +31,6 @@ const ( ` ) -// nolint func Up36(ctx context.Context, tx *sql.Tx) error { // Add the external ID column and remove type specific ones. if _, err := tx.ExecContext(ctx, up36_1); err != nil { diff --git a/core/utils/utils.go b/core/utils/utils.go index 237f6a43589..af41ef80ace 100644 --- a/core/utils/utils.go +++ b/core/utils/utils.go @@ -594,8 +594,6 @@ func (eb *ErrorBuffer) SetCap(cap int) { } // UnwrapError returns a list of underlying errors if passed error implements joinedError or return the err in a single-element list otherwise. -// -//nolint:errorlint // error type checks will fail on wrapped errors. Disabled since we are not doing checks on error types. func UnwrapError(err error) []error { joined, ok := err.(interface{ Unwrap() []error }) if !ok {