addr.transfer() fails, does it use a
throw-style exception? In other words, does a failed
transfer consume all provided gas?
I believe that it won't consume all of the gas provided.
Whilst as per the documentation it will throw:
<address>.transfer(uint256 amount): send given amount of Wei to Address, throws on failure
Since the "REVERT instruction" EIP it looks like not all of the gas is consumed anymore.
To test this, I created some simple contracts - that can be seen on this EthFiddle.
I deployed the contracts using remix and called the
forward function of my
Transfer contract and despite the transaction using Remix's default of 3,000,000 gas the actual gas cost was 29,135:
Debugging the transaction, and looking at the stack, I can see that the reasonably recently added REVERT OPCODE was called:
Which I believe accounts for not all of the gas being consumed.
address.transfer() fails it throws an exception and reverts any state changes.
Edit to clarify my original answer
As per the documentation, when a
.transfer() fails it throws a require-style exception, which will revert any state changes. Require-style exceptions will not consume any gas.