-
Notifications
You must be signed in to change notification settings - Fork 2
fix: Solve the code specification problem detected by golangci-lint. #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| linters: | ||
| # please, do not use `enable-all`: it's deprecated and will be removed soon. | ||
| # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint | ||
| disable-all: true | ||
| enable: | ||
| - bodyclose | ||
| - dogsled | ||
| - dupl | ||
| - errcheck | ||
| - goconst | ||
| - gocyclo | ||
| - gofmt | ||
| - goimports | ||
| - gosimple | ||
| - govet | ||
| - ineffassign | ||
| - misspell | ||
| - nakedret | ||
| - rowserrcheck | ||
| - typecheck | ||
| - unconvert | ||
| - unparam | ||
| - unused | ||
|
|
||
| run: | ||
| # ignore test file | ||
| tests: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,6 @@ import ( | |
| "github.com/meshplus/bitxhub-model/constant" | ||
| "github.com/meshplus/bitxhub-model/pb" | ||
| //lint:ignore SA1019 Needed for precompile | ||
| "golang.org/x/crypto/ripemd160" | ||
| ) | ||
|
|
||
| // PrecompiledContract is the basic interface for native Go contracts. The implementation | ||
|
|
@@ -89,19 +88,19 @@ func (ic *interchain) Run(input []byte, caller common.Address, evm *EVM) ([]byte | |
| // PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum | ||
| // contracts used in the Frontier and Homestead releases. | ||
| var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{ | ||
| common.BytesToAddress([]byte{1}): &ecrecover{}, | ||
| common.BytesToAddress([]byte{2}): &sha256hash{}, | ||
| common.BytesToAddress([]byte{3}): &ripemd160hash{}, | ||
| common.BytesToAddress([]byte{1}): &ecrecover{}, | ||
| common.BytesToAddress([]byte{2}): &sha256hash{}, | ||
| //common.BytesToAddress([]byte{3}): &ripemd160hash{}, | ||
| common.BytesToAddress([]byte{4}): &dataCopy{}, | ||
| common.BytesToAddress([]byte{200}): &interchain{}, | ||
| } | ||
|
|
||
| // PrecompiledContractsByzantium contains the default set of pre-compiled Ethereum | ||
| // contracts used in the Byzantium release. | ||
| var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{ | ||
| common.BytesToAddress([]byte{1}): &ecrecover{}, | ||
| common.BytesToAddress([]byte{2}): &sha256hash{}, | ||
| common.BytesToAddress([]byte{3}): &ripemd160hash{}, | ||
| common.BytesToAddress([]byte{1}): &ecrecover{}, | ||
| common.BytesToAddress([]byte{2}): &sha256hash{}, | ||
| //common.BytesToAddress([]byte{3}): &ripemd160hash{}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. above all |
||
| common.BytesToAddress([]byte{4}): &dataCopy{}, | ||
| common.BytesToAddress([]byte{5}): &bigModExp{eip2565: false}, | ||
| common.BytesToAddress([]byte{6}): &bn256AddByzantium{}, | ||
|
|
@@ -113,9 +112,9 @@ var PrecompiledContractsByzantium = map[common.Address]PrecompiledContract{ | |
| // PrecompiledContractsIstanbul contains the default set of pre-compiled Ethereum | ||
| // contracts used in the Istanbul release. | ||
| var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ | ||
| common.BytesToAddress([]byte{1}): &ecrecover{}, | ||
| common.BytesToAddress([]byte{2}): &sha256hash{}, | ||
| common.BytesToAddress([]byte{3}): &ripemd160hash{}, | ||
| common.BytesToAddress([]byte{1}): &ecrecover{}, | ||
| common.BytesToAddress([]byte{2}): &sha256hash{}, | ||
| //common.BytesToAddress([]byte{3}): &ripemd160hash{}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. above all |
||
| common.BytesToAddress([]byte{4}): &dataCopy{}, | ||
| common.BytesToAddress([]byte{5}): &bigModExp{eip2565: false}, | ||
| common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, | ||
|
|
@@ -128,9 +127,9 @@ var PrecompiledContractsIstanbul = map[common.Address]PrecompiledContract{ | |
| // PrecompiledContractsBerlin contains the default set of pre-compiled Ethereum | ||
| // contracts used in the Berlin release. | ||
| var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{ | ||
| common.BytesToAddress([]byte{1}): &ecrecover{}, | ||
| common.BytesToAddress([]byte{2}): &sha256hash{}, | ||
| common.BytesToAddress([]byte{3}): &ripemd160hash{}, | ||
| common.BytesToAddress([]byte{1}): &ecrecover{}, | ||
| common.BytesToAddress([]byte{2}): &sha256hash{}, | ||
| //common.BytesToAddress([]byte{3}): &ripemd160hash{}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. above all |
||
| common.BytesToAddress([]byte{4}): &dataCopy{}, | ||
| common.BytesToAddress([]byte{5}): &bigModExp{eip2565: true}, | ||
| common.BytesToAddress([]byte{6}): &bn256AddIstanbul{}, | ||
|
|
@@ -260,20 +259,20 @@ func (c *sha256hash) Run(input []byte, caller common.Address, evm *EVM) ([]byte, | |
| } | ||
|
|
||
| // RIPEMD160 implemented as a native contract. | ||
| type ripemd160hash struct{} | ||
| //type ripemd160hash struct{} | ||
|
|
||
| // RequiredGas returns the gas required to execute the pre-compiled contract. | ||
| // | ||
| // This method does not require any overflow checking as the input size gas costs | ||
| // required for anything significant is so high it's impossible to pay for. | ||
| func (c *ripemd160hash) RequiredGas(input []byte) uint64 { | ||
| return uint64(len(input)+31)/32*params.Ripemd160PerWordGas + params.Ripemd160BaseGas | ||
| } | ||
| func (c *ripemd160hash) Run(input []byte, caller common.Address, evm *EVM) ([]byte, error) { | ||
| ripemd := ripemd160.New() | ||
| ripemd.Write(input) | ||
| return common.LeftPadBytes(ripemd.Sum(nil), 32), nil | ||
| } | ||
| //func (c *ripemd160hash) RequiredGas(input []byte) uint64 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. above all |
||
| // return uint64(len(input)+31)/32*params.Ripemd160PerWordGas + params.Ripemd160BaseGas | ||
| //} | ||
| //func (c *ripemd160hash) Run(input []byte, caller common.Address, evm *EVM) ([]byte, error) { | ||
| // ripemd := ripemd160.New() | ||
| // ripemd.Write(input) | ||
| // return common.LeftPadBytes(ripemd.Sum(nil), 32), nil | ||
| //} | ||
|
|
||
| // data copy implemented as a native contract. | ||
| type dataCopy struct{} | ||
|
|
@@ -771,6 +770,7 @@ func (c *bls12381G1MultiExp) RequiredGas(input []byte) uint64 { | |
| return (uint64(k) * params.Bls12381G1MulGas * discount) / 1000 | ||
| } | ||
|
|
||
| //nolint:dupl | ||
| func (c *bls12381G1MultiExp) Run(input []byte, caller common.Address, evm *EVM) ([]byte, error) { | ||
| // Implements EIP-2537 G1MultiExp precompile. | ||
| // G1 multiplication call expects `160*k` bytes as an input that is interpreted as byte concatenation of `k` slices each of them being a byte concatenation of encoding of G1 point (`128` bytes) and encoding of a scalar value (`32` bytes). | ||
|
|
@@ -800,7 +800,10 @@ func (c *bls12381G1MultiExp) Run(input []byte, caller common.Address, evm *EVM) | |
|
|
||
| // Compute r = e_0 * p_0 + e_1 * p_1 + ... + e_(k-1) * p_(k-1) | ||
| r := g.New() | ||
| g.MultiExp(r, points, scalars) | ||
| _, err = g.MultiExp(r, points, scalars) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Encode the G1 point to 128 bytes | ||
| return g.EncodePoint(r), nil | ||
|
|
@@ -902,6 +905,7 @@ func (c *bls12381G2MultiExp) RequiredGas(input []byte) uint64 { | |
| return (uint64(k) * params.Bls12381G2MulGas * discount) / 1000 | ||
| } | ||
|
|
||
| //nolint:dupl | ||
| func (c *bls12381G2MultiExp) Run(input []byte, caller common.Address, evm *EVM) ([]byte, error) { | ||
| // Implements EIP-2537 G2MultiExp precompile logic | ||
| // > G2 multiplication call expects `288*k` bytes as an input that is interpreted as byte concatenation of `k` slices each of them being a byte concatenation of encoding of G2 point (`256` bytes) and encoding of a scalar value (`32` bytes). | ||
|
|
@@ -931,7 +935,10 @@ func (c *bls12381G2MultiExp) Run(input []byte, caller common.Address, evm *EVM) | |
|
|
||
| // Compute r = e_0 * p_0 + e_1 * p_1 + ... + e_(k-1) * p_(k-1) | ||
| r := g.New() | ||
| g.MultiExp(r, points, scalars) | ||
| _, err = g.MultiExp(r, points, scalars) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Encode the G2 point to 256 bytes. | ||
| return g.EncodePoint(r), nil | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,10 @@ func (l *JSONLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint | |
| if !l.cfg.DisableReturnData { | ||
| log.ReturnData = rData | ||
| } | ||
| l.encoder.Encode(log) | ||
| err = l.encoder.Encode(log) | ||
| if err != nil { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| // CaptureEnd is triggered at end of execution. | ||
|
|
@@ -88,7 +91,13 @@ func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, | |
| Err string `json:"error,omitempty"` | ||
| } | ||
| if err != nil { | ||
| l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, err.Error()}) | ||
| err = l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, err.Error()}) | ||
| if err != nil { | ||
| return | ||
| } | ||
| } | ||
| err = l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, ""}) | ||
| if err != nil { | ||
| return | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. replace by : |
||
| } | ||
| l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, ""}) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why comment this code