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 2 #2

Open
Edward-Lo opened this issue Sep 10, 2020 · 0 comments
Open

Issue 2 #2

Edward-Lo opened this issue Sep 10, 2020 · 0 comments

Comments

@Edward-Lo
Copy link
Collaborator

Description

There is a lack of sanity check in the getuintprofit method of flamingo staking contract, which might lead to unwanted behavior.

getuintprofit is a query function and returns currentUintStackProfit of the corresponding asset.

flamingo-contract-staking/StakingReocrd.cs

else if (method == "getuintprofit")
{
  var assetId = (byte[])args[0];

  var currentTotalStakingAmount = GetCurrentTotalAmount(assetId);
  var currentShareAmount = GetCurrentShareAmount(assetId);
  return currentShareAmount / currentTotalStakingAmount;
}

flamingo-contract-staking/GlobalRecordMethod.cs

private static BigInteger GetCurrentTotalAmount(byte[] assetId)
{
  var Params = new object[] { ExecutionEngine.ExecutingScriptHash };
  BigInteger totalAmount = (BigInteger)((DyncCall)assetId.ToDelegate())("balanceOf", Params);
  return totalAmount;
}

However, it lacks a sanity check for assetId. Users might accidentally pass any script which declared the balanceOf ABI, and leads to unwanted behaviors in the end.

Recommendation

flamingo-contract-staking/StakingReocrd.cs

else if (method == "getuintprofit")
{
  var assetId = (byte[])args[0];
  if (!IsInWhiteList(assetId) || assetId.Length != 20) return 0;
  
  var currentTotalStakingAmount = GetCurrentTotalAmount(assetId);
  var currentShareAmount = GetCurrentShareAmount(assetId);
  return currentShareAmount / currentTotalStakingAmount;
}
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

1 participant