diff --git a/core/vm/interpreter_test.go b/core/vm/interpreter_test.go index 001b102c81..8ed512316b 100644 --- a/core/vm/interpreter_test.go +++ b/core/vm/interpreter_test.go @@ -18,6 +18,7 @@ package vm import ( "math" + "math/big" "testing" "time" @@ -77,29 +78,19 @@ func TestLoopInterrupt(t *testing.T) { func BenchmarkInterpreter(b *testing.B) { var ( - evm = NewEVM(BlockContext{}, nil, params.TestChainConfig, Config{}) - startGas uint64 = 30_000_000 - value = uint256.NewInt(0) - contract = NewContract(common.Address{}, common.Address{}, value, startGas, nil) + statedb, _ = state.New(types.EmptyRootHash, state.NewDatabaseForTesting()) + evm = NewEVM(BlockContext{BlockNumber: big.NewInt(1), Time: 1, Random: &common.Hash{}}, statedb, params.MergedTestChainConfig, Config{}) + startGas uint64 = 100_000_000 + value = uint256.NewInt(0) + stack = newstack() + mem = NewMemory() + contract = NewContract(common.Address{}, common.Address{}, value, startGas, nil) ) - contract.Code = common.Hex2Bytes(loopInterruptTests[0]) + stack.push(uint256.NewInt(123)) + stack.push(uint256.NewInt(123)) + gasSStoreEIP3529 = makeGasSStoreFunc(params.SstoreClearsScheduleRefundEIP3529) + b.ResetTimer() for i := 0; i < b.N; i++ { - evm.interpreter.Run(contract, []byte{}, false) + gasSStoreEIP3529(evm, contract, stack, mem, 1234) } } - -// BenchmarkInterpreter-14 14613990 79.01 ns/op 32 B/op 2 allocs/op - -func BenchmarkDup(b *testing.B) { - stack := newstack() - stack.push(uint256.NewInt(1234)) - stack.push(uint256.NewInt(4321)) - for range b.N { - for range 1_000_000 { - //stack.dup(1) - stack.dup1() - } - } -} - -// BenchmarkDup-14 38 31579698 ns/op 188685761 B/op 2 allocs/op diff --git a/core/vm/operations_acl.go b/core/vm/operations_acl.go index ff3875868f..085b018e4c 100644 --- a/core/vm/operations_acl.go +++ b/core/vm/operations_acl.go @@ -34,10 +34,10 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { } // Gas sentry honoured, do the actual gas calculation based on the stored value var ( - y, x = stack.Back(1), stack.peek() - slot = common.Hash(x.Bytes32()) - current = evm.StateDB.GetState(contract.Address(), slot) - cost = uint64(0) + y, x = stack.Back(1), stack.peek() + slot = common.Hash(x.Bytes32()) + current, original = evm.StateDB.GetStateAndCommittedState(contract.Address(), slot) + cost = uint64(0) ) // Check slot presence in the access list if _, slotPresent := evm.StateDB.SlotInAccessList(contract.Address(), slot); !slotPresent { @@ -52,7 +52,6 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { // return params.SloadGasEIP2200, nil return cost + params.WarmStorageReadCostEIP2929, nil // SLOAD_GAS } - original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32()) if original == current { if original == (common.Hash{}) { // create slot (2.1.1) return cost + params.SstoreSetGasEIP2200, nil diff --git a/core/vm/stack.go b/core/vm/stack.go index 685dd25dc7..879dc9aa6d 100644 --- a/core/vm/stack.go +++ b/core/vm/stack.go @@ -117,10 +117,6 @@ func (st *Stack) dup(n int) { st.push(&st.data[st.len()-n]) } -func (st *Stack) dup1() { - st.push(&st.data[st.len()-1]) -} - func (st *Stack) peek() *uint256.Int { return &st.data[st.len()-1] }