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;

    function Crowdfunding() {
        owner = msg.sender;

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

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

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

    function withdrawFunds() {

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

2 Answers 2


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? Commented Jul 27, 2017 at 15:28
  • I'm trying to figure out this too Commented Jul 28, 2017 at 10:27

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 and acknowledge you have read our privacy policy.

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