stack_table.go 555 Bytes
Newer Older
1 2 3 4 5 6 7 8
package vm

import (
	"fmt"

	"github.com/ethereum/go-ethereum/params"
)

9
func makeStackFunc(pop, push int) stackValidationFunc {
10 11 12 13 14
	return func(stack *Stack) error {
		if err := stack.require(pop); err != nil {
			return err
		}

15
		if stack.len()+push-pop > int(params.StackLimit) {
16
			return fmt.Errorf("stack limit reached %d (%d)", stack.len(), params.StackLimit)
17 18 19 20
		}
		return nil
	}
}
21 22

func makeDupStackFunc(n int) stackValidationFunc {
23
	return makeStackFunc(n, n+1)
24 25 26
}

func makeSwapStackFunc(n int) stackValidationFunc {
27
	return makeStackFunc(n, n)
28
}