Request and Discusion for a Grant (UBI v2 optimization)

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:

  1. As of 2022-07-03, UBI has consumed 105.1 ETH in gas.

  2. My estimation only covered transfer(...) savings, but the savings should be similar in all the other functions, because only one slot for an UbiAccount is being used.

  3. In the old UBI:

    • transfer to an address without ubi takes 81k gas.
    • transfer to an address with ubi takes 64k gas.
  4. In my UBI:

    • transfer to an address without ubi (should) take 55k gas
    • transfer to an address with ubi takes 40k gas.
  5. Comparing best case with best case, we obtain that this new UBI is 37.5% more efficient than the old one.

  6. 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:

  1. 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.

  1. 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.

  1. 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 another 1 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.

1 Like

A note, I don’t know the cost overhead fUBI causes, but for the gas save estimation I made, it would be more fair to my cause to compare gas cost of transfer, best case, of DemocracyEarth’s UBI + fUBI with my implementation.
I made the comparison with an implementation that does not support streams.

TBH, the ones that are doing this the UBIv2 version, are doing it without any grant, so if any grant is given, I would request the grant to be assigne to me, @donosonaumczuk , @0xaztor which were the main contributors to the development of UBIv2.

Any improvement proposal will be welcomed, but grant distribution needs to be rethought.
We can use this post to actualy request a Grant for all of us.

If you want to take part on the development, please, do so, and we can ask for a retroactive grant once the development is completed and launched.

3 Likes

Who could award this grant? Does UBI (or DemocracyEarth, or something like that) have a treasury for such endeavors? I don’t know much about UBI or it’s ecosystem or funding.
Worst case, we can request a grant from PoH Treasury.

UBI DAO has its own funds, but I still believe the grant should be retroactive.
Once the job is done, deployed and working.

Also, I think there are a couple of problems with your implementation, given that you dont consider the current version, such as the achitecture for delegations (which allows to plug in future delegator iplementations), as well as the upgradeable proxy (which if not done correctly, could break the contract).

You left out most of the work, including considerations, we’ve done throughout the entire year.
I would recommend to ask for a grant once you have studied and discussed UBI in much detail with the developers.

1 Like

Fair. I’ll continue to work on it and I’ll show the whole thing whenever it’s over.

This delegations you’re talking about, are you referring to the permit, nonces, etc? I let that out since I did everything from scratch, but I can implement it.

The upgradeable proxy is the most complex part so I’ll leave it for the end, when I’m certain this is the base architecture I’m going for. I don’t understand well how storage works with the proxy so I need to study it to make the migration.

I’ll also refactor my sUBI implementation to be ERC-721 compliant instead. It’s just a more sensible idea.

1 Like

Awesome, I recommend you to look at the last version of the Delegations architecture,.
Basically if you wanna implement a specific delegation, you should implement the IUBIDelegator interface.

Delegating means delegating part or all of your UBI stream.