Skip to content

Commit 7b189d6

Browse files
authored
core: fix staticcheck warnings (#20384)
* core: fix staticcheck warnings * fix goimports
1 parent c4844e9 commit 7b189d6

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

core/rawdb/database.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,10 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace st
150150
}
151151
// Database contains only older data than the freezer, this happens if the
152152
// state was wiped and reinited from an existing freezer.
153-
} else {
154-
// Key-value store continues where the freezer left off, all is fine. We might
155-
// have duplicate blocks (crash after freezer write but before kay-value store
156-
// deletion, but that's fine).
157153
}
154+
// Otherwise, key-value store continues where the freezer left off, all is fine.
155+
// We might have duplicate blocks (crash after freezer write but before key-value
156+
// store deletion, but that's fine).
158157
} else {
159158
// If the freezer is empty, ensure nothing was moved yet from the key-value
160159
// store, otherwise we'll end up missing data. We check block #1 to decide
@@ -167,9 +166,9 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, freezer string, namespace st
167166
return nil, errors.New("ancient chain segments already extracted, please set --datadir.ancient to the correct path")
168167
}
169168
// Block #1 is still in the database, we're allowed to init a new feezer
170-
} else {
171-
// The head header is still the genesis, we're allowed to init a new feezer
172169
}
170+
// Otherwise, the head header is still the genesis, we're allowed to init a new
171+
// feezer.
173172
}
174173
}
175174
// Freezer is consistent with the key-value database, permit combining the two

core/vm/contracts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"github.com/ethereum/go-ethereum/crypto/blake2b"
2929
"github.com/ethereum/go-ethereum/crypto/bn256"
3030
"github.com/ethereum/go-ethereum/params"
31+
32+
//lint:ignore SA1019 Needed for precompile
3133
"golang.org/x/crypto/ripemd160"
3234
)
3335

core/vm/contracts_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
// precompiledTest defines the input/output pairs for precompiled contract tests.
3030
type precompiledTest struct {
3131
input, expected string
32-
gas uint64
3332
name string
3433
noBenchmark bool // Benchmark primarily the worst-cases
3534
}
@@ -418,6 +417,24 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
418417
})
419418
}
420419

420+
func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) {
421+
p := PrecompiledContractsIstanbul[common.HexToAddress(addr)]
422+
in := common.Hex2Bytes(test.input)
423+
contract := NewContract(AccountRef(common.HexToAddress("1337")),
424+
nil, new(big.Int), p.RequiredGas(in)-1)
425+
t.Run(fmt.Sprintf("%s-Gas=%d", test.name, contract.Gas), func(t *testing.T) {
426+
_, err := RunPrecompiledContract(p, in, contract)
427+
if err.Error() != "out of gas" {
428+
t.Errorf("Expected error [out of gas], got [%v]", err)
429+
}
430+
// Verify that the precompile did not touch the input buffer
431+
exp := common.Hex2Bytes(test.input)
432+
if !bytes.Equal(in, exp) {
433+
t.Errorf("Precompiled %v modified input data", addr)
434+
}
435+
})
436+
}
437+
421438
func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing.T) {
422439
p := PrecompiledContractsIstanbul[common.HexToAddress(addr)]
423440
in := common.Hex2Bytes(test.input)
@@ -541,6 +558,13 @@ func BenchmarkPrecompiledBn256Add(bench *testing.B) {
541558
}
542559
}
543560

561+
// Tests OOG
562+
func TestPrecompiledModExpOOG(t *testing.T) {
563+
for _, test := range modexpTests {
564+
testPrecompiledOOG("05", test, t)
565+
}
566+
}
567+
544568
// Tests the sample inputs from the elliptic curve scalar multiplication EIP 213.
545569
func TestPrecompiledBn256ScalarMul(t *testing.T) {
546570
for _, test := range bn256ScalarMulTests {

core/vm/stack.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ func (st *Stack) Back(n int) *big.Int {
7474
return st.data[st.len()-n-1]
7575
}
7676

77-
func (st *Stack) require(n int) error {
78-
if st.len() < n {
79-
return fmt.Errorf("stack underflow (%d <=> %d)", len(st.data), n)
80-
}
81-
return nil
82-
}
83-
8477
// Print dumps the content of the stack
8578
func (st *Stack) Print() {
8679
fmt.Println("### stack ###")

0 commit comments

Comments
 (0)