From 631099322c6bda8ff947df2ef65a3f2416c8e399 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Wed, 6 Mar 2024 05:48:02 -0300 Subject: [PATCH] Fix TestProcessVerkle tests (#400) * move self-destruct witness logic Signed-off-by: Ignacio Hagopian * fix test Signed-off-by: Ignacio Hagopian --------- Signed-off-by: Ignacio Hagopian --- core/state_processor_test.go | 4 ++-- core/vm/instructions.go | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 6b05435cd9..fb0420d69a 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -485,8 +485,8 @@ func TestProcessVerkle(t *testing.T) { txCost1 := params.TxGas txCost2 := params.TxGas - contractCreationCost := intrinsicContractCreationGas + uint64(7700 /* creation */ +2939 /* execution costs */) - codeWithExtCodeCopyGas := intrinsicCodeWithExtCodeCopyGas + uint64(7000 /* creation */ +299744 /* execution costs */) + contractCreationCost := intrinsicContractCreationGas + uint64(5600+700+700+700 /* creation with value */ +2739 /* execution costs */) + codeWithExtCodeCopyGas := intrinsicCodeWithExtCodeCopyGas + uint64(5600+700 /* creation */ +302044 /* execution costs */) blockGasUsagesExpected := []uint64{ txCost1*2 + txCost2, txCost1*2 + txCost2 + contractCreationCost + codeWithExtCodeCopyGas, diff --git a/core/vm/instructions.go b/core/vm/instructions.go index cc3de642bd..eea71d66c5 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -945,22 +945,6 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance) tracer.CaptureExit([]byte{}, 0, nil) } - if interpreter.evm.chainRules.IsPrague { - contractAddr := scope.Contract.Address() - beneficiaryAddr := beneficiary.Bytes20() - // If the beneficiary isn't the contract, we need to touch the beneficiary's balance. - // If the beneficiary is the contract itself, there're two possibilities: - // 1. The contract was created in the same transaction: the balance is already touched (no need to touch again) - // 2. The contract wasn't created in the same transaction: there's no net change in balance, - // and SELFDESTRUCT will perform no action on the account header. (we touch since we did SubBalance+AddBalance above) - if contractAddr != beneficiaryAddr || interpreter.evm.StateDB.WasCreatedInCurrentTx(contractAddr) { - statelessGas := interpreter.evm.Accesses.TouchAddressOnReadAndComputeGas(beneficiaryAddr[:], uint256.Int{}, utils.BalanceLeafKey) - if !scope.Contract.UseGas(statelessGas) { - scope.Contract.Gas = 0 - return nil, ErrOutOfGas - } - } - } return nil, errStopToken } @@ -977,6 +961,22 @@ func opSelfdestruct6780(pc *uint64, interpreter *EVMInterpreter, scope *ScopeCon tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance) tracer.CaptureExit([]byte{}, 0, nil) } + if interpreter.evm.chainRules.IsPrague { + contractAddr := scope.Contract.Address() + beneficiaryAddr := beneficiary.Bytes20() + // If the beneficiary isn't the contract, we need to touch the beneficiary's balance. + // If the beneficiary is the contract itself, there're two possibilities: + // 1. The contract was created in the same transaction: the balance is already touched (no need to touch again) + // 2. The contract wasn't created in the same transaction: there's no net change in balance, + // and SELFDESTRUCT will perform no action on the account header. (we touch since we did SubBalance+AddBalance above) + if contractAddr != beneficiaryAddr || interpreter.evm.StateDB.WasCreatedInCurrentTx(contractAddr) { + statelessGas := interpreter.evm.Accesses.TouchAddressOnReadAndComputeGas(beneficiaryAddr[:], uint256.Int{}, utils.BalanceLeafKey) + if !scope.Contract.UseGas(statelessGas) { + scope.Contract.Gas = 0 + return nil, ErrOutOfGas + } + } + } return nil, errStopToken }