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

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

Issue 8 #8

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 ClaimFLM method of flamingo staking contract.

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.

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

    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;
    }        
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