We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
There is a lack of sanity check in the ClaimFLM method of flamingo staking contract.
ClaimFLM
Staking/flamingo-contract-staking/flamingo-contract-staking/StakingReocrd.cs
public static bool ClaimFLM(byte[] fromAddress, byte[] assetId, byte[] callingScript) { if (!Runtime.CheckWitness(fromAddress)) return false; byte[] key = assetId.Concat(fromAddress); StakingReocrd stakingReocrd = (StakingReocrd)Storage.Get(key).Deserialize(); if (!stakingReocrd.fromAddress.Equals(fromAddress)) { return false; } UpdateStackRecord(assetId, GetCurrentTimeStamp()); BigInteger newProfit = SettleProfit(stakingReocrd.timeStamp, stakingReocrd.amount, assetId); var profitAmount = stakingReocrd.Profit + newProfit; SaveUserStaking(fromAddress, stakingReocrd.amount, stakingReocrd.assetId, Blockchain.GetHeight(), 0, key); if (!MintFLM(fromAddress, profitAmount, callingScript)) { return false; } return true; }
ClaimFLM will try to combine assetId and fromAddress as a key to retrieve the StakingReocrd.
assetId
fromAddress
StakingReocrd
However, it doesn't check whether the record can be successfully retrieved, but tries to deserialize the result directly by calling Deserialize.
Deserialize
public static bool ClaimFLM(byte[] fromAddress, byte[] assetId, byte[] callingScript) { if (!Runtime.CheckWitness(fromAddress)) return false; byte[] key = assetId.Concat(fromAddress); var result = Storage.Get(key); if (result.Length == 0) return false; StakingReocrd stakingReocrd = (StakingReocrd)result.Deserialize(); if (!stakingReocrd.fromAddress.Equals(fromAddress)) { return false; } UpdateStackRecord(assetId, GetCurrentTimeStamp()); BigInteger newProfit = SettleProfit(stakingReocrd.timeStamp, stakingReocrd.amount, assetId); var profitAmount = stakingReocrd.Profit + newProfit; SaveUserStaking(fromAddress, stakingReocrd.amount, stakingReocrd.assetId, Blockchain.GetHeight(), 0, key); if (!MintFLM(fromAddress, profitAmount, callingScript)) { return false; } return true; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Description
There is a lack of sanity check in the
ClaimFLM
method of flamingo staking contract.Staking/flamingo-contract-staking/flamingo-contract-staking/StakingReocrd.cs
ClaimFLM
will try to combineassetId
andfromAddress
as a key to retrieve theStakingReocrd
.However, it doesn't check whether the record can be successfully retrieved, but tries to deserialize the result directly by calling
Deserialize
.Recommendation
Staking/flamingo-contract-staking/flamingo-contract-staking/StakingReocrd.cs
The text was updated successfully, but these errors were encountered: