Skip to content

Commit

Permalink
Merge pull request #3191 from nspcc-dev/fix-roundtrip
Browse files Browse the repository at this point in the history
native: prohibit non-zero GAS/NEO roundtrip with zero balance
  • Loading branch information
roman-khimov authored Nov 8, 2023
2 parents c5e284c + b4866bd commit f8d8b03
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/core/native/native_nep17.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ func (c *nep17TokenNative) updateAccBalance(ic *interop.Context, acc util.Uint16
if amount.Sign() < 0 {
return nil, errors.New("insufficient funds")
}
if requiredBalance != nil && requiredBalance.Sign() > 0 {
return nil, errors.New("insufficient funds")
}
if amount.Sign() == 0 {
// it's OK to transfer 0 if the balance is 0, no need to put si to the storage
return nil, nil
Expand Down
16 changes: 16 additions & 0 deletions pkg/core/native/native_test/neo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,22 @@ func TestNEO_TransferZeroWithNonZeroBalance(t *testing.T) {
})
}

// https://github.com/nspcc-dev/neo-go/issues/3190
func TestNEO_TransferNonZeroWithZeroBalance(t *testing.T) {
neoValidatorsInvoker := newNeoValidatorsClient(t)
e := neoValidatorsInvoker.Executor

acc := neoValidatorsInvoker.WithSigners(e.NewAccount(t))
accH := acc.Signers[0].ScriptHash()
h := acc.Invoke(t, false, "transfer", accH, accH, int64(5), nil)
aer := e.CheckHalt(t, h, stackitem.Make(false))
require.Equal(t, 0, len(aer.Events))
// check balance wasn't changed and height was not updated
updatedBalance, updatedHeight := e.Chain.GetGoverningTokenBalance(accH)
require.Equal(t, int64(0), updatedBalance.Int64())
require.Equal(t, uint32(0), updatedHeight)
}

func TestNEO_CalculateBonus(t *testing.T) {
neoCommitteeInvoker := newNeoCommitteeClient(t, 10_0000_0000)
e := neoCommitteeInvoker.Executor
Expand Down

0 comments on commit f8d8b03

Please sign in to comment.