The FlamingoSwapPairContract.Nep5 contract implements the Transfer() function following the NEP-5 standard.
However, the current implementation has two minor issues which violate the NEP-5 standard.
private static bool Transfer(byte[] from, byte[] to, BigInteger amount, byte[] callscript)
{
//Check parameters
Assert(from.Length == 20 && to.Length == 20, "The parameters from and to SHOULD be 20-byte addresses.");
Assert(amount > 0, "The parameter amount MUST be greater than 0.");
if (!Runtime.CheckWitness(from) && from.AsBigInteger() != callscript.AsBigInteger())
return false;
StorageMap asset = Storage.CurrentContext.CreateMap(BalanceMapKey);
var fromAmount = asset.Get(from).AsBigInteger();
if (fromAmount < amount)
return false;
if (from == to)
return true;
...
}
Transfer() should allow zero amount transfers with corresponding event emitted, but the assertion Assert(amount > 0, "...") forbids this, which violates the NEP-5.
When the from and to addresses are the same, current implementation fails to fire the event but simply return true.
Recommendation
Fix the violations
private static bool Transfer(byte[] from, byte[] to, BigInteger amount, byte[] callscript)
{
//Check parameters
Assert(from.Length == 20 && to.Length == 20, "The parameters from and to SHOULD be 20-byte addresses.");
Assert(amount >= 0, "The parameter amount MUST be greater than 0.");
if (!Runtime.CheckWitness(from) && from.AsBigInteger() != callscript.AsBigInteger())
return false;
StorageMap asset = Storage.CurrentContext.CreateMap(BalanceMapKey);
var fromAmount = asset.Get(from).AsBigInteger();
if (fromAmount < amount)
return false;
if (from == to) {
Transferred(from, to, amount);
return true;
}
...
}
Description
The FlamingoSwapPairContract.Nep5 contract implements the
Transfer()
function following the NEP-5 standard.However, the current implementation has two minor issues which violate the NEP-5 standard.
Transfer()
should allow zero amount transfers with corresponding event emitted, but the assertionAssert(amount > 0, "...")
forbids this, which violates the NEP-5.from
andto
addresses are the same, current implementation fails to fire the event but simply return true.Recommendation
Fix the violations