diff --git a/core/vm/contracts.go b/core/vm/contracts.go index e92f08fe0..665b3f7b7 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -28,6 +28,8 @@ import ( "github.com/ledgerwatch/turbo-geth/crypto/blake2b" "github.com/ledgerwatch/turbo-geth/crypto/bn256" "github.com/ledgerwatch/turbo-geth/params" + + //lint:ignore SA1019 Needed for precompile "golang.org/x/crypto/ripemd160" ) diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index c30362c82..fc459b4d2 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -29,7 +29,6 @@ import ( // precompiledTest defines the input/output pairs for precompiled contract tests. type precompiledTest struct { input, expected string - gas uint64 name string noBenchmark bool // Benchmark primarily the worst-cases } @@ -418,6 +417,24 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) { }) } +func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) { + p := PrecompiledContractsIstanbul[common.HexToAddress(addr)] + in := common.Hex2Bytes(test.input) + contract := NewContract(AccountRef(common.HexToAddress("1337")), + nil, new(big.Int), p.RequiredGas(in)-1) + t.Run(fmt.Sprintf("%s-Gas=%d", test.name, contract.Gas), func(t *testing.T) { + _, err := RunPrecompiledContract(p, in, contract) + if err.Error() != "out of gas" { + t.Errorf("Expected error [out of gas], got [%v]", err) + } + // Verify that the precompile did not touch the input buffer + exp := common.Hex2Bytes(test.input) + if !bytes.Equal(in, exp) { + t.Errorf("Precompiled %v modified input data", addr) + } + }) +} + func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing.T) { p := PrecompiledContractsIstanbul[common.HexToAddress(addr)] in := common.Hex2Bytes(test.input) @@ -541,6 +558,13 @@ func BenchmarkPrecompiledBn256Add(bench *testing.B) { } } +// Tests OOG +func TestPrecompiledModExpOOG(t *testing.T) { + for _, test := range modexpTests { + testPrecompiledOOG("05", test, t) + } +} + // Tests the sample inputs from the elliptic curve scalar multiplication EIP 213. func TestPrecompiledBn256ScalarMul(t *testing.T) { for _, test := range bn256ScalarMulTests { diff --git a/core/vm/stack.go b/core/vm/stack.go index 84faf9b31..a60b521f5 100644 --- a/core/vm/stack.go +++ b/core/vm/stack.go @@ -78,13 +78,6 @@ func (st *Stack) Back(n int) *big.Int { return st.data[st.len()-n-1] } -func (st *Stack) require(n int) error { - if st.len() < n { - return fmt.Errorf("stack underflow (%d <=> %d)", len(st.data), n) - } - return nil -} - // Print dumps the content of the stack func (st *Stack) Print() { fmt.Println("### stack ###")