Assessment reports>Chateau>Discussion>States not updated

Some states are not updated

Across the codebase, some states are not updated. For example, in StakingPool.sol —

  • In the unstake() function:

function unstake() public NOT_AMERICAN {
    uint[] memory userIssueIndexs = userIssueIndex[msg.sender];

    uint unstakeAmount;
    for (uint i; i < userIssueIndexs.length; i++) {
        uint index = userIssueIndexs[i];
        if (index > indexStar) {
            Issue storage issueInfo = issues[index];
            if (issueInfo.isStaking) {
                unstakeAmount += issueInfo.issueAmount;
+               issueInfo.issueAmount = 0;
                issueInfo.isStaking = false;
            }
        }
    }
  • In the swap() function:

for (uint i = indexEnd; i > indexStar; i--) { 
    Issue storage issueInfo = issues[i];
    if (issueInfo.isStaking) { 
        if (amountB > 0) {
            if (amountB >= issueInfo.issueAmount) {
                uint amountA = (issueInfo.issueAmount * 10000) / rate;
                amountB -= issueInfo.issueAmount; 
                redeemToekn.safeTransfer(issueInfo.user, amountA);
+               issueInfo.issueAmount = 0;
                issueInfo.isStaking = false; 
            } else { 
                uint amountA = (amountB * 10000) / rate;
                redeemToekn.safeTransfer(issueInfo.user, amountA);
                issueInfo.issueAmount -= amountB; 
                amountB = 0;
            }
        }
    }
}
Zellic © 2024Back to top ↑