Just out of curiosity. Let's say I want to run a contracts function that costs 300k gas and I supply only 150k. It will fail but how. The function will stop during 'work' or whole function won't execute.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.Sign up to join this community
The function will start running, but once the contract runs out of gas, execution will terminate and revert. So all state will revert to previous, as if nothing had happened. Apart from using up the 150k gas.
When you execute transaction the amount of
gasLimit * gasPrice is first deducted from your account. When function execution is done the remaining ether (if execution took less gas then
gasLimit) is refunded to your account.
So the function won't execute.
From ethereum white paper:
The process for the state transition function in this case is as follows:
Check that the transaction is valid and well formed.
Check that the transaction sender has at least 2000 * 0.001 = 2 ether. If they do, then subtract 2 ether from the sender's account.