mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
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:
parent
72a9e9f7f0
commit
64c7e1e545
4 changed files with 16 additions and 38 deletions
|
|
@ -392,7 +392,6 @@ func chm(genesis *types.Block, db common.Database) *ChainManager {
|
||||||
bc.futureBlocks, _ = lru.New(100)
|
bc.futureBlocks, _ = lru.New(100)
|
||||||
bc.processor = bproc{}
|
bc.processor = bproc{}
|
||||||
bc.ResetWithGenesisBlock(genesis)
|
bc.ResetWithGenesisBlock(genesis)
|
||||||
bc.txState = state.ManageState(bc.State())
|
|
||||||
|
|
||||||
return bc
|
return bc
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,8 @@ func baseCheck(op OpCode, stack *stack, gas *big.Int) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.stackPush > 0 && len(stack.data)-r.stackPop+r.stackPush > int(params.StackLimit.Int64())+1 {
|
if r.stackPush > 0 && stack.len()-r.stackPop+r.stackPush > int(params.StackLimit.Int64()) {
|
||||||
return fmt.Errorf("stack limit reached %d (%d)", len(stack.data), params.StackLimit.Int64())
|
return fmt.Errorf("stack limit reached %d (%d)", stack.len(), params.StackLimit.Int64())
|
||||||
}
|
}
|
||||||
|
|
||||||
gas.Add(gas, r.gas)
|
gas.Add(gas, r.gas)
|
||||||
|
|
|
||||||
|
|
@ -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
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -27,32 +11,27 @@ func newstack() *stack {
|
||||||
|
|
||||||
type stack struct {
|
type stack struct {
|
||||||
data []*big.Int
|
data []*big.Int
|
||||||
ptr int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *stack) Data() []*big.Int {
|
func (st *stack) Data() []*big.Int {
|
||||||
return st.data[:st.ptr]
|
return st.data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *stack) push(d *big.Int) {
|
func (st *stack) push(d *big.Int) {
|
||||||
// NOTE push limit (1024) is checked in baseCheck
|
// NOTE push limit (1024) is checked in baseCheck
|
||||||
stackItem := new(big.Int).Set(d)
|
//stackItem := new(big.Int).Set(d)
|
||||||
if len(st.data) > st.ptr {
|
//st.data = append(st.data, stackItem)
|
||||||
st.data[st.ptr] = stackItem
|
st.data = append(st.data, d)
|
||||||
} else {
|
|
||||||
st.data = append(st.data, stackItem)
|
|
||||||
}
|
|
||||||
st.ptr++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *stack) pop() (ret *big.Int) {
|
func (st *stack) pop() (ret *big.Int) {
|
||||||
st.ptr--
|
ret = st.data[len(st.data)-1]
|
||||||
ret = st.data[st.ptr]
|
st.data = st.data[:len(st.data)-1]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *stack) len() int {
|
func (st *stack) len() int {
|
||||||
return st.ptr
|
return len(st.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *stack) swap(n int) {
|
func (st *stack) swap(n int) {
|
||||||
|
|
@ -60,7 +39,7 @@ func (st *stack) swap(n int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *stack) dup(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 {
|
func (st *stack) peek() *big.Int {
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
|
||||||
addr := common.BigToAddress(stack.pop())
|
addr := common.BigToAddress(stack.pop())
|
||||||
balance := statedb.GetBalance(addr)
|
balance := statedb.GetBalance(addr)
|
||||||
|
|
||||||
stack.push(balance)
|
stack.push(new(big.Int).Set(balance))
|
||||||
|
|
||||||
case ORIGIN:
|
case ORIGIN:
|
||||||
origin := self.env.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()))
|
stack.push(common.Bytes2Big(caller.Bytes()))
|
||||||
|
|
||||||
case CALLVALUE:
|
case CALLVALUE:
|
||||||
stack.push(value)
|
stack.push(new(big.Int).Set(value))
|
||||||
|
|
||||||
case CALLDATALOAD:
|
case CALLDATALOAD:
|
||||||
data := getData(input, stack.pop(), common.Big32)
|
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)
|
mem.Set(mOff.Uint64(), l.Uint64(), codeCopy)
|
||||||
|
|
||||||
case GASPRICE:
|
case GASPRICE:
|
||||||
stack.push(context.Price)
|
stack.push(new(big.Int).Set(context.Price))
|
||||||
|
|
||||||
case BLOCKHASH:
|
case BLOCKHASH:
|
||||||
num := stack.pop()
|
num := stack.pop()
|
||||||
|
|
@ -471,11 +471,11 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
|
||||||
case DIFFICULTY:
|
case DIFFICULTY:
|
||||||
difficulty := self.env.Difficulty()
|
difficulty := self.env.Difficulty()
|
||||||
|
|
||||||
stack.push(difficulty)
|
stack.push(new(big.Int).Set(difficulty))
|
||||||
|
|
||||||
case GASLIMIT:
|
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:
|
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)
|
size := uint64(op - PUSH1 + 1)
|
||||||
|
|
@ -555,7 +555,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
|
||||||
case MSIZE:
|
case MSIZE:
|
||||||
stack.push(big.NewInt(int64(mem.Len())))
|
stack.push(big.NewInt(int64(mem.Len())))
|
||||||
case GAS:
|
case GAS:
|
||||||
stack.push(context.Gas)
|
stack.push(new(big.Int).Set(context.Gas))
|
||||||
|
|
||||||
case CREATE:
|
case CREATE:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue