1

https://ropsten.etherscan.io/tx/0x8d5b9a6906b9f287c4b09333272f691a75655e470c128b78b3bc4a540c534190
In this transaction, I tried to send 10wei to 0x0000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000001,
.....
0x0000000000000000000000000000000000000009
But the ethes sent to 0x0000000000000000000000000000000000000001 and several other accounts have failed, and the other part has succeeded. I don't know why this is so. This is the source code of the contract.

  function getThisBalance() payable returns(uint, uint){
  for (uint i = 0; i < msg.value; i ++){
      address(i).send(1);
  }
  return (i, msg.value);

}

1

The reason your send is failing for certain addresses (e.g. address(1)) is that this address is actually a contract (even though it doesn't look like it on etherscan.io).

These addresses are pre-compiled contracts (e.g. the ECDSA recovery contract) so take additional gas to send funds to. You can pass additional gas when sending the ETH to work around this, or use a different range of addresses avoiding pre-compiled contracts if the addresses aren't important to you.

  • Precompiled contracts also expect input parameters to be valid if not they will cause an error. – Ismael Jun 20 '18 at 1:27
  • Thank you for your answer. Can you tell me how to specify gas in the internal transaction? – user17314 Jun 20 '18 at 5:49
  • You can use something like: msg.sender.call.gas(2500000).value(amount)() to specify a larger amount of gas. NB - the reason not to do this is it allows the contract to which you are sending funds to re-enter your contract (since it has the gas to do so now). For pre-compiled known contracts this is not necessarily an issue, but is dangerous when sending ETH to unknown contracts. – Adam Dossa Jun 20 '18 at 10:29
0

address.send transfers Ether to the specified account. If that account is a smart contract, it's fallback function is executed.

By default, a smart contract's fallback function is not payable. That means, it will revert when Ether is sent to it. So, if one of your addresses is that of a smart contract, that does not have a payable fallback function, address.send will return false and the ether will not be sent to that smart contract. The transaction, however will continue as your code doens't do anything with the return value of address.send.

Another reason for address.send to fail is that only 2300 gas is sent along with it. A smart contract that has a payable fallback function can only receive Ether by using address.send if the execution of the fallback function does not cost more that 2300 gas. It's possible to emit an event with 2300 gas, but not much more than that.

To send more than 2300 gas to the fallback function, you could use address.call.value([wei])(), which forwards all gas, or address.call.value([wei]).gas([gas])(). address.call returns false if it failed, and true if it succeeded.

However!

address.call is a potential security threat. It could introduce a Re-entrancy vulnerability. This is why using it is discouraged.

  • Thank you for your answer. Can you tell me how to specify gas in the internal transaction? – user17314 Jun 20 '18 at 5:49

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.