diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f35cd5aa..3b03aa2e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,7 +32,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - name: Install Golang - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: '1.21.x' - name: Build FFI @@ -55,16 +55,16 @@ jobs: run: make lint-check working-directory: rvsol - # go-lint: - # runs-on: ubuntu-latest - # timeout-minutes: 20 - # steps: - # - uses: actions/checkout@v3 - # - uses: actions/setup-go@v4 - # with: - # go-version: '1.21.x' - # cache: false - # - name: golangci-lint - # uses: golangci/golangci-lint-action@v3 - # with: - # version: latest + rvgo-lint: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '1.21.x' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v4 + with: + version: latest diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 00000000..da6389d4 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,10 @@ +run: + timeout: 5m +linters: + enable: + - goimports + - sqlclosecheck + - bodyclose + - asciicheck + - misspell + - errorlint diff --git a/rvgo/Makefile b/rvgo/Makefile index b6437f72..6137f225 100644 --- a/rvgo/Makefile +++ b/rvgo/Makefile @@ -24,3 +24,11 @@ clean: test: go test ./... .PHONY: test + +lint-check: + golangci-lint run +.PHONY: lint-check + +lint-fix: + golangci-lint run --fix +.PHONY: lint-fix diff --git a/rvgo/cmd/load_elf.go b/rvgo/cmd/load_elf.go index 7b217cb0..df72bfde 100644 --- a/rvgo/cmd/load_elf.go +++ b/rvgo/cmd/load_elf.go @@ -3,6 +3,7 @@ package cmd import ( "debug/elf" "fmt" + cannon "github.com/ethereum-optimism/optimism/cannon/cmd" "github.com/ethereum-optimism/optimism/op-service/jsonutil" "github.com/urfave/cli/v2" diff --git a/rvgo/cmd/process_preimage_oracle.go b/rvgo/cmd/process_preimage_oracle.go index 440e7e15..b8ea6c2f 100644 --- a/rvgo/cmd/process_preimage_oracle.go +++ b/rvgo/cmd/process_preimage_oracle.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "errors" "fmt" "os" "os/exec" @@ -107,7 +108,8 @@ func (p *ProcessPreimageOracle) Close() error { func (p *ProcessPreimageOracle) wait() { err := p.cmd.Wait() var waitErr error - if err, ok := err.(*exec.ExitError); !ok || !err.Success() { + var exitErr *exec.ExitError + if !errors.As(err, &exitErr) || !exitErr.Success() { waitErr = err } p.cancelIO(fmt.Errorf("%w: pre-image server has exited", waitErr)) diff --git a/rvgo/fast/memory.go b/rvgo/fast/memory.go index 9215be1d..766d37b2 100644 --- a/rvgo/fast/memory.go +++ b/rvgo/fast/memory.go @@ -253,7 +253,7 @@ func (m *Memory) GetUnaligned(addr uint64, dest []byte) { l = 32 } var zeroes [32]byte - d = copy(dest[d:], zeroes[:l]) + copy(dest[d:], zeroes[:l]) } else { copy(dest[d:], p.Data[pageAddr:]) } diff --git a/rvgo/fast/state.go b/rvgo/fast/state.go index 64e36483..77c36f58 100644 --- a/rvgo/fast/state.go +++ b/rvgo/fast/state.go @@ -3,6 +3,7 @@ package fast import ( "encoding/binary" "fmt" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" diff --git a/rvgo/fast/vm.go b/rvgo/fast/vm.go index d9d77100..889a1461 100644 --- a/rvgo/fast/vm.go +++ b/rvgo/fast/vm.go @@ -25,7 +25,7 @@ func (inst *InstrumentedState) riscvStep() (outErr error) { if err, ok := errInterface.(error); ok { outErr = fmt.Errorf("revert: %w", err) } else { - outErr = fmt.Errorf("revert: %v", err) + outErr = fmt.Errorf("revert: %v", err) // nolint:errorlint } } diff --git a/rvgo/fast/witness.go b/rvgo/fast/witness.go index 295af378..63e030da 100644 --- a/rvgo/fast/witness.go +++ b/rvgo/fast/witness.go @@ -40,7 +40,7 @@ func (wit *StepWitness) EncodeStepInput(localContext LocalContext) []byte { input = append(input, uint64ToBytes32(32*3+32+uint64(len(wit.State))+abiStatePadding)...) // local context in bytes input = append(input, common.Hash(localContext).Bytes()...) - + // state data length in bytes input = append(input, uint64ToBytes32(uint64(len(wit.State)))...) input = append(input, wit.State[:]...) diff --git a/rvgo/fast/yul256.go b/rvgo/fast/yul256.go index 02cfcf22..19fcd9aa 100644 --- a/rvgo/fast/yul256.go +++ b/rvgo/fast/yul256.go @@ -17,6 +17,7 @@ func beWordAsB32(v U256) [32]byte { return v.Bytes32() } +// nolint:unused func add(x, y U256) (out U256) { out.Add(&x, &y) return @@ -32,21 +33,25 @@ func mul(x, y U256) (out U256) { return } +// nolint:unused func div(x, y U256) (out U256) { out.Div(&x, &y) return } +// nolint:unused func sdiv(x, y U256) (out U256) { // note: signed overflow semantics are the same between Go and EVM assembly out.SDiv(&x, &y) return } +// nolint:unused func mod(x, y U256) (out U256) { out.Mod(&x, &y) return } +// nolint:unused func smod(x, y U256) (out U256) { out.SMod(&x, &y) return @@ -57,6 +62,7 @@ func not(x U256) (out U256) { return } +// nolint:unused func lt(x, y U256) (out U256) { if x.Lt(&y) { out.SetUint64(1) @@ -64,6 +70,7 @@ func lt(x, y U256) (out U256) { return } +// nolint:unused func gt(x, y U256) (out U256) { if x.Gt(&y) { out.SetUint64(1) @@ -71,6 +78,7 @@ func gt(x, y U256) (out U256) { return } +// nolint:unused func slt(x, y U256) (out U256) { if x.Slt(&y) { out.SetUint64(1) @@ -78,6 +86,7 @@ func slt(x, y U256) (out U256) { return } +// nolint:unused func sgt(x, y U256) (out U256) { if x.Sgt(&y) { out.SetUint64(1) @@ -85,6 +94,7 @@ func sgt(x, y U256) (out U256) { return } +// nolint:unused func eq(x, y U256) (out U256) { if x.Eq(&y) { out.SetUint64(1) @@ -92,6 +102,7 @@ func eq(x, y U256) (out U256) { return } +// nolint:unused func iszero(x U256) bool { return x.IsZero() } @@ -106,6 +117,7 @@ func or(x, y U256) (out U256) { return } +// nolint:unused func xor(x, y U256) (out U256) { out.Xor(&x, &y) return @@ -130,6 +142,7 @@ func shr(x, y U256) (out U256) { } // returns y >> x (signed) +// nolint:unused func sar(x, y U256) (out U256) { if !x.IsUint64() && x.Uint64() >= 256 { return diff --git a/rvgo/fast/yul64.go b/rvgo/fast/yul64.go index ffdcbc25..c9b0099f 100644 --- a/rvgo/fast/yul64.go +++ b/rvgo/fast/yul64.go @@ -20,6 +20,7 @@ func shortToU256(v uint16) U256 { return *uint256.NewInt(uint64(v)) } +// nolint:unused func longToU256(v uint64) U256 { return *uint256.NewInt(v) } diff --git a/rvgo/slow/yul64.go b/rvgo/slow/yul64.go index 5bcd11a8..08dc87af 100644 --- a/rvgo/slow/yul64.go +++ b/rvgo/slow/yul64.go @@ -27,6 +27,7 @@ func shortToU256(v uint16) U256 { return *uint256.NewInt(uint64(v)) } +// nolint:unused func longToU256(v uint64) U256 { return *uint256.NewInt(v) } diff --git a/rvgo/test/evm_test.go b/rvgo/test/evm_test.go index af9af170..2a318e29 100644 --- a/rvgo/test/evm_test.go +++ b/rvgo/test/evm_test.go @@ -130,6 +130,7 @@ func testContracts(t require.TestingT) *Contracts { } } +// nolint:unused func addTracer(t *testing.T, env *vm.EVM, addrs *Addresses, contracts *Contracts) { //env.Config.Tracer = logger.NewMarkdownLogger(&logger.Config{}, os.Stdout)