0

For some reason my function keeps throwing at 2nd line, where I'm declaring an uint256 named depositedContribution, I have no idea why and I've tried to debug it for hours with no results, what could be the problem with that particular line?

function withdraw() external stateRequired(State.OPEN) {
            require(contributorData[address(msg.sender)].contribution > 0);

            uint256 depositedContribution = contributorData[address(msg.sender)].contribution.add(contributorData[address(msg.sender)].contributionFee);

            fees = fees.sub(contributorData[address(msg.sender)].contributionFee);
            size = size.sub(depositedContribution);

            contributions--;

            msg.sender.transfer(depositedContribution);

            contributorData[address(msg.sender)].contributionFee = 0;
            contributorData[address(msg.sender)].contribution = 0;
            contributorData[address(msg.sender)].contributed = false;

            emit ContributionWithdrawn(msg.sender, this, depositedContribution);
        }
0

It looks like you are using the SafeMath library. The add function contains a assert statement, which reverts the transaction when an overflow happens.

You should check the values of contributorData[address(msg.sender)].contribution and contributorData[address(msg.sender)].contributionFee and find out if the total of those values is bigger than 2^256-1, which is the largest value a uint can contain

  • That's not the issue – NowsyMe Jun 26 '18 at 10:59
  • can a struct be too big? – NowsyMe Jun 27 '18 at 18:34
0

1) I do not see any reason to cast msg.sender to “address”. Use it directly.

2) Check if your safemath has “add” or “sum”

3) make a run using ‘+’ instead of ‘add’ in order to understand if you have overflow or safemath errors

Hope this can help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.