mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
consume gas for getting deployment code
This commit is contained in:
parent
75ee88a536
commit
df114344d0
1 changed files with 18 additions and 2 deletions
|
|
@ -530,7 +530,7 @@ func (evm *EVM) CreateWithAddress(caller ContractRef, code []byte, gas uint64, v
|
|||
return evm.create(caller, &codeAndHash{code: code}, gas, value, address, CREATE)
|
||||
}
|
||||
|
||||
func (evm *EVM) GetDeploymentCode(caller ContractRef, code []byte, gas uint64, value *big.Int, address common.Address) ([]byte, error) {
|
||||
func (evm *EVM) GetDeploymentCode(caller ContractRef, code []byte, gas uint64, value *big.Int, address common.Address) ([]byte, uint64, error) {
|
||||
contract := NewContract(caller, AccountRef(address), value, gas)
|
||||
contract.SetCodeOptionalHash(&address, &codeAndHash{code: code})
|
||||
|
||||
|
|
@ -544,7 +544,23 @@ func (evm *EVM) GetDeploymentCode(caller ContractRef, code []byte, gas uint64, v
|
|||
if err == nil && len(ret) >= 1 && ret[0] == 0xEF && evm.chainRules.IsLondon {
|
||||
err = ErrInvalidCode
|
||||
}
|
||||
return ret, err
|
||||
|
||||
if err == nil {
|
||||
createDataGas := uint64(len(ret)) * params.CreateDataGas
|
||||
if !contract.UseGas(createDataGas, evm.Config.Tracer, tracing.GasChangeCallCodeStorage) {
|
||||
err = ErrCodeStoreOutOfGas
|
||||
}
|
||||
}
|
||||
|
||||
// When an error was returned by the EVM or when setting the creation code
|
||||
// above we revert to the snapshot and consume any gas remaining. Additionally,
|
||||
// when we're in homestead this also counts for code storage gas errors.
|
||||
if err != nil && (evm.chainRules.IsHomestead || err != ErrCodeStoreOutOfGas) {
|
||||
if err != ErrExecutionReverted {
|
||||
contract.UseGas(contract.Gas, evm.Config.Tracer, tracing.GasChangeCallFailedExecution)
|
||||
}
|
||||
}
|
||||
return ret, contract.Gas, err
|
||||
}
|
||||
|
||||
// ChainConfig returns the environment's chain configuration
|
||||
|
|
|
|||
Loading…
Reference in a new issue