core/vm: remove redundant conversions (#21903)

This commit is contained in:
Daniel Liu 2024-09-18 10:23:21 +08:00 committed by Daniel Liu
parent 67b5b2bf9a
commit a5531a2470
4 changed files with 19 additions and 19 deletions

View file

@ -543,7 +543,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
// instead of the usual sender-and-nonce-hash as the address where the contract is initialized at. // instead of the usual sender-and-nonce-hash as the address where the contract is initialized at.
func (evm *EVM) Create2(caller ContractRef, code []byte, gas uint64, endowment *big.Int, salt *uint256.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) { func (evm *EVM) Create2(caller ContractRef, code []byte, gas uint64, endowment *big.Int, salt *uint256.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) {
codeAndHash := &codeAndHash{code: code} codeAndHash := &codeAndHash{code: code}
contractAddr = crypto.CreateAddress2(caller.Address(), common.Hash(salt.Bytes32()), codeAndHash.Hash().Bytes()) contractAddr = crypto.CreateAddress2(caller.Address(), salt.Bytes32(), codeAndHash.Hash().Bytes())
return evm.create(caller, codeAndHash, gas, endowment, contractAddr, CREATE2) return evm.create(caller, codeAndHash, gas, endowment, contractAddr, CREATE2)
} }

View file

@ -97,7 +97,7 @@ var (
func gasSStore(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { func gasSStore(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
var ( var (
y, x = stack.Back(1), stack.Back(0) y, x = stack.Back(1), stack.Back(0)
current = evm.StateDB.GetState(contract.Address(), common.Hash(x.Bytes32())) current = evm.StateDB.GetState(contract.Address(), x.Bytes32())
) )
// The legacy gas metering only takes into consideration the current state // The legacy gas metering only takes into consideration the current state
// Legacy rules should be applied if we are in Petersburg (removal of EIP-1283) // Legacy rules should be applied if we are in Petersburg (removal of EIP-1283)
@ -136,7 +136,7 @@ func gasSStore(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySi
if current == value { // noop (1) if current == value { // noop (1)
return params.NetSstoreNoopGas, nil return params.NetSstoreNoopGas, nil
} }
original := evm.StateDB.GetCommittedState(contract.Address(), common.Hash(x.Bytes32())) original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
if original == current { if original == current {
if original == (common.Hash{}) { // create slot (2.1.1) if original == (common.Hash{}) { // create slot (2.1.1)
return params.NetSstoreInitGas, nil return params.NetSstoreInitGas, nil
@ -184,14 +184,14 @@ func gasSStoreEIP2200(evm *EVM, contract *Contract, stack *Stack, mem *Memory, m
// Gas sentry honoured, do the actual gas calculation based on the stored value // Gas sentry honoured, do the actual gas calculation based on the stored value
var ( var (
y, x = stack.Back(1), stack.Back(0) y, x = stack.Back(1), stack.Back(0)
current = evm.StateDB.GetState(contract.Address(), common.Hash(x.Bytes32())) current = evm.StateDB.GetState(contract.Address(), x.Bytes32())
) )
value := common.Hash(y.Bytes32()) value := common.Hash(y.Bytes32())
if current == value { // noop (1) if current == value { // noop (1)
return params.SloadGasEIP2200, nil return params.SloadGasEIP2200, nil
} }
original := evm.StateDB.GetCommittedState(contract.Address(), common.Hash(x.Bytes32())) original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
if original == current { if original == current {
if original == (common.Hash{}) { // create slot (2.1.1) if original == (common.Hash{}) { // create slot (2.1.1)
return params.SstoreSetGasEIP2200, nil return params.SstoreSetGasEIP2200, nil

View file

@ -343,7 +343,7 @@ func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeConte
func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
slot := scope.Stack.peek() slot := scope.Stack.peek()
slot.SetUint64(uint64(interpreter.evm.StateDB.GetCodeSize(common.Address(slot.Bytes20())))) slot.SetUint64(uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20())))
return nil, nil return nil, nil
} }
@ -540,7 +540,7 @@ func opSstore(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b
loc := scope.Stack.pop() loc := scope.Stack.pop()
val := scope.Stack.pop() val := scope.Stack.pop()
interpreter.evm.StateDB.SetState(scope.Contract.Address(), interpreter.evm.StateDB.SetState(scope.Contract.Address(),
common.Hash(loc.Bytes32()), common.Hash(val.Bytes32())) loc.Bytes32(), val.Bytes32())
return nil, nil return nil, nil
} }
@ -842,7 +842,7 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext
} }
beneficiary := scope.Stack.pop() beneficiary := scope.Stack.pop()
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address()) balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
interpreter.evm.StateDB.AddBalance(common.Address(beneficiary.Bytes20()), balance) interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance)
interpreter.evm.StateDB.Suicide(scope.Contract.Address()) interpreter.evm.StateDB.Suicide(scope.Contract.Address())
if interpreter.cfg.Debug { if interpreter.cfg.Debug {
interpreter.cfg.Tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance) interpreter.cfg.Tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance)
@ -864,7 +864,7 @@ func makeLog(size int) executionFunc {
mStart, mSize := stack.pop(), stack.pop() mStart, mSize := stack.pop(), stack.pop()
for i := 0; i < size; i++ { for i := 0; i < size; i++ {
addr := stack.pop() addr := stack.pop()
topics[i] = common.Hash(addr.Bytes32()) topics[i] = addr.Bytes32()
} }
d := scope.Memory.GetCopy(int64(mStart.Uint64()), int64(mSize.Uint64())) d := scope.Memory.GetCopy(int64(mStart.Uint64()), int64(mSize.Uint64()))

View file

@ -73,7 +73,7 @@ func gasSStoreEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memory, m
// return params.SloadGasEIP2200, nil // return params.SloadGasEIP2200, nil
return cost + WarmStorageReadCostEIP2929, nil // SLOAD_GAS return cost + WarmStorageReadCostEIP2929, nil // SLOAD_GAS
} }
original := evm.StateDB.GetCommittedState(contract.Address(), common.Hash(x.Bytes32())) original := evm.StateDB.GetCommittedState(contract.Address(), x.Bytes32())
if original == current { if original == current {
if original == (common.Hash{}) { // create slot (2.1.1) if original == (common.Hash{}) { // create slot (2.1.1)
return cost + params.SstoreSetGasEIP2200, nil return cost + params.SstoreSetGasEIP2200, nil