From 663f10192f6abdb8208fc47368f01f03ebf1af9d Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 16 Mar 2021 12:56:31 +0300 Subject: [PATCH 1/2] core: record transfers even if 'from' balance is 0 Transfer events should still be saved even if balance tracking goes wild. --- pkg/core/blockchain.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 46d448668..07af0b03f 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -945,15 +945,14 @@ func (bc *Blockchain) processNEP5Transfer(cache *dao.Cached, transfer *state.NEP return } bs := balances.Trackers[transfer.Asset] - if bs.Balance == nil { - return - } - bs.Balance.Sub(bs.Balance, transfer.Amount) - if bs.Balance.Sign() > 0 { - bs.LastUpdatedBlock = transfer.Block - balances.Trackers[transfer.Asset] = bs - } else { - delete(balances.Trackers, transfer.Asset) + if bs.Balance != nil { + bs.Balance.Sub(bs.Balance, transfer.Amount) + if bs.Balance.Sign() > 0 { + bs.LastUpdatedBlock = transfer.Block + balances.Trackers[transfer.Asset] = bs + } else { + delete(balances.Trackers, transfer.Asset) + } } transfer.Amount.Neg(transfer.Amount) From 1202494479073f5c27e06bc3ce042ccc003be7a9 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 12 Apr 2021 12:14:33 +0300 Subject: [PATCH 2/2] state: reject too big transfers, fix #1900 --- pkg/core/state/nep5.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/core/state/nep5.go b/pkg/core/state/nep5.go index a87685293..606052c12 100644 --- a/pkg/core/state/nep5.go +++ b/pkg/core/state/nep5.go @@ -188,6 +188,9 @@ func NEP5TransferFromNotification(ne NotificationEvent, txHash util.Uint256, hei if !ok { return nil, errors.New("wrong amount type") } + if len(bs) > amountSize { + return nil, errors.New("integer overflow") + } amount = emit.BytesToInt(bs) } toAddr := parseUint160(to)