diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000..895d156d --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,44 @@ +name: golangci-lint +on: + pull_request: + push: + branches: [master, dev] +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + check-latest: true + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + args: --timeout=15m -v + + # Optional: show only new issues if it's a pull request. The default value is `false`. + only-new-issues: false + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index e4500fd6..a2653c22 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -8,14 +8,11 @@ jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/setup-python@v4 - - uses: actions/checkout@master + - uses: actions/checkout@v3 with: fetch-depth: 2 - uses: actions/setup-go@v5 with: go-version-file: "go.mod" check-latest: true - - run: go install golang.org/x/tools/cmd/goimports@latest - - run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.59.0 - uses: pre-commit/action@v2.0.2 diff --git a/.golangci.yml b/.golangci.yml index cd3bcde3..d983b9de 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,54 +1,48 @@ -{ - "run": { - "tests": false, - }, - "linters": { - "fast": false, - "enable": [ - "errcheck", - "errorlint", - "gas", - "gocritic", - "gosimple", - "govet", - "ineffassign", - "megacheck", - "misspell", - "nakedret", - "prealloc", - "revive", - "staticcheck", - "unconvert", - "unparam", - ], - "disable": [ - "unused", - ] - }, - "linters-settings": { - "revive": { - "enableAllRules": true, - "rules": [ - { - "name": "var-naming", - "arguments": [ - ["ID"] - ] - } - ] - }, - "gocritic": { - "enabled-tags": [ - "diagnostic", - "experimental", - "opinionated", - "performance", - "style", - ], - "disabled-checks": [ - "hugeParam", - "unnamedResult", - ] - } - }, -} +run: + tests: false + skip-dirs: + - chain + - exchange + - injective_data + - proto + +linters: + fast: false + enable: + - errcheck + - errorlint + - gas + - gocritic + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - megacheck + - misspell + - nakedret + - prealloc + - revive + - staticcheck + - unconvert + - unparam + disable: + - unused + +linters-settings: + revive: + enableAllRules: true + rules: + - name: var-naming + arguments: + - ["ID"] + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - hugeParam + - unnamedResult diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ac692ca7..aea4d0e1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,10 +13,3 @@ repos: - id: end-of-file-fixer - id: end-of-file-fixer - id: check-yaml - - repo: https://github.com/dnephin/pre-commit-golang - rev: master - hooks: - - id: go-fmt - - id: go-imports - - id: golangci-lint - args: [--timeout=15m] diff --git a/eip712_cosmos.go b/eip712_cosmos.go index 85aca9e2..b70681af 100644 --- a/eip712_cosmos.go +++ b/eip712_cosmos.go @@ -4,13 +4,14 @@ import ( "bytes" "encoding/json" "fmt" + "math" "math/big" "reflect" "runtime/debug" "strings" "time" - "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cosmtypes "github.com/cosmos/cosmos-sdk/types" @@ -64,6 +65,12 @@ func WrapTxToEIP712( []cosmtypes.Msg{}, memo, ) + if chainID > uint64(math.MaxInt64) { + err := fmt.Errorf("chainID is too large: %v (max supported value is %v)", chainID, math.MaxInt64) + return typeddata.TypedData{}, err + } + intChainId := int64(chainID) + txData := make(map[string]interface{}) if err := json.Unmarshal(data, &txData); err != nil { err = errors.Wrap(err, "failed to unmarshal data provided into WrapTxToEIP712") @@ -98,7 +105,7 @@ func WrapTxToEIP712( domain := typeddata.TypedDataDomain{ Name: "Injective Web3", Version: "1.0.0", - ChainId: ethmath.NewHexOrDecimal256(int64(chainID)), + ChainId: ethmath.NewHexOrDecimal256(intChainId), VerifyingContract: "cosmos", Salt: "0", } @@ -413,7 +420,7 @@ var ( hashType = reflect.TypeOf(common.Hash{}) addressType = reflect.TypeOf(common.Address{}) bigIntType = reflect.TypeOf(big.Int{}) - cosmIntType = reflect.TypeOf(math.Int{}) + cosmIntType = reflect.TypeOf(sdkmath.Int{}) cosmosAnyType = reflect.TypeOf(&codectypes.Any{}) timeType = reflect.TypeOf(time.Time{}) ) @@ -531,10 +538,17 @@ func WrapTxToEIP712V2( msgs []cosmtypes.Msg, feeDelegation *FeeDelegationOptions, ) (typeddata.TypedData, error) { + + if chainID > uint64(math.MaxInt64) { + err := fmt.Errorf("chainID is too large: %v (max supported value is %v)", chainID, math.MaxInt64) + return typeddata.TypedData{}, err + } + intChainId := int64(chainID) + domain := typeddata.TypedDataDomain{ Name: "Injective Web3", Version: "1.0.0", - ChainId: ethmath.NewHexOrDecimal256(int64(chainID)), + ChainId: ethmath.NewHexOrDecimal256(intChainId), VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC", Salt: "0", } diff --git a/ethereum/util/noncecache.go b/ethereum/util/noncecache.go index 1b904566..14bbd005 100644 --- a/ethereum/util/noncecache.go +++ b/ethereum/util/noncecache.go @@ -1,6 +1,7 @@ package util import ( + "math" "sync" "github.com/ethereum/go-ethereum/common" @@ -127,7 +128,12 @@ func (n nonceCache) Sync(account common.Address, syncFn func() (uint64, error)) } if nonce, err := syncFn(); err == nil { n.mux.Lock() - n.nonces[account] = int64(nonce) + if nonce > uint64(math.MaxInt64) { + // Handle overflow case - could log error or take other action + n.nonces[account] = math.MaxInt64 + } else { + n.nonces[account] = int64(nonce) + } n.mux.Unlock() } }