Skip to content

Commit

Permalink
Merge pull request #28 from ethereum-optimism/rvgo-lint
Browse files Browse the repository at this point in the history
rvgo: Lint CI job
  • Loading branch information
ImTei authored Mar 26, 2024
2 parents 122e520 + aea9010 commit 6e04b32
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 18 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
run:
timeout: 5m
linters:
enable:
- goimports
- sqlclosecheck
- bodyclose
- asciicheck
- misspell
- errorlint
8 changes: 8 additions & 0 deletions rvgo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions rvgo/cmd/load_elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion rvgo/cmd/process_preimage_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"errors"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion rvgo/fast/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:])
}
Expand Down
1 change: 1 addition & 0 deletions rvgo/fast/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion rvgo/fast/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Expand Down
2 changes: 1 addition & 1 deletion rvgo/fast/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:]...)
Expand Down
13 changes: 13 additions & 0 deletions rvgo/fast/yul256.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -57,41 +62,47 @@ func not(x U256) (out U256) {
return
}

// nolint:unused
func lt(x, y U256) (out U256) {
if x.Lt(&y) {
out.SetUint64(1)
}
return
}

// nolint:unused
func gt(x, y U256) (out U256) {
if x.Gt(&y) {
out.SetUint64(1)
}
return
}

// nolint:unused
func slt(x, y U256) (out U256) {
if x.Slt(&y) {
out.SetUint64(1)
}
return
}

// nolint:unused
func sgt(x, y U256) (out U256) {
if x.Sgt(&y) {
out.SetUint64(1)
}
return
}

// nolint:unused
func eq(x, y U256) (out U256) {
if x.Eq(&y) {
out.SetUint64(1)
}
return
}

// nolint:unused
func iszero(x U256) bool {
return x.IsZero()
}
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions rvgo/fast/yul64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions rvgo/slow/yul64.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions rvgo/test/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 6e04b32

Please sign in to comment.