mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Enforce a combined max stack depth of 1000 after every opcode.
This limit is for the sum of main and alt stacks. Found by bitcoind negative tests.
This commit is contained in:
parent
d6d755e411
commit
dec16d7ff2
12
script.go
12
script.go
@ -116,8 +116,16 @@ var (
|
||||
// StackErrNonPushOnly is returned when ScriptInfo is called with a
|
||||
// pkScript that peforms operations other that pushing data to the stack.
|
||||
StackErrNonPushOnly = errors.New("SigScript is non pushonly")
|
||||
|
||||
// StackErrOverflow is returned when stack and altstack combined depth
|
||||
// is over the limit.
|
||||
StackErrOverflow = errors.New("Stacks overflowed")
|
||||
)
|
||||
|
||||
// maxStackSize is the maximum combined height of stack and alt stack during
|
||||
// execution.
|
||||
const maxStackSize = 1000
|
||||
|
||||
// ErrUnsupportedAddress is returned when a concrete type that implements
|
||||
// a btcutil.Address is not a supported type.
|
||||
var ErrUnsupportedAddress = errors.New("unsupported address type")
|
||||
@ -599,6 +607,10 @@ func (m *Script) Step() (done bool, err error) {
|
||||
return true, err
|
||||
}
|
||||
|
||||
if m.dstack.Depth() + m.astack.Depth() > maxStackSize {
|
||||
return false, StackErrOverflow
|
||||
}
|
||||
|
||||
// prepare for next instruction
|
||||
m.scriptoff++
|
||||
if m.scriptoff >= len(m.scripts[m.scriptidx]) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user