From 2ab0e6c3994d3c6459e70393e86b7c782e3a1f16 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Thu, 10 Dec 2020 10:42:12 +0300 Subject: [PATCH] core: check stack length before returning `false` verification result We must be sure that stack has no other items before returning `false` verification result. It is an error in both cases, but by preserving the order we know exactly that it was correct `false` on stack. --- pkg/core/blockchain.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index aceabd0a7..2d2c00fbb 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1670,12 +1670,12 @@ func (bc *Blockchain) verifyHashAgainstScript(hash util.Uint160, witness *transa if err != nil { return 0, fmt.Errorf("%w: invalid return value", ErrVerificationFailed) } - if !res { - return 0, fmt.Errorf("%w: invalid signature", ErrVerificationFailed) - } if vm.Estack().Len() != 0 { return 0, fmt.Errorf("%w: expected exactly one returned value", ErrVerificationFailed) } + if !res { + return 0, fmt.Errorf("%w: invalid signature", ErrVerificationFailed) + } } else { return 0, fmt.Errorf("%w: no result returned from the script", ErrVerificationFailed) }