transaction: add script length limit

As it is implemented in C# code.
This commit is contained in:
Roman Khimov 2020-10-07 18:23:10 +03:00
parent d029f5c0d8
commit 705941a800

View file

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"math"
"math/rand" "math/rand"
"github.com/nspcc-dev/neo-go/pkg/config/netmode" "github.com/nspcc-dev/neo-go/pkg/config/netmode"
@ -14,6 +15,8 @@ import (
) )
const ( const (
// MaxScriptLength is the limit for transaction's script length.
MaxScriptLength = math.MaxUint16
// MaxTransactionSize is the upper limit size in bytes that a transaction can reach. It is // MaxTransactionSize is the upper limit size in bytes that a transaction can reach. It is
// set to be 102400. // set to be 102400.
MaxTransactionSize = 102400 MaxTransactionSize = 102400
@ -140,7 +143,7 @@ func (t *Transaction) decodeHashableFields(br *io.BinReader) {
t.ValidUntilBlock = br.ReadU32LE() t.ValidUntilBlock = br.ReadU32LE()
br.ReadArray(&t.Signers, MaxAttributes) br.ReadArray(&t.Signers, MaxAttributes)
br.ReadArray(&t.Attributes, MaxAttributes-len(t.Signers)) br.ReadArray(&t.Attributes, MaxAttributes-len(t.Signers))
t.Script = br.ReadVarBytes() t.Script = br.ReadVarBytes(MaxScriptLength)
if br.Err == nil { if br.Err == nil {
br.Err = t.isValid() br.Err = t.isValid()
} }