core/vm: changed stack behaviour

The vm stack no longer keeps track of a stack ptr but instead just let
go decide on reuse
This commit is contained in:
Jeffrey Wilcke 2015-07-17 23:09:36 +02:00
parent 72a9e9f7f0
commit 64c7e1e545
4 changed files with 16 additions and 38 deletions

View file

@ -392,7 +392,6 @@ func chm(genesis *types.Block, db common.Database) *ChainManager {
bc.futureBlocks, _ = lru.New(100)
bc.processor = bproc{}
bc.ResetWithGenesisBlock(genesis)
bc.txState = state.ManageState(bc.State())
return bc
}

View file

@ -54,8 +54,8 @@ func baseCheck(op OpCode, stack *stack, gas *big.Int) error {
return err
}
if r.stackPush > 0 && len(stack.data)-r.stackPop+r.stackPush > int(params.StackLimit.Int64())+1 {
return fmt.Errorf("stack limit reached %d (%d)", len(stack.data), params.StackLimit.Int64())
if r.stackPush > 0 && stack.len()-r.stackPop+r.stackPush > int(params.StackLimit.Int64()) {
return fmt.Errorf("stack limit reached %d (%d)", stack.len(), params.StackLimit.Int64())
}
gas.Add(gas, r.gas)

View file

@ -1,19 +1,3 @@
// Copyright 2014 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
package vm
import (
@ -27,32 +11,27 @@ func newstack() *stack {
type stack struct {
data []*big.Int
ptr int
}
func (st *stack) Data() []*big.Int {
return st.data[:st.ptr]
return st.data
}
func (st *stack) push(d *big.Int) {
// NOTE push limit (1024) is checked in baseCheck
stackItem := new(big.Int).Set(d)
if len(st.data) > st.ptr {
st.data[st.ptr] = stackItem
} else {
st.data = append(st.data, stackItem)
}
st.ptr++
//stackItem := new(big.Int).Set(d)
//st.data = append(st.data, stackItem)
st.data = append(st.data, d)
}
func (st *stack) pop() (ret *big.Int) {
st.ptr--
ret = st.data[st.ptr]
ret = st.data[len(st.data)-1]
st.data = st.data[:len(st.data)-1]
return
}
func (st *stack) len() int {
return st.ptr
return len(st.data)
}
func (st *stack) swap(n int) {
@ -60,7 +39,7 @@ func (st *stack) swap(n int) {
}
func (st *stack) dup(n int) {
st.push(st.data[st.len()-n])
st.push(new(big.Int).Set(st.data[st.len()-n]))
}
func (st *stack) peek() *big.Int {

View file

@ -376,7 +376,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
addr := common.BigToAddress(stack.pop())
balance := statedb.GetBalance(addr)
stack.push(balance)
stack.push(new(big.Int).Set(balance))
case ORIGIN:
origin := self.env.Origin()
@ -388,7 +388,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
stack.push(common.Bytes2Big(caller.Bytes()))
case CALLVALUE:
stack.push(value)
stack.push(new(big.Int).Set(value))
case CALLDATALOAD:
data := getData(input, stack.pop(), common.Big32)
@ -441,7 +441,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
mem.Set(mOff.Uint64(), l.Uint64(), codeCopy)
case GASPRICE:
stack.push(context.Price)
stack.push(new(big.Int).Set(context.Price))
case BLOCKHASH:
num := stack.pop()
@ -471,11 +471,11 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
case DIFFICULTY:
difficulty := self.env.Difficulty()
stack.push(difficulty)
stack.push(new(big.Int).Set(difficulty))
case GASLIMIT:
stack.push(self.env.GasLimit())
stack.push(new(big.Int).Set(self.env.GasLimit()))
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32:
size := uint64(op - PUSH1 + 1)
@ -555,7 +555,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
case MSIZE:
stack.push(big.NewInt(int64(mem.Len())))
case GAS:
stack.push(context.Gas)
stack.push(new(big.Int).Set(context.Gas))
case CREATE: