7

Trying to call sendFundsToFriend() method on the testnet contract https://testnet.etherscan.io/address/0xce8efd03766a309af57ddeb9c79f3e7cd23da0df (contract code at https://gist.github.com/anonymous/5bdc3d9032a8b3cb5cba7c7625afa4d7 ) I got:

Warning! Error encountered during contract execution [Out of gas]

The tx result says:

Result: {
  "blockHash": "0x585ca866c5143090c7a82443269d55658a176a018b1ad90827ec70adc1ff66c8",
  "blockNumber": 465927,
  "contractAddress": null,
  "cumulativeGasUsed": 508930,
  "from": "0xe5f68950d479fab12797dabbe5a4b0d88ec7a722",
  "gasUsed": 58787,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "root": "0x1289d7517d81fa8c4894c0cd97fd200ec4e9f0fecebba586435daca8e4e8f9ec",
  "to": "0xce8efd03766a309af57ddeb9c79f3e7cd23da0df",
  "transactionHash": "0x703d7657c093557d1cd42dfeb7b8d0d3b74e413d22e8009b26d7ac966c85d048",
  "transactionIndex": 3
}
Transaction cost: 58787 gas.

enter image description here

When sending the tx, Transaction gas limit is set to 3000000, the default browser-solidity value.

If tx cost is 58787 gas and the limit is 3000000, why the out of gas error? Any idea? Thx!

P.S.: Tried a similar tx from a geth node instead of using metamask+browser-solidity and it worked ok:

https://testnet.etherscan.io/tx/0x56465b6594769578d9223ca902757780600dd2628074aedcf9635fb590b75bfa

So, I am doing something wrong with browser-solidity when calling the contract method, or might be some kind of bug in this environment...

3 Answers3

4

My theory, looking at the transactions of the deployed, is that the failed transactions were to a non-existent address (zero nonce, zero ETH before), and the successful ones were to an existent address (apparently had transactions in the past and ETH already). The former would consume more gas, pushing it beyond the normal gas limit.

The way to test this would be to use metamask+browser-solidity to send to an address that already had ETH. If it fails, then it's not the case. If it doesn't fail, then this is probably what happened.

It may still be a bug in metamask, as it miscalculated how much gas to provide.

EDIT:

I may have found the answer.

Compare a successful geth with an unsuccessful metamask (I presume) shows that the raw transactions are actually different. I suspect whichever client sent the unsuccessful transaction is formatting fields differently, or just buggily.

At this point I'd file a bug with metamask. It's beyond my own ability to debug.

Matthew Schmidt
  • 7,290
  • 1
  • 24
  • 35
  • Unfortunately, it doesn't work this way either: https://testnet.etherscan.io/tx/0x133489c66841cdc9107ac0049687193940f1d8727c267ee5f60911077fbdbf04 In this case, destination address is https://testnet.etherscan.io/address/0xa7e3c7c227c72a60e5a2f9912448fb1c21078769 having several previous txs and a not null balance. This same tx using geth node works ok from a geth node => https://testnet.etherscan.io/tx/0xc719dbf19d57eca5bc9d2ff88fdc9e6918bf2bab4b6b585c1dcb3fe8ece97cb4 – Juan Ignacio Pérez Sacristán Feb 07 '17 at 00:30
  • 1
    Looking closely, it seems that metamask sends exactly enough gas, whereas geth sends extra gas. I'm not sure why it would break if it has just enough--there's a small number of obscure possibilities. (I don't think it's a refund issue, since there's no storage deletion or selfdestructs.) – Matthew Schmidt Feb 07 '17 at 14:49
  • gas sent by metamask:

    33787 on https://testnet.etherscan.io/tx/0x133489c66841cdc9107ac0049687193940f1d8727c267ee5f60911077fbdbf04 58787 on https://testnet.etherscan.io/tx/0x703d7657c093557d1cd42dfeb7b8d0d3b74e413d22e8009b26d7ac966c85d048 and https://testnet.etherscan.io/tx/0x5dde4e0536756b380b34a6fed79bda50bbe274c25b07ac1812f0d816917b9fbd

    while geth is sending 1000000 but spending just 23263 => https://testnet.etherscan.io/tx/0xe925db662523e74f587b0eb7107c1823da213b1bedfb1279ac3a7fb4dbcd80b5

    – Juan Ignacio Pérez Sacristán Feb 07 '17 at 17:17
  • 1
    I still can't think of it being anything but not having quite enough gas, since the transactions are identical otherwise. What client sent it shouldn't matter, as it's miners that execute it. – Matthew Schmidt Feb 07 '17 at 20:06
  • 1
    Or not!? See my latest edit. – Matthew Schmidt Feb 07 '17 at 20:25
  • Thanks Matthew. A bug with metamask is my hypothesis too. – Juan Ignacio Pérez Sacristán Feb 08 '17 at 08:58
4

At first I thought maybe we were mis-calculating gas somehow and failing transactions, since most of the failed txs have very low gas, but actually sometimes nearly identical transactions seemed to succeed with lower gas, like this pair: https://testnet.etherscan.io/tx/0x5dde4e0536756b380b34a6fed79bda50bbe274c25b07ac1812f0d816917b9fbd https://testnet.etherscan.io/tx/0xd2f0047ee8d6ed27a8435352c809a95484e9c3c0d63a2f672a32dd9a4243e90c

One thing I notice, is that these two are actually different contracts, so I'm not sure which one you posted the source code of.

It's also worth noting that you're using a few patterns for sending that are not recommended in the Solidity docs: https://solidity.readthedocs.io/en/develop/security-considerations.html?highlight=send#sending-and-receiving-ether

I do notice that some of the failed transactions are to contracts, and those are some of the more dangerous times to use the send function, since those contracts could burn up the gas.

Sorry, spent a while on this, not sure I found it.

DanF
  • 2,626
  • 10
  • 19
1

I was facing same issue with Remix + Ganache, I switched to other Ethereum Test Net and issue didnt poped up. Try with some other test-net.