mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
core/vm/evm : Reused codeSize everywhere instead of calling len(ret) multiple times
This commit is contained in:
parent
b1809d13d1
commit
6404c37a62
1 changed files with 13 additions and 8 deletions
|
|
@ -578,32 +578,37 @@ func (evm *EVM) initNewContract(contract *Contract, address common.Address) ([]b
|
||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
codeSize := len(ret)
|
||||||
|
|
||||||
// Check whether the max code size has been exceeded, assign err if the case.
|
// Check whether the max code size has been exceeded, assign err if the case.
|
||||||
if evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize {
|
if evm.chainRules.IsEIP158 && codeSize > params.MaxCodeSize {
|
||||||
return ret, ErrMaxCodeSizeExceeded
|
return ret, ErrMaxCodeSizeExceeded
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if codeSize == 0 {
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Reject code starting with 0xEF if EIP-3541 is enabled.
|
// Reject code starting with 0xEF if EIP-3541 is enabled.
|
||||||
if len(ret) >= 1 && ret[0] == 0xEF && evm.chainRules.IsLondon {
|
if codeSize >= 1 && ret[0] == 0xEF && evm.chainRules.IsLondon {
|
||||||
return ret, ErrInvalidCode
|
return ret, ErrInvalidCode
|
||||||
}
|
}
|
||||||
|
|
||||||
if !evm.chainRules.IsEIP4762 {
|
if !evm.chainRules.IsEIP4762 {
|
||||||
createDataGas := uint64(len(ret)) * params.CreateDataGas
|
createDataGas := uint64(codeSize) * params.CreateDataGas
|
||||||
if !contract.UseGas(createDataGas, evm.Config.Tracer, tracing.GasChangeCallCodeStorage) {
|
if !contract.UseGas(createDataGas, evm.Config.Tracer, tracing.GasChangeCallCodeStorage) {
|
||||||
return ret, ErrCodeStoreOutOfGas
|
return ret, ErrCodeStoreOutOfGas
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
consumed, wanted := evm.AccessEvents.CodeChunksRangeGas(address, 0, uint64(len(ret)), uint64(len(ret)), true, contract.Gas)
|
consumed, wanted := evm.AccessEvents.CodeChunksRangeGas(address, 0, uint64(codeSize), uint64(codeSize), true, contract.Gas)
|
||||||
contract.UseGas(consumed, evm.Config.Tracer, tracing.GasChangeWitnessCodeChunk)
|
contract.UseGas(consumed, evm.Config.Tracer, tracing.GasChangeWitnessCodeChunk)
|
||||||
if len(ret) > 0 && (consumed < wanted) {
|
if codeSize > 0 && (consumed < wanted) {
|
||||||
return ret, ErrCodeStoreOutOfGas
|
return ret, ErrCodeStoreOutOfGas
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ret) > 0 {
|
evm.StateDB.SetCode(address, ret, tracing.CodeChangeContractCreation)
|
||||||
evm.StateDB.SetCode(address, ret, tracing.CodeChangeContractCreation)
|
|
||||||
}
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue