From a003879b843a177196a6c706b40ae0f2479d2842 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 2 Dec 2021 15:30:20 +0300 Subject: [PATCH] native: avoid allocations in increaseBalance --- pkg/core/native/native_gas.go | 2 +- pkg/core/native/native_neo.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/core/native/native_gas.go b/pkg/core/native/native_gas.go index 2903e10f9..e06925741 100644 --- a/pkg/core/native/native_gas.go +++ b/pkg/core/native/native_gas.go @@ -54,7 +54,7 @@ func (g *GAS) increaseBalance(_ *interop.Context, _ util.Uint160, si *state.Stor err = errors.New("insufficient funds") } return err - } else if sign == -1 && acc.Balance.Cmp(new(big.Int).Neg(amount)) == -1 { + } else if sign == -1 && acc.Balance.CmpAbs(amount) == -1 { return errors.New("insufficient funds") } acc.Balance.Add(&acc.Balance, amount) diff --git a/pkg/core/native/native_neo.go b/pkg/core/native/native_neo.go index eb5291d87..163525080 100644 --- a/pkg/core/native/native_neo.go +++ b/pkg/core/native/native_neo.go @@ -405,7 +405,7 @@ func (n *NEO) increaseBalance(ic *interop.Context, h util.Uint160, si *state.Sto if err != nil { return err } - if (amount.Sign() == -1 && acc.Balance.Cmp(new(big.Int).Neg(amount)) == -1) || + if (amount.Sign() == -1 && acc.Balance.CmpAbs(amount) == -1) || (amount.Sign() == 0 && checkBal != nil && acc.Balance.Cmp(checkBal) == -1) { return errors.New("insufficient funds") }