forked from cerc-io/plugeth
core/vm: unexported stack again. No longer required
This commit is contained in:
parent
065aff9ffa
commit
fc2a061d51
@ -21,7 +21,7 @@ var (
|
|||||||
GasContractByte = big.NewInt(200)
|
GasContractByte = big.NewInt(200)
|
||||||
)
|
)
|
||||||
|
|
||||||
func baseCheck(op OpCode, stack *Stack, gas *big.Int) error {
|
func baseCheck(op OpCode, stack *stack, gas *big.Int) error {
|
||||||
// PUSH and DUP are a bit special. They all cost the same but we do want to have checking on stack push limit
|
// PUSH and DUP are a bit special. They all cost the same but we do want to have checking on stack push limit
|
||||||
// PUSH is also allowed to calculate the same price for all PUSHes
|
// PUSH is also allowed to calculate the same price for all PUSHes
|
||||||
// DUP requirements are handled elsewhere (except for the stack limit check)
|
// DUP requirements are handled elsewhere (except for the stack limit check)
|
||||||
|
@ -5,20 +5,20 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newStack() *Stack {
|
func newstack() *stack {
|
||||||
return &Stack{}
|
return &stack{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stack struct {
|
type stack struct {
|
||||||
data []*big.Int
|
data []*big.Int
|
||||||
ptr int
|
ptr int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) Data() []*big.Int {
|
func (st *stack) Data() []*big.Int {
|
||||||
return st.data
|
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 {
|
if len(st.data) > st.ptr {
|
||||||
@ -29,36 +29,36 @@ func (st *Stack) push(d *big.Int) {
|
|||||||
st.ptr++
|
st.ptr++
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) pop() (ret *big.Int) {
|
func (st *stack) pop() (ret *big.Int) {
|
||||||
st.ptr--
|
st.ptr--
|
||||||
ret = st.data[st.ptr]
|
ret = st.data[st.ptr]
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) len() int {
|
func (st *stack) len() int {
|
||||||
return st.ptr
|
return st.ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) swap(n int) {
|
func (st *stack) swap(n int) {
|
||||||
st.data[st.len()-n], st.data[st.len()-1] = st.data[st.len()-1], st.data[st.len()-n]
|
st.data[st.len()-n], st.data[st.len()-1] = st.data[st.len()-1], st.data[st.len()-n]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) dup(n int) {
|
func (st *stack) dup(n int) {
|
||||||
st.push(st.data[st.len()-n])
|
st.push(st.data[st.len()-n])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) peek() *big.Int {
|
func (st *stack) peek() *big.Int {
|
||||||
return st.data[st.len()-1]
|
return st.data[st.len()-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) require(n int) error {
|
func (st *stack) require(n int) error {
|
||||||
if st.len() < n {
|
if st.len() < n {
|
||||||
return fmt.Errorf("stack underflow (%d <=> %d)", len(st.data), n)
|
return fmt.Errorf("stack underflow (%d <=> %d)", len(st.data), n)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Stack) Print() {
|
func (st *stack) Print() {
|
||||||
fmt.Println("### stack ###")
|
fmt.Println("### stack ###")
|
||||||
if len(st.data) > 0 {
|
if len(st.data) > 0 {
|
||||||
for i, val := range st.data {
|
for i, val := range st.data {
|
||||||
|
@ -75,7 +75,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
|
|||||||
op OpCode // current opcode
|
op OpCode // current opcode
|
||||||
codehash = crypto.Sha3Hash(code) // codehash is used when doing jump dest caching
|
codehash = crypto.Sha3Hash(code) // codehash is used when doing jump dest caching
|
||||||
mem = NewMemory() // bound memory
|
mem = NewMemory() // bound memory
|
||||||
stack = newStack() // local stack
|
stack = newstack() // local stack
|
||||||
pc = uint64(0) // program counter
|
pc = uint64(0) // program counter
|
||||||
statedb = self.env.State() // current state
|
statedb = self.env.State() // current state
|
||||||
|
|
||||||
@ -632,7 +632,7 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) {
|
|||||||
|
|
||||||
// calculateGasAndSize calculates the required given the opcode and stack items calculates the new memorysize for
|
// calculateGasAndSize calculates the required given the opcode and stack items calculates the new memorysize for
|
||||||
// the operation. This does not reduce gas or resizes the memory.
|
// the operation. This does not reduce gas or resizes the memory.
|
||||||
func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCode, statedb *state.StateDB, mem *Memory, stack *Stack) (*big.Int, *big.Int, error) {
|
func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCode, statedb *state.StateDB, mem *Memory, stack *stack) (*big.Int, *big.Int, error) {
|
||||||
var (
|
var (
|
||||||
gas = new(big.Int)
|
gas = new(big.Int)
|
||||||
newMemSize *big.Int = new(big.Int)
|
newMemSize *big.Int = new(big.Int)
|
||||||
@ -789,7 +789,7 @@ func (self *Vm) RunPrecompiled(p *PrecompiledAccount, input []byte, context *Con
|
|||||||
|
|
||||||
// log emits a log event to the environment for each opcode encountered. This is not to be confused with the
|
// log emits a log event to the environment for each opcode encountered. This is not to be confused with the
|
||||||
// LOG* opcode.
|
// LOG* opcode.
|
||||||
func (self *Vm) log(pc uint64, op OpCode, gas *big.Int, memory *Memory, stack *Stack, context *Context) {
|
func (self *Vm) log(pc uint64, op OpCode, gas *big.Int, memory *Memory, stack *stack, context *Context) {
|
||||||
if Debug {
|
if Debug {
|
||||||
mem := make([]byte, len(memory.Data()))
|
mem := make([]byte, len(memory.Data()))
|
||||||
copy(mem, memory.Data())
|
copy(mem, memory.Data())
|
||||||
|
Loading…
Reference in New Issue
Block a user