MetaMask: Enhanced Gas UI - Jyoti Puri (@jyopur) @ETHDubaiConf
ETHDubai 2022 · 31 Mar 2022 · 22:45
Jyoti Puri explains Ethereum’s gas mechanism and presents MetaMask interface changes designed to make gas fees easier to understand.
Speakers
Topics
From ETHDubai 2022, hosted by DeFi Dubai.
Transcript
hey hi everyone yeah i know everyone is tired of the long day of talks but yeah the topic i'm going to talk about is really interesting i'm going to to be talking about the enhanced gas uis in metamask about about me i'm jyoti i'm based out of new delhi and i'm a senior senior developer with medamast extension team and i have been part of the project to improve our gas uis now gas or networks is is one of the most interesting and complicated topic and they're important they're important because they're a cost for our users and they are complicated because gases are highly unpredictable they are volatile there are spikes and slows and as a
wallet it's a challenge for us to represent gas in a way which is least confusing for the users so we need to ensure that our users transaction are not stuck waiting for block like they have sufficient gas to find place on a block and at the same time we need to ensure that our users are not overpaying for gas now during the course of this transaction in next 20 minutes i'll take you through what is ethereum gas as it might be a new topic for some of you we'll see how gas pricing in ethereum was done traditionally then we'll like we'll look at eip1559 and how that changed the gas pricing mechanism in ethereum and what metamask has done to adopt eip155
then we'll see how what were our learnings from our initial implementation of erp-1559 and how we have improvised upon that now to begin with what is gas and ethereum so gas and ethereum is is a kind of like analogy for fuels for fuel for your car so you need fuel to run your car and in the same way you need gas in ethereum network to run your transaction so on it gas is a way of allocating expensive resources over the network to run your transaction you need these resources on ethereum so as you can see
in the diagram over here so every small network resource or any computational resource on ethereum has a cost the cost is calculated in terms of gas so gas is a way of resource allocation in ethereum and since its implementation in ethereum a lot of other projects have started using gas as a mechanism of resource allocation during the course of presentation i am going to be using the term gas fee and transaction we sort of interchangeably so yeah don't get confused with that also an important point yeah a couple of people also came over to the booth to us and and they were asking like when is madamask releasing zero gas transaction so metamask is not not who charges the
gan this gas so metamask is just a wallet we take your gas inputs we send it over to the network so it's a network that gives you these computational resources and it's the network that is charging this gas for your transaction so metamask at least for 101 transactions is not charging anything yeah so how would you calculate the total amount of gas your transaction is going to need so it's similar it's like and again an analogy to the fuel situation so the unit of gas your transaction need multiply multiplied by price per unit of gas so consider like how much money you're going to spend to refuel your vehicle so that will be the number of
liters of fuel that you will take multiplied by the price of the fuel so so the number of unit of gas your transaction will need depending on the complexity of the contract and the size of the contract that multiply multiplied by grass price will give you your total spending on gas for your transaction now the unit of gas the transaction will need is going to be constant so the magic lies with the gas pricing in ethereum gas pricing traditionally was done using an auction-based mechanism so users in the transaction will specify their gas free bid or what they call they used to call as gas price
the miners will will choose the transaction will with the highest gas price and they'll mine it now this looks very simplified that your total expenditure on gas will be the units of gas which we usually specify as gas limit on the ui multiplied by gas price and traditionally the block size was fixed to 15 million gas now this mechanism is very simple right there's one variable which is gas price the miner will choose the transaction the highest gas price all of the gas fee will go to the miner so simple as that but the truck but the mechanism has drawback in this mechanism the gas pricing is totally controlled by the miner so the
network has no control over gas pricing and the second drop back is that the bots competing for gas on the network can result in gas bicyclist surging and there are spikes sharp spikes and everyone else on the network at that point has to suffer and pay more for the gas so users were not happy with this auction mechanism they were complaining with the nature of auction it was highly unpredictable it was hard for users to know what will be the gas price in the next block and what they need to pay to be on the next block ethereum overhaul their gas mechanism with eip-1459 in london upgrade last year uh it was in august uh
2021 erp one for in erp 1559 this auction mechanism and gas price was replaced by these two variable which you call as a base fee and priority fee and the block size was also made variable it was two times of what it was previously so previously it was 15 million gas and now it's 30 million gas now i'll tell you what is base fee and priority fee so yeah i hope everyone is with me so far it's making sense okay so base fee is the minimum price per unit of gas you need to pay to for your transaction to be included on a block
base fee is decided by the network so it's not the miner deciding it it's a network who decides the base fee it's for ethereum it's always an eth and the base fee part is burnt out so there are very important significant consequences of these like the network finally has a control over gas pricing and and this also makes eid a deflationary a deflationary asset and and a big advantage is base fee is highly predictable since it's a network who decides the base fee and and there is a clear so if if the block is like more than 50 occupied the network will increase the base fee by 12.5 percent if
the block is less than 50 occupied the network will decrease the base fee by twelve point five percent so that was base fee is highly predictable so if we see like here you can see like whenever when the block size was more than 50 percent the network in the in the next block so so the blocks so the gas fee for a block will depend on the block previous to it so if the block previous previous block was more than 50 occupied the net will increase and so an increase cannot just go on infinitely so at some point the base increase will stop it will start decreasing and it will eventually reach an equilibrium now the second variable n1559
is priority fee priority fee or what we call as minor tip is a way to incentivize the miner and uh priority fee is your tool if you if you if you are um looking forward to participating in the gas war so if you are running a time critical transaction you are participating in an nft drop augmenting or the market is highly volatile and you need to ensure that your transaction is executed really fast add a high priority fee to it so miner will be happy to run your transaction so now in so casper you know interview priority fee is is a bit similar to gas price
p1559 but one five nine five nine has introduced one more variable which is base fee and it has improvised the overall gas pricing mechanism so now gas pricing for your transaction will be unit of gas again represented as gas limit on the ui uh into base fee plus priority fee so if you look at the scenario like pre 1559 with auction based mechanism there was a fee which is going completely to the miner now in erp fund 559 we have base fee which is burnt out and we have miners tip which goes to the miner since it was in since
eip1559 was introduced in august last year metamask was amongst the very first browsers to add support for it so if you are creating a type 2 transaction which is a transaction that supports 1559 on a network which is supporting five nine you will see this transaction confirmation screen in manamas wherein you can see the max fee specified and you can confirm your transaction it will use the default guess estimates suggested by metamask or if you are an advanced user you can click on the edit link it will open the advanced gas v model where you can select one of our predefined estimate low medium and high or if you are an even more advanced user
you can provide your custom estimates for max free priority fee and gas limit so by default metamask will suggest you the medium estimates now there are a couple of like terminology here which which is like which is always confusing so i'll take a minute to explain that so what is gas limit gas limit is the maximum amount of gas i authorize for consumption for my transaction so suppose my dr i specify the gas limit as 5000 now my transaction you needs only 3 000 so the network will use only 3000 it will not use 5000 but
suppose i specified the grass fee as 1000 but my transaction needed 3 000 so it will run out of gas whatever gas is consumed will be lost and my transaction will not be executed so always specify a gas limit like a bit more than what you think your transaction is going to need second base fee basically as we see as you saw already is the minimum price per unit of gas which is specified by the network and it's ultimately burnt out priority free prodify is this is in theory optional but yeah practically um probably if you have two ways like almost always needed to run your transaction uh priority is um again price per unit of gas it is paid to the miner it is
decided by the user then we have this field called max fee per gas which is uh which is a very confusing value so uh max v per gas as priority fee uh plus maximum amount which you are willing to pay for base fee so so the thing is base fee can be changing so i'm creating my transaction and the base fee on the network might be say 50 way but by the time that my transaction is executed the base view on the network might have got up to 75 grain so if i specify just a base fee or 50 gray and i and i send my transaction uh but and when it's executing the base fee has gone up to 75 great what will happen is my transaction will be stuck
it will be waiting for base fee to come down to 50 go and then it will be executed so what i can do is i can specify max fee per gas which you specify in metamask so that is maximum what i'm willing to pay so i can in my transaction i can specify max we per gas as 100 and priority fee as say 10 so what it will do is um 10 goe will go in parity fee and rest of 90 goe is what i'm authorizing the network to use for my transaction so actually the network might use only 50 gray it might use 75 way and the rest will be refunded back to me but if it's less than that my transaction will wait for the gas on the network to come down
so yeah just just to give you an example so suppose in my transaction i specify max fee per gas as hundred um my spending on priority fee is 20 and base fee is 80. so in all 20 plus 80 is 100 and my transaction has sufficient gas the transaction will be successful now suppose i specify max fee per gas as 120 then the priority fee part is 20 the the base fee when my transaction is executed on the network is 80. so in all i need 100 query so 20go will be so the transaction will go successful and 20 will be refunded back to me now suppose i specify mxp fee per gas as 80. now priority fee is 20 base fee at the time
of transaction execution is 80. so in all i need 100 way of gas but i specified only 80 so my transaction will be stuck it will be waiting for gas fee on the network to come down to 60 and then only the transaction can be executed so yeah i hope this max feeper gas is clear yeah it's it's complete it's confusing now ever since we introduced eip1559 we have been collecting data on the on the network we uh we have been looking at gas behaviors on the network after 1459 we have been collecting user
feedbacks and and we had some very interesting observations so uh it is expected that with eip155 the gas spikes will go down but we found that the spikes were still there user psychology on the network has a huge influence on gas pricing and and there are actually multiple factors but they're highly unpredictable and in front of the gas packs were there and typically our users were falling into three categories so there's a category of set and weight users they don't want to pay high for gas they're happy to skip the sky spikes but they their transactions are not time critical they are happy to wait and make and don't overpay
then there's a second category of users for whom gas is not a concern like they're happy to pay whatever it takes but the transactions are time critical and they want it to be executed really fast and then there's a third category of normal user they'll just go with what is the market trend at the point so we have work towards reducing the complexity of our gas uis we designed and technically implemented controls to reduce user confusion in metamouse we call it eip1559v2 here's here's a little video we've updated the gas ui event to make it more accurate and easier to use first we've changed the priority
selections to load market and aggressive to reflect improved market-based gas-free estimations especially in response to volatile conditions next you can now yeah so as you all just saw we have introduced new three friendlier level of estimates which are called as low market and aggressive so our new low they are really low so if if you want to skip the
spike you're you're happy to wait for gases to slow gas price to come down on the network go with our low estimate if you want to go with the current market trends go with our market estimate and uh if if you're running a time critical transaction you you want to win the gas war your transaction is critical go with the aggressive estimate it will set your max fee and priority fee to really high and it will ensure you it will your chances of winning the gas were as high with that estimate so if uh you create a transaction now in metamask on the transaction confirmation screen you'll see that market estimate by default so whatever is the current um gas
field level in the market it will show you that by default here you can click this market link and open the added gas free model where you can select one of our predefined values of low market and aggressive and you can select either either of these now malamask has done a lot of very good job in deriving these estimates we look back on the blockchain we look on the gas trends on the blockchain we collect data from recent blocks in the blockchain and we run our algorithms over that data to derive these estimates being one of the highest used wallets it's it's very important that we come up with the right estimates because if we are estimating on to the lower side that will mean a lot of transaction on the network will be stuck waiting for
gas prices to come down and if we are estimating on an upper side that will mean the gas pricing on the network as a whole will increase so yeah being being the highest use wallet it's our responsibility to ensure that our estimates are good and we've done a good job at them like a lot of projects use our estimates as benchmark also on this added gas fee model at the bottom we show you the current network status so you can make a more informed decision at selecting the predefined estimates you can see the current value of base fee priority fee on the model and how is the network currently behaving so whether it's stable or it's slow or it's high so you can accordingly
decide the gas we estimate that will be appropriate for you also across on our gas ui we have added informative tooltips they'll show you the breakdown of gas price that you're paying and they'll give you more context of what a value is and they're especially useful for new users we have also changed the advanced gas controls which allow you to set custom values for gas so the new controls not only allow users to set custom value for gas but they also allow you to save these values as default for you so um so you can save this value as default so if you if you're running a time critical
transaction you want to uh execute it really fast you can see save these custom values as default come create a transaction it will it's going to use these defaults your default gas settings and you can quickly confirm or if you want to edit these custom values that will be a single click so um if you have these well defaults set and you create a transaction this is what you're going to see in com confirm transaction page it has used it will use these advanced settings for you you can click that advanced link and select one of the predefined gas estimates low medium and low market and aggressive or you can click the edit link the edit link will take you to the
advanced gas v model where we allow you to enter custom value for gas so you can set a custom value for max fee which is like the maximum amount you're willing to pay for the transaction you can specify custom value of priority fee which you're happy to pay to the miner and your gas limit also in this model we show you the current network values so we show what is currently the base fee and priority fee over the network what has been the range in last 12 hours so you can make a more informed decision also here we allow you to set these values as default for yourself so whenever you create a transaction in metamask it will straight away use these
defaults the new gas ui has been released last month as of version 10.10.0 it's it's still in beta so you can go to settings experimental and enable it and use it the advanced gas ui on mobile side is still under development yeah uh yeah since we've released eip159 we too we continue to collect user data we continue to see the gas trends over network and um yeah we we continue our work on improvising the gas ui with the beacon chain merger we expect more changes in the way gas
works on network not in terms of like the mechanism it's going to be erp-159 but the user psychology is going to change the network trends are going to change and for us improving the gas ui is a continuous effort so we've already started thinking of ap150n and v3 which will improvise these uis further yes so during the course of the transaction we looked at uh what is gas pricing and what has changed with 1.1559 and we also saw how madamask has adopted one five five nine what we learned from it and what changes we have done to our gas ui we look forward to ensure that we provide great user experience and
accurate estimates to our users now we have time for any questions you