Skip to content

Commit

Permalink
Merge pull request #29 from sei-protocol/get-deployment-code-consume-gas
Browse files Browse the repository at this point in the history
consume gas for getting deployment code
  • Loading branch information
codchen authored May 14, 2024
2 parents 75ee88a + df11434 commit 6460822
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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
Expand Down

0 comments on commit 6460822

Please sign in to comment.