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

MVDFunctionalityProposalManager retireAll method stack too deep. #14

Open
PaoloRollo opened this issue Dec 8, 2020 · 0 comments
Open
Labels
bug Something isn't working

Comments

@PaoloRollo
Copy link
Contributor

Currently the retireAll method inside the MVDFunctionalityProposalContract blocks its compilation by raising a stack too deep error.

This is the current method implementation:

    /** @dev Allows the sender to retire all the tokens used for voting in this proposal.
      * @param proposalId proposal identifier.
     */
    function retireAll(uint256 proposalId) public override duringSurvey(proposalId) {
        require(_proposals[proposalId].getItemProposalWeightFunctionalityAddress != address(0), "");
        IGetItemProposalWeightFunctionality functionality = IGetItemProposalWeightFunctionality(_proposals[proposalId].getItemProposalWeightFunctionalityAddress);
        uint256 total = 0;
        address[] memory collections = _userCollectionAddresses[proposalId][msg.sender];
        for (uint j = 0; j < collections.length; j++) {
            uint256[] memory amounts = new uint256[](_userObjectIds[proposalId][msg.sender][collections[j]].length);
            for (uint256 i = 0; i < _userObjectIds[proposalId][msg.sender][collections[j]].length; i++) {
                require(_accept[proposalId][msg.sender][_userObjectIds[proposalId][msg.sender][collections[j]][i]] + _refuse[proposalId][msg.sender][_userObjectIds[proposalId][msg.sender][collections[j]][i]] > 0, "");
            }
            for (uint256 i = 0; i < _userObjectIds[proposalId][msg.sender][collections[j]].length; i++) {
                uint256 tokenWeight = functionality.getItemProposalWeight(collections[j], _userObjectIds[proposalId][msg.sender][collections[j]][i]);
                if (tokenWeight > 0) {
                    uint256 acpt = _accept[proposalId][msg.sender][_userObjectIds[proposalId][msg.sender][collections[j]][i]];
                    uint256 rfs = _refuse[proposalId][msg.sender][_userObjectIds[proposalId][msg.sender][collections[j]][i]];
                    uint256 wAcpt = acpt / tokenWeight;
                    uint256 wRfs = rfs / tokenWeight;
                    amounts[i] = wAcpt + wRfs;
                    _accept[proposalId][msg.sender][_userObjectIds[proposalId][msg.sender][collections[j]][i]] = 0;
                    _refuse[proposalId][msg.sender][_userObjectIds[proposalId][msg.sender][collections[j]][i]] = 0;
                    _totalAccept[proposalId] -= acpt;
                    _totalRefuse[proposalId] -= rfs;
                    total += (acpt + rfs);
                } else {
                    amounts[i] = 0;
                }
            }
            IEthItemCollection(collections[j]).safeBatchTransferFrom(address(this), msg.sender, amounts, _userObjectIds[proposalId][msg.sender][collections[j]], "");
        }
        emit RetireAll(msg.sender, proposalId, total);
    }

It raises a stack too deep because there are too many nested mappings; a solution could be splitting the function into two retireAllAccept and retireAllRefuse.

@PaoloRollo PaoloRollo added the bug Something isn't working label Dec 8, 2020
@PaoloRollo PaoloRollo self-assigned this Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant