diff --git a/core/vm/evm.go b/core/vm/evm.go index 74af45f5c..0ea1ba5ba 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -49,15 +49,11 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err // Intercept the StateManager calls if contract.Address() == StateManagerAddress { log.Debug("Calling State Manager contract.", "StateManagerAddress", hex.EncodeToString(StateManagerAddress.Bytes())) - gas := stateManagerRequiredGas(input) - if contract.UseGas(gas) { - ret, err := callStateManager(input, evm, contract) - if err != nil { - log.Error("State manager error!", "Error", err) - } - return ret, err + ret, err := callStateManager(input, evm, contract) + if err != nil { + log.Error("State manager error!", err) } - return nil, ErrOutOfGas + return ret, err } if contract.CodeAddr != nil { diff --git a/core/vm/state_manager.go b/core/vm/state_manager.go index 64869c6eb..24a5978ce 100644 --- a/core/vm/state_manager.go +++ b/core/vm/state_manager.go @@ -11,55 +11,23 @@ import ( "github.com/ethereum/go-ethereum/log" ) -type stateManagerFunctionAndGasCost struct { - smFunction stateManagerFunction - smGasCost uint64 -} type stateManagerFunction func(*EVM, *Contract, []byte) ([]byte, error) -var funcs = map[string]stateManagerFunctionAndGasCost{ - "getStorage(address,bytes32)": { - smFunction: getStorage, - smGasCost: 20000, - }, - "setStorage(address,bytes32,bytes32)": { - smFunction: setStorage, - smGasCost: 20000, - }, - "getOvmContractNonce(address)": { - smFunction: getOvmContractNonce, - smGasCost: 20000, - }, - "incrementOvmContractNonce(address)": { - smFunction: incrementOvmContractNonce, - smGasCost: 20000, - }, - "getCodeContractBytecode(address)": { - smFunction: getCodeContractBytecode, - smGasCost: 20000, - }, - "getCodeContractHash(address)": { - smFunction: getCodeContractHash, - smGasCost: 20000, - }, - "getCodeContractAddressFromOvmAddress(address)": { - smFunction: getCodeContractAddress, - smGasCost: 20000, - }, - "associateCodeContract(address,address)": { - smFunction: associateCodeContract, - smGasCost: 20000, - }, - "registerCreatedContract(address)": { - smFunction: registerCreatedContract, - smGasCost: 20000, - }, +var funcs = map[string]stateManagerFunction{ + "getStorage(address,bytes32)": getStorage, + "setStorage(address,bytes32,bytes32)": setStorage, + "getOvmContractNonce(address)": getOvmContractNonce, + "incrementOvmContractNonce(address)": incrementOvmContractNonce, + "getCodeContractBytecode(address)": getCodeContractBytecode, + "getCodeContractHash(address)": getCodeContractHash, + "getCodeContractAddressFromOvmAddress(address)": getCodeContractAddress, + "associateCodeContract(address,address)": associateCodeContract, + "registerCreatedContract(address)": registerCreatedContract, } - -var methodIds map[[4]byte]stateManagerFunctionAndGasCost +var methodIds map[[4]byte]stateManagerFunction func init() { - methodIds = make(map[[4]byte]stateManagerFunctionAndGasCost, len(funcs)) + methodIds = make(map[[4]byte]stateManagerFunction, len(funcs)) for methodSignature, f := range funcs { methodIds[methodSignatureToMethodID(methodSignature)] = f } @@ -71,24 +39,16 @@ func methodSignatureToMethodID(methodSignature string) [4]byte { return methodID } -func stateManagerRequiredGas(input []byte) (gas uint64) { - var methodID [4]byte - copy(methodID[:], input[:4]) - gas = methodIds[methodID].smGasCost - return gas -} - func callStateManager(input []byte, evm *EVM, contract *Contract) (ret []byte, err error) { var methodID [4]byte + if len(input) == 0 { + return nil, nil + } copy(methodID[:], input[:4]) - ret, err = methodIds[methodID].smFunction(evm, contract, input) + ret, err = methodIds[methodID](evm, contract, input) return ret, err } -/* - * StateManager functions - */ - func setStorage(evm *EVM, contract *Contract, input []byte) (ret []byte, err error) { address := common.BytesToAddress(input[4:36]) key := common.BytesToHash(input[36:68])