0

This crowdfunding contract is far from complete, I'm still in the process of writing the code and testing each individual function. The approach that I have taken with the getRefund() function seems to work perfectly, however, I'm a little concerned about there being potential collisions as I have mapped all the investor's addresses to the amount of ETH sent to the contract. Is it possible for address A and address B to map to the same index within the mapping? If so, wouldn't this mean that if address A were to claim a refund, wouldn't address A also obtain the funds that were sent from address B?

pragma solidity ^0.4.0;

contract Crowdfunding {

    address private owner;

    mapping (address => uint) investors;

    //Constructor
    function Crowdfunding() {
        owner = msg.sender;
    }

    //Modifiers
    modifier investorsOnly {
        if(investors[msg.sender] == 0) throw;
        _;
    }

    //Events
    event PaymentReceived(uint Amount, address From, address To);
    event WithdrawalClaimed(uint Amount, address From);

    //Functions
    function() payable {
        investors[msg.sender] += msg.value;
        PaymentReceived(msg.value, msg.sender, this);
    }

    function withdrawFunds() {
        suicide(owner);
    }

    function getRefund() investorsOnly {
        uint amount = investors[msg.sender];
        investors[msg.sender] = 0;
        msg.sender.transfer(amount);
        WithdrawalClaimed(amount, msg.sender); 
    }
}
0

Is it possible for address A and address B to map to the same index within the mapping?

No, it's not possible because with mapping you define a unique link between the address and the amount contributed. So the refund process should go without troubles. To collide 2 address should have the same private key, and this is almost impossible.

Tip: use revert() instead of throw, that is deprecated.

Also, the fallback function gas cost should be lower than 2300:

Please ensure you test your fallback function thoroughly to ensure the execution cost is less than 2300 gas before deploying a contract.

  • Thank you very much for your help. I have now tested the fallback function and the estimated fee is 42,980 gas. I'm not quite sure how to lower this. Do you have any suggestions? – Zenos Pavlakou Jul 27 '17 at 15:28
  • I'm trying to figure out this too – Paolo Guerra Jul 28 '17 at 10:27
0

From here.

"The way private keys are generated means that there is a "2160 or about 1 in 1,461,501,637,330,902,918,203,684,832,716,283,019,655,932,542,976" of two private keys colliding.As such, to all extents and purposes addresses are unique."

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.