github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/core/vm/stack_table.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package vm 13 14 import ( 15 "fmt" 16 17 "github.com/Sberex/go-sberex/params" 18 ) 19 20 func makeStackFunc(pop, push int) stackValidationFunc { 21 return func(stack *Stack) error { 22 if err := stack.require(pop); err != nil { 23 return err 24 } 25 26 if stack.len()+push-pop > int(params.StackLimit) { 27 return fmt.Errorf("stack limit reached %d (%d)", stack.len(), params.StackLimit) 28 } 29 return nil 30 } 31 } 32 33 func makeDupStackFunc(n int) stackValidationFunc { 34 return makeStackFunc(n, n+1) 35 } 36 37 func makeSwapStackFunc(n int) stackValidationFunc { 38 return makeStackFunc(n, n) 39 }