native: optimize contract call

Port neo-project/neo#3170.

Close #3346

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
Ekaterina Pavlova 2024-03-19 18:40:51 +03:00
parent 7e12cc11e4
commit 2000158456
3 changed files with 10 additions and 6 deletions

View file

@ -93,12 +93,16 @@ func (c *Contract) FromStackItem(item stackitem.Item) error {
if err != nil {
return err
}
c.NEF, err = nef.FileFromBytes(bytes)
skipCheck := false
if c.UpdateCounter > 0 {
skipCheck = true
}
c.NEF, err = nef.FileFromBytes(bytes, skipCheck)
if err != nil {
return err
}
m := new(manifest.Manifest)
err = m.FromStackItem(arr[4])
err = m.FromStackItem(arr[4], skipCheck)
if err != nil {
return err
}

View file

@ -206,13 +206,13 @@ func extraToStackItem(rawExtra []byte) stackitem.Item {
}
// FromStackItem converts stackitem.Item to Manifest.
func (m *Manifest) FromStackItem(item stackitem.Item) error {
func (m *Manifest) FromStackItem(item stackitem.Item, skipCheck ...bool) error {
var err error
if item.Type() != stackitem.StructT {
return errors.New("invalid Manifest stackitem type")
}
str := item.Value().([]stackitem.Item)
if len(str) != 8 {
if (len(skipCheck) == 0 || !skipCheck[0]) && len(str) != 8 {
return errors.New("invalid stackitem length")
}
m.Name, err = stackitem.ToString(str[0])

View file

@ -184,9 +184,9 @@ func (n File) bytes(checkSize bool) ([]byte, error) {
}
// FileFromBytes returns a NEF File deserialized from the given bytes.
func FileFromBytes(source []byte) (File, error) {
func FileFromBytes(source []byte, skipCheck ...bool) (File, error) {
result := File{}
if len(source) > stackitem.MaxSize {
if len(source) > stackitem.MaxSize && (len(skipCheck) == 0 || !skipCheck[0]) {
return result, fmt.Errorf("invalid NEF file size: expected %d at max, got %d", stackitem.MaxSize, len(source))
}
r := io.NewBinReaderFromBuf(source)