A few days I started thinking about gas optimizations for UBI. Yesterday I made a proof of concept implementation. Current UBI (without streams!) appears to cost 64k to transfer.
The version I built costs 40k gas to transfer, and it features “streams” (these streams are different from the ones developed by DemocracyEarth). These streams are represented by a token sUBI which is ERC-20 compatible (to show the balance in wallets).
There are still a few things that would be interesting:
- make it work for proxy pattern, such as the current one.
- make it work through a migration such as the one described here.
- make sUBI transfer work as you would expect with an ERC-20
I don’t have a lot of time to devote to this, but I could build something more elaborated if I had a grant.
Let me convey the value of this work:
- proved it’s possible to have cheaper UBI transfers, which is vital for a low value high volume token. It could even prove vital in sidechains in the future.
- this lower cost is there despite also dealing with a delegated stream implementation. Old UBI did not have this feature. It is very likely that the DemocracyEarth implementation of flows/streams would have increased gas consumption.
Let’s make an attempt at calculating the value:
-
As of 2022-07-03, UBI has consumed 105.1 ETH in gas.
-
My estimation only covered
transfer(...)
savings, but the savings should be similar in all the other functions, because only one slot for anUbiAccount
is being used. -
In the old UBI:
-
transfer
to an address without ubi takes 81k gas. -
transfer
to an address with ubi takes 64k gas.
-
-
In my UBI:
-
transfer
to an address without ubi (should) take 55k gas -
transfer
to an address with ubi takes 40k gas.
-
-
Comparing best case with best case, we obtain that this new UBI is 37.5% more efficient than the old one.
-
Assuming that the savings are of similar size for the other transactions, a vague estimate claims that the following ETH amount would have been saved:
105.1 ETH * 0.375 = 39.4125 ETH
Of course, this makes the assumption that, if my version was migrated, a similar amount of activity would take place and all that ETH would be saved in comparison, which is not necessarily true. It’s very likely that in the short term UBI takes place in a sidechain or a L2.
As there are plans to deploy new UBI in Mainnet, at least for a while, we can compute a heuristical gas save:
- Let’s say that all the Mainnet usage that will take place, will be 30% of what already took place. Then, the saving is:
39.4125 ETH * 0.3 = 11.82375 ETH
This 30% estimate was made taking into account that the optimization also incentivizes higher usage. Even arbitrage bots in Uniswap will benefit from the save.
- If the dev that made this optimization is entitled to a chunk of this save (say, 20%):
11.82375 * 0.2 = 2.36475 ETH
Note on why this entitlement makes economical sense. If there is precedence on devs finding gas optimizations, receiving a percentage of the expected saving, then you incentivize these discoveries, and especially, you incentivize the finding of big gas saves.
- And, say the dev gets some base amount, in the concept of efforts, bringing the concept “into existence”, that can lead to core devs to take it into account, creating good marketing and activity, etc. Think, Hackathon bounties. I think that
1 ETH
in this concept is good enough for the scale of my contribution. Hackathons usually have more generous bounties, but this was an unsolicited contribution, so I don’t want to cross the line on what a reasonable compensation is.
My current progress took about 1 night of programming, and 2 days of figuring out and writing ideas.
If I were to continue work on it, for the extent of the work I would have to do (learn about proxy pattern, implement it, solve the seamless migration issue and solve all edge cases), it would be a quite advanced endeavor so I would request another1 ETH
for it, but, it depends on the type of work I would do.
So, adding the base amount and the gas save amount, I suggest and request this grant amount, for current work done + wrapping it up properly:
4.36475 ETH
Mainly, I just want to create a conversation on whether this grant is worth it or not. You can think of it as a retro grant + some future job to integrate it with proxy, etc. Please discuss if you think the amount proposed is fair, if there should be a grant at all, etc. (Or, if you think it’s too low, feel free to express yourself! To be fair, I think it’s kinda low, but I’m testing the waters)
On another note, this grant is not about me in particular, but about creating precedence on “unsolicited, valuable contributions will be rewarded retroactively”, which is what you want and more especially for a project like this.