Is there a way to check Sender's Gas Limit?

If the sender sets too low, I will just accept whatever gas amount that he had set and return immediately without hitting the limit.

I am trying to mitigate Fomo3D type of attack.

2 Answers 2


The gasLimit is a property of the blocks but I interpreted your question as "transaction gas supplied."

If I'm not wrong, you can't go all the way back to the gas supplied for a transaction but you can watch the gas as a transaction runs with msg.gas which will give you the gas remaining, on that step, from the amount that was sent to your function.

What are the attributes of the `msg` object and how can I list them?

On first look, I question using that as you describe. FOMO was built so the last guy wins which was an interesting way to go, to be sure. The gas sent to the winning transaction wasn't important. It was the constitution of the blocks that came after.

The winner crowded out competitive transactions by sending high gas-consumers (what and where wasn't as important as the gas burn) after taking his place in the final position. If that had anything to do with the actual FOMO contract, then I missed that detail. FOMO set up an incentive to DoS competition for a few blocks.

It's not clear that there was anything to be done inside the FOMO contract to prevent that, but rather a careful consideration of the rules of your game.

Hope it helps.


A contract can't access the gas limit in a transaction.

Maybe msg.gas could be used, but gas specific code should be avoided because gas costs can and will change.

For example, the gas cost for SLOAD was raised from 50 to 200 in 2016, and again in 2019 in EIP 1884, with some impacts described in: https://chainsecurity.com/istanbul-hardfork-eips-increasing-gas-costs-and-more/

UNGAS may also be implemented in the future to remove msg.gas.

Related: Is transfer() still safe after the Istanbul update?

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.