Lets say we have a view function which'll use up more than 30m gas and ultimately fail for hitting the ceiling. (out of gas)What if i limited the function to stop if gas is low.
function stuff() public view returns(uint a){
while(a<10000000 && gasleft() > 50000){
a++;
}
}
For now ethereum calculates this function's gas as around 30m and when there's too little left it leaves the loop and doesn't fail.
But i'm wondering if ethereum in future would get smarter and figure out it can just go through this function with 21k gas ?
Is checking gasleft() a self fullfilling prophecy ? is it future proofed ?
PS1: Consider user not entering a manual gaslimit, all done by auto gas estimation
PS2: Correct me if i'm wrong, All my findings are from my own testing. I'm usually wrong :)
PS3: I noticed some ppl doesn't know view or pure functions still use gas so i published this contract to demonstrate.https://goerli.etherscan.io/address/0xb5df66e29157bdac857099a776b2f3a47c57ff10#code
[link] [comments]
You can get bonuses upto $100 FREE BONUS when you:
π° Install these recommended apps:
π² SocialGood - 100% Crypto Back on Everyday Shopping
π² xPortal - The DeFi For The Next Billion
π² CryptoTab Browser - Lightweight, fast, and ready to mine!
π° Register on these recommended exchanges:
π‘ Binanceπ‘ Bitfinexπ‘ Bitmartπ‘ Bittrexπ‘ Bitget
π‘ CoinExπ‘ Crypto.comπ‘ Gate.ioπ‘ Huobiπ‘ Kucoin.
Comments