From bbc4ea4ae8e8a962deae3d5693d9d4a9376eab88 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Thu, 5 Jan 2017 11:52:10 +0100 Subject: core/vm: improved EVM run loop & instruction calling (#3378) The run loop, which previously contained custom opcode executes have been removed and has been simplified to a few checks. Each operation consists of 4 elements: execution function, gas cost function, stack validation function and memory size function. The execution function implements the operation's runtime behaviour, the gas cost function implements the operation gas costs function and greatly depends on the memory and stack, the stack validation function validates the stack and makes sure that enough items can be popped off and pushed on and the memory size function calculates the memory required for the operation and returns it. This commit also allows the EVM to go unmetered. This is helpful for offline operations such as contract calls. --- core/state_transition.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'core/state_transition.go') diff --git a/core/state_transition.go b/core/state_transition.go index 48540be14..38fbebfd9 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -57,7 +57,7 @@ type StateTransition struct { data []byte state vm.StateDB - env *vm.Environment + env *vm.EVM } // Message represents a message sent to a contract. @@ -106,7 +106,7 @@ func IntrinsicGas(data []byte, contractCreation, homestead bool) *big.Int { } // NewStateTransition initialises and returns a new state transition object. -func NewStateTransition(env *vm.Environment, msg Message, gp *GasPool) *StateTransition { +func NewStateTransition(env *vm.EVM, msg Message, gp *GasPool) *StateTransition { return &StateTransition{ gp: gp, env: env, @@ -127,7 +127,7 @@ func NewStateTransition(env *vm.Environment, msg Message, gp *GasPool) *StateTra // the gas used (which includes gas refunds) and an error if it failed. An error always // indicates a core error meaning that the message would always fail for that particular // state and would never be accepted within a block. -func ApplyMessage(env *vm.Environment, msg Message, gp *GasPool) ([]byte, *big.Int, error) { +func ApplyMessage(env *vm.EVM, msg Message, gp *GasPool) ([]byte, *big.Int, error) { st := NewStateTransition(env, msg, gp) ret, _, gasUsed, err := st.TransitionDb() @@ -159,7 +159,7 @@ func (self *StateTransition) to() vm.Account { func (self *StateTransition) useGas(amount *big.Int) error { if self.gas.Cmp(amount) < 0 { - return vm.OutOfGasError + return vm.ErrOutOfGas } self.gas.Sub(self.gas, amount) @@ -233,7 +233,7 @@ func (self *StateTransition) TransitionDb() (ret []byte, requiredGas, usedGas *b ) if contractCreation { ret, _, vmerr = vmenv.Create(sender, self.data, self.gas, self.value) - if homestead && err == vm.CodeStoreOutOfGasError { + if homestead && err == vm.ErrCodeStoreOutOfGas { self.gas = Big0 } } else { -- cgit v1.2.3