Ethernaut Fallback Level fails with "Out of Gas" while making a transaction

When I trying to send a value to the exam contract through contract.sendTransaction. It will fail with an error of “Out of gas”.

Please refer to the transaction address

https://ropsten.etherscan.io/tx/0xfac0eb77fbe6ce2ef3492e39dfeeb9d0bb233a1bbd2ba831e39dc823022b1ce4

to see the detail.

Theoretically, this approach should be a valid transaction and would be accepted, no matter if this is the answer to this exam or not.

2 Likes

Hi @ZixuZhao

For Ethernaut Fallback level it looks like you sent 1 wei to the Fallback contract with 21,000 gas limit
await sendTransaction({from: player, to: instance, value:1})

The transaction failed with out of gas. Etherscan

From https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function
Like any function, the fallback function can execute complex operations as long as there is enough gas passed on to it.

You need to send the transaction to the fallback function with a higher gas limit. Try 100,000 as 21.000 is only enough to transfer Ether.

https://metamask.zendesk.com/hc/en-us/articles/360015488771-How-to-Adjust-Gas-Price-and-Gas-Limit-

If you send await sendTransaction({from: player, to: instance, value:1}) with 100,000 gas limit this will still fail, but because it was reverted rather than out of gas.

This reverts due to the require in the fallback function, it checks that you have sent more than 0 Ether and your contributions are greater than 0.

  function() payable public {
    require(msg.value > 0 && contributions[msg.sender] > 0);
    owner = msg.sender;
  }

Whilst you sent more than 0 Ether your contributions are 0.

You can check your contributions using fromWei(await contract.getContribution())

You can call the contribute function with 0.001 Ether await contract.contribute({value: toWei(0.001)})
Please note, this value of Ether will fail due to the require require(msg.value < 0.001 ether);
You only need to edit the gas limit for sendTransaction.

To check your progress:
Get owner: await contract.owner()
Get balance of contract: await getBalance(instance)

I won't give the solution away but there are a number of community solutions if you get stuck on a level, or feel free to ask further questions in the forum.

5 Likes

Thanks for the hint. Now I find the real problem is the gas limit.

2 Likes