Skip to content

Commit fcdcd3b

Browse files
authored
Fix TestProcessVerkle tests (ethereum#400)
* move self-destruct witness logic Signed-off-by: Ignacio Hagopian <[email protected]> * fix test Signed-off-by: Ignacio Hagopian <[email protected]> --------- Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent 25a358f commit fcdcd3b

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

core/state_processor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ func TestProcessVerkle(t *testing.T) {
485485

486486
txCost1 := params.TxGas
487487
txCost2 := params.TxGas
488-
contractCreationCost := intrinsicContractCreationGas + uint64(7700 /* creation */ +2939 /* execution costs */)
489-
codeWithExtCodeCopyGas := intrinsicCodeWithExtCodeCopyGas + uint64(7000 /* creation */ +299744 /* execution costs */)
488+
contractCreationCost := intrinsicContractCreationGas + uint64(5600+700+700+700 /* creation with value */ +2739 /* execution costs */)
489+
codeWithExtCodeCopyGas := intrinsicCodeWithExtCodeCopyGas + uint64(5600+700 /* creation */ +302044 /* execution costs */)
490490
blockGasUsagesExpected := []uint64{
491491
txCost1*2 + txCost2,
492492
txCost1*2 + txCost2 + contractCreationCost + codeWithExtCodeCopyGas,

core/vm/instructions.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -945,22 +945,6 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
945945
tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
946946
tracer.CaptureExit([]byte{}, 0, nil)
947947
}
948-
if interpreter.evm.chainRules.IsPrague {
949-
contractAddr := scope.Contract.Address()
950-
beneficiaryAddr := beneficiary.Bytes20()
951-
// If the beneficiary isn't the contract, we need to touch the beneficiary's balance.
952-
// If the beneficiary is the contract itself, there're two possibilities:
953-
// 1. The contract was created in the same transaction: the balance is already touched (no need to touch again)
954-
// 2. The contract wasn't created in the same transaction: there's no net change in balance,
955-
// and SELFDESTRUCT will perform no action on the account header. (we touch since we did SubBalance+AddBalance above)
956-
if contractAddr != beneficiaryAddr || interpreter.evm.StateDB.WasCreatedInCurrentTx(contractAddr) {
957-
statelessGas := interpreter.evm.Accesses.TouchAddressOnReadAndComputeGas(beneficiaryAddr[:], uint256.Int{}, utils.BalanceLeafKey)
958-
if !scope.Contract.UseGas(statelessGas) {
959-
scope.Contract.Gas = 0
960-
return nil, ErrOutOfGas
961-
}
962-
}
963-
}
964948
return nil, errStopToken
965949
}
966950

@@ -977,6 +961,22 @@ func opSelfdestruct6780(pc *uint64, interpreter *EVMInterpreter, scope *ScopeCon
977961
tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
978962
tracer.CaptureExit([]byte{}, 0, nil)
979963
}
964+
if interpreter.evm.chainRules.IsPrague {
965+
contractAddr := scope.Contract.Address()
966+
beneficiaryAddr := beneficiary.Bytes20()
967+
// If the beneficiary isn't the contract, we need to touch the beneficiary's balance.
968+
// If the beneficiary is the contract itself, there're two possibilities:
969+
// 1. The contract was created in the same transaction: the balance is already touched (no need to touch again)
970+
// 2. The contract wasn't created in the same transaction: there's no net change in balance,
971+
// and SELFDESTRUCT will perform no action on the account header. (we touch since we did SubBalance+AddBalance above)
972+
if contractAddr != beneficiaryAddr || interpreter.evm.StateDB.WasCreatedInCurrentTx(contractAddr) {
973+
statelessGas := interpreter.evm.Accesses.TouchAddressOnReadAndComputeGas(beneficiaryAddr[:], uint256.Int{}, utils.BalanceLeafKey)
974+
if !scope.Contract.UseGas(statelessGas) {
975+
scope.Contract.Gas = 0
976+
return nil, ErrOutOfGas
977+
}
978+
}
979+
}
980980
return nil, errStopToken
981981
}
982982

0 commit comments

Comments
 (0)