Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 5 #5

Open
Edward-Lo opened this issue Sep 26, 2020 · 1 comment
Open

Issue 5 #5

Edward-Lo opened this issue Sep 26, 2020 · 1 comment

Comments

@Edward-Lo
Copy link
Collaborator

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.

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;
    ...
}
  1. Transfer() should allow zero amount transfers with corresponding event emitted, but the assertion Assert(amount > 0, "...") forbids this, which violates the NEP-5.
  2. 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;
    }
    ...
}
@Ashuaidehao
Copy link
Contributor

Update Assert(amount >= 0, "The parameter amount MUST be greater than 0."); .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants