Skip to content

Commit

Permalink
enable more linters (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Mar 25, 2023
1 parent 5160bef commit a4034d5
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 260 deletions.
32 changes: 16 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ run:
deadline: 10m

linters:
disable-all: true
presets:
- bugs
- error
- unused
- performance
disable:
- exhaustive
- musttag
- contextcheck
- wrapcheck
- goerr113
- unparam
- makezero
enable:
- errorlint
- unconvert
- predeclared
# - wastedassign # go1.18
- wastedassign
- thelper
- gofmt
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
# - gocritic
- bodyclose # go1.18
- gosec
# - forcetypeassert
- prealloc
# - contextcheck
# - goerr113
- gocritic
# - revive
# - forcetypeassert
# - stylecheck

linters-settings:
Expand Down
12 changes: 6 additions & 6 deletions commitment/bin_patricia_hashed.go
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ func (bph *BinPatriciaHashed) ProcessUpdates(plainKeys, hashedKeys [][]byte, upd

update := updates[i]
// Update the cell
if update.Flags == DELETE_UPDATE {
if update.Flags == DeleteUpdate {
bph.deleteBinaryCell(hashedKey)
if bph.trace {
fmt.Printf("key %x deleted\n", plainKey)
Expand All @@ -1552,19 +1552,19 @@ func (bph *BinPatriciaHashed) ProcessUpdates(plainKeys, hashedKeys [][]byte, upd
if bph.trace {
fmt.Printf("accountFn updated key %x =>", plainKey)
}
if update.Flags&BALANCE_UPDATE != 0 {
if update.Flags&BalanceUpdate != 0 {
if bph.trace {
fmt.Printf(" balance=%d", update.Balance.Uint64())
}
cell.Balance.Set(&update.Balance)
}
if update.Flags&NONCE_UPDATE != 0 {
if update.Flags&NonceUpdate != 0 {
if bph.trace {
fmt.Printf(" nonce=%d", update.Nonce)
}
cell.Nonce = update.Nonce
}
if update.Flags&CODE_UPDATE != 0 {
if update.Flags&CodeUpdate != 0 {
if bph.trace {
fmt.Printf(" codeHash=%x", update.CodeHashOrStorage)
}
Expand All @@ -1573,7 +1573,7 @@ func (bph *BinPatriciaHashed) ProcessUpdates(plainKeys, hashedKeys [][]byte, upd
if bph.trace {
fmt.Printf("\n")
}
if update.Flags&STORAGE_UPDATE != 0 {
if update.Flags&StorageUpdate != 0 {
cell.setStorage(update.CodeHashOrStorage[:update.ValLength])
if bph.trace {
fmt.Printf("\rstorageFn filled key %x => %x\n", plainKey, update.CodeHashOrStorage[:update.ValLength])
Expand Down Expand Up @@ -1715,7 +1715,7 @@ func (s *binState) Encode(buf []byte) ([]byte, error) {
if err := binary.Write(ee, binary.BigEndian, uint16(len(s.Root))); err != nil {
return nil, fmt.Errorf("encode root len: %w", err)
}
if n, err := ee.Write(s.Root[:]); err != nil || n != len(s.Root) {
if n, err := ee.Write(s.Root); err != nil || n != len(s.Root) {
return nil, fmt.Errorf("encode root: %w", err)
}
d := make([]byte, len(s.Depths))
Expand Down
54 changes: 27 additions & 27 deletions commitment/hex_patricia_hashed.go
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ func (hph *HexPatriciaHashed) ProcessUpdates(plainKeys, hashedKeys [][]byte, upd

update := updates[i]
// Update the cell
if update.Flags == DELETE_UPDATE {
if update.Flags == DeleteUpdate {
hph.deleteCell(hashedKey)
if hph.trace {
fmt.Printf("key %x deleted\n", plainKey)
Expand All @@ -1753,19 +1753,19 @@ func (hph *HexPatriciaHashed) ProcessUpdates(plainKeys, hashedKeys [][]byte, upd
if hph.trace {
fmt.Printf("accountFn updated key %x =>", plainKey)
}
if update.Flags&BALANCE_UPDATE != 0 {
if update.Flags&BalanceUpdate != 0 {
if hph.trace {
fmt.Printf(" balance=%d", update.Balance.Uint64())
}
cell.Balance.Set(&update.Balance)
}
if update.Flags&NONCE_UPDATE != 0 {
if update.Flags&NonceUpdate != 0 {
if hph.trace {
fmt.Printf(" nonce=%d", update.Nonce)
}
cell.Nonce = update.Nonce
}
if update.Flags&CODE_UPDATE != 0 {
if update.Flags&CodeUpdate != 0 {
if hph.trace {
fmt.Printf(" codeHash=%x", update.CodeHashOrStorage)
}
Expand All @@ -1774,7 +1774,7 @@ func (hph *HexPatriciaHashed) ProcessUpdates(plainKeys, hashedKeys [][]byte, upd
if hph.trace {
fmt.Printf("\n")
}
if update.Flags&STORAGE_UPDATE != 0 {
if update.Flags&StorageUpdate != 0 {
cell.setStorage(update.CodeHashOrStorage[:update.ValLength])
if hph.trace {
fmt.Printf("\rstorageFn filled key %x => %x\n", plainKey, update.CodeHashOrStorage[:update.ValLength])
Expand Down Expand Up @@ -1825,28 +1825,28 @@ func (hph *HexPatriciaHashed) hashAndNibblizeKey(key []byte) []byte {
type UpdateFlags uint8

const (
CODE_UPDATE UpdateFlags = 1
DELETE_UPDATE UpdateFlags = 2
BALANCE_UPDATE UpdateFlags = 4
NONCE_UPDATE UpdateFlags = 8
STORAGE_UPDATE UpdateFlags = 16
CodeUpdate UpdateFlags = 1
DeleteUpdate UpdateFlags = 2
BalanceUpdate UpdateFlags = 4
NonceUpdate UpdateFlags = 8
StorageUpdate UpdateFlags = 16
)

func (uf UpdateFlags) String() string {
var sb strings.Builder
if uf == DELETE_UPDATE {
if uf == DeleteUpdate {
sb.WriteString("Delete")
} else {
if uf&BALANCE_UPDATE != 0 {
if uf&BalanceUpdate != 0 {
sb.WriteString("+Balance")
}
if uf&NONCE_UPDATE != 0 {
if uf&NonceUpdate != 0 {
sb.WriteString("+Nonce")
}
if uf&CODE_UPDATE != 0 {
if uf&CodeUpdate != 0 {
sb.WriteString("+Code")
}
if uf&STORAGE_UPDATE != 0 {
if uf&StorageUpdate != 0 {
sb.WriteString("+Storage")
}
}
Expand Down Expand Up @@ -1888,18 +1888,18 @@ func (u *Update) DecodeForStorage(enc []byte) {

func (u *Update) Encode(buf []byte, numBuf []byte) []byte {
buf = append(buf, byte(u.Flags))
if u.Flags&BALANCE_UPDATE != 0 {
if u.Flags&BalanceUpdate != 0 {
buf = append(buf, byte(u.Balance.ByteLen()))
buf = append(buf, u.Balance.Bytes()...)
}
if u.Flags&NONCE_UPDATE != 0 {
if u.Flags&NonceUpdate != 0 {
n := binary.PutUvarint(numBuf, u.Nonce)
buf = append(buf, numBuf[:n]...)
}
if u.Flags&CODE_UPDATE != 0 {
if u.Flags&CodeUpdate != 0 {
buf = append(buf, u.CodeHashOrStorage[:]...)
}
if u.Flags&STORAGE_UPDATE != 0 {
if u.Flags&StorageUpdate != 0 {
n := binary.PutUvarint(numBuf, uint64(u.ValLength))
buf = append(buf, numBuf[:n]...)
if u.ValLength > 0 {
Expand All @@ -1915,7 +1915,7 @@ func (u *Update) Decode(buf []byte, pos int) (int, error) {
}
u.Flags = UpdateFlags(buf[pos])
pos++
if u.Flags&BALANCE_UPDATE != 0 {
if u.Flags&BalanceUpdate != 0 {
if len(buf) < pos+1 {
return 0, fmt.Errorf("decode Update: buffer too small for balance len")
}
Expand All @@ -1927,7 +1927,7 @@ func (u *Update) Decode(buf []byte, pos int) (int, error) {
u.Balance.SetBytes(buf[pos : pos+balanceLen])
pos += balanceLen
}
if u.Flags&NONCE_UPDATE != 0 {
if u.Flags&NonceUpdate != 0 {
var n int
u.Nonce, n = binary.Uvarint(buf[pos:])
if n == 0 {
Expand All @@ -1938,14 +1938,14 @@ func (u *Update) Decode(buf []byte, pos int) (int, error) {
}
pos += n
}
if u.Flags&CODE_UPDATE != 0 {
if u.Flags&CodeUpdate != 0 {
if len(buf) < pos+32 {
return 0, fmt.Errorf("decode Update: buffer too small for codeHash")
}
copy(u.CodeHashOrStorage[:], buf[pos:pos+32])
pos += 32
}
if u.Flags&STORAGE_UPDATE != 0 {
if u.Flags&StorageUpdate != 0 {
l, n := binary.Uvarint(buf[pos:])
if n == 0 {
return 0, fmt.Errorf("decode Update: buffer too small for storage len")
Expand All @@ -1967,16 +1967,16 @@ func (u *Update) Decode(buf []byte, pos int) (int, error) {
func (u *Update) String() string {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("Flags: [%s]", u.Flags))
if u.Flags&BALANCE_UPDATE != 0 {
if u.Flags&BalanceUpdate != 0 {
sb.WriteString(fmt.Sprintf(", Balance: [%d]", &u.Balance))
}
if u.Flags&NONCE_UPDATE != 0 {
if u.Flags&NonceUpdate != 0 {
sb.WriteString(fmt.Sprintf(", Nonce: [%d]", u.Nonce))
}
if u.Flags&CODE_UPDATE != 0 {
if u.Flags&CodeUpdate != 0 {
sb.WriteString(fmt.Sprintf(", CodeHash: [%x]", u.CodeHashOrStorage))
}
if u.Flags&STORAGE_UPDATE != 0 {
if u.Flags&StorageUpdate != 0 {
sb.WriteString(fmt.Sprintf(", Storage: [%x]", u.CodeHashOrStorage[:u.ValLength]))
}
return sb.String()
Expand Down
10 changes: 5 additions & 5 deletions commitment/hex_patricia_hashed_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ func Fuzz_ProcessUpdates_ArbitraryUpdateCount(f *testing.F) {

aux := make([]byte, 32)

flg := UpdateFlags(updateSeed.Intn(int(CODE_UPDATE | DELETE_UPDATE | STORAGE_UPDATE | NONCE_UPDATE | BALANCE_UPDATE)))
flg := UpdateFlags(updateSeed.Intn(int(CodeUpdate | DeleteUpdate | StorageUpdate | NonceUpdate | BalanceUpdate)))
switch {
case flg&BALANCE_UPDATE != 0:
case flg&BalanceUpdate != 0:
builder.Balance(pkey, updateSeed.Uint64()).Nonce(pkey, updateSeed.Uint64())
continue
case flg&CODE_UPDATE != 0:
case flg&CodeUpdate != 0:
keccak := sha3.NewLegacyKeccak256().(keccakState)
var s [8]byte
n, err := updateSeed.Read(s[:])
Expand All @@ -121,7 +121,7 @@ func Fuzz_ProcessUpdates_ArbitraryUpdateCount(f *testing.F) {

builder.CodeHash(pkey, hex.EncodeToString(aux))
continue
case flg&STORAGE_UPDATE != 0:
case flg&StorageUpdate != 0:
sz := updateSeed.Intn(length.Hash)
n, err = updateSeed.Read(aux[:sz])
require.NoError(t, err)
Expand All @@ -131,7 +131,7 @@ func Fuzz_ProcessUpdates_ArbitraryUpdateCount(f *testing.F) {
keysSeed.Read(loc)
builder.Storage(pkey, hex.EncodeToString(loc), hex.EncodeToString(aux[:sz]))
continue
case flg&DELETE_UPDATE != 0:
case flg&DeleteUpdate != 0:
continue
default:
continue
Expand Down
Loading

0 comments on commit a4034d5

Please sign in to comment.