Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas optimization for Ubiquity contracts #895

Closed
0xRizwan opened this issue Feb 12, 2024 · 26 comments
Closed

Gas optimization for Ubiquity contracts #895

0xRizwan opened this issue Feb 12, 2024 · 26 comments

Comments

@0xRizwan
Copy link

Hi,

I have done gas optimization on contracts in development branch.

Link to check the gas optimization changes- development...0xRizwan:ubiquity-dollar-Gas-optimization:development

Total gas saved from current implementation contracts- 13_38_283

cc- @pavlovcik and @molecula451

@0x4007
Copy link
Member

0x4007 commented Feb 12, 2024

How long does something like this take to do?

Also @rndquu @gitcoindev rfc

@rndquu
Copy link
Member

rndquu commented Feb 12, 2024

How long does something like this take to do?

Also @rndquu @gitcoindev rfc

I would put ~4 hours

@molecula451
Copy link
Contributor

i'm likely good with require() i would focus in gas optimizations in edges such as:

  • Minting
  • Deposit
  • Withdraw

Overall user experience but at the same time preserving what we architecturally like in terms of code definition.

Perhaps we would like to upgrade to Erroring Support or not

@0xRizwan
Copy link
Author

How long does something like this take to do?
Also @rndquu @gitcoindev rfc

I would put ~4 hours

Hey,

Thanks for the comment. This would definitely need ~6 hours. The tests also required to be changed. To be noted all tests are passed shared in above link.

@0xRizwan
Copy link
Author

0xRizwan commented Feb 13, 2024

i'm likely good with require() i would focus in gas optimizations in edges such as:

  • Minting
  • Deposit
  • Withdraw

Overall user experience but at the same time preserving what we architecturally like in terms of code definition.

Perhaps we would like to upgrade to Erroring Support or not

custom errors are preferred over require/assert. This definately saves gas with use of custom errors. In case of require, i see the string message length was more than 32 bytes at some instances which means additional 1 slot is required in such case. Instead of using more than 1 slot for just return string message, i would still prefer custom errors. To be noted, custom errors has not been used fully in all contracts, at some places require is kept too.

I believe the contracts is being deployed on Ethereum mainnet. For user experience, i would request to see the possibility of L2 deployment. This definately increases number of users using the protocol due to low fees and the users frequently using functions like Minting, Deposit, Withdraw would incur very very low gas as compared to Ethereum.

For example:
Taking my real life example. On average, I pay 4$ for Ethereum transaction and 0.25$ for Arbitrum transaction.

@molecula451
Copy link
Contributor

custom errors are preferred over require/assert. This definately saves gas with use of custom errors. In case of require, i see the string message length was more than 32 bytes at some instances which means additional 1 slot is required in such case. Instead of using more than 1 slot for just return string message, i would still prefer custom errors. To be noted, custom errors has not been used fully in all contracts, at some places require is kept too.

I'm sure custom errors are better implementation, consider this as a refactor, but changing to custom errors could be considered a refactor, instead of some gas optimization as there are require() working very good tho, feel free to start working on the issue

@0xRizwan
Copy link
Author

/start

This comment was marked as duplicate.

@molecula451
Copy link
Contributor

/help

Copy link

ubiquibot bot commented Feb 13, 2024

Available Commands

Command Description Example
/start Assign yourself to the issue. /start
/stop Unassign yourself from the issue. /stop
/help List all available commands. /help
/query Returns the user's wallet, access, and multiplier information. /query @user
/ask Ask a context aware question. /ask is x or y the best approach?
/multiplier Set the task payout multiplier for a specific contributor, and provide a reason for why. /multiplier @user 0.5 "multiplier
reason"
/labels Set access control, for admins only. /labels @user priority time
price
/authorize Approve a label change, for admins only. /authorize
/wallet Register your wallet address for payments. /wallet ubq.eth

@0x4007
Copy link
Member

0x4007 commented Feb 13, 2024

@0xRizwan Make sure to set your wallet address first. I think that's the unhandled error.

@0xRizwan
Copy link
Author

/wallet 0x9Ea3efa3F1145A46c4eEc34B5a995De570b8050b

Copy link

ubiquibot bot commented Feb 13, 2024

+ Successfully registered wallet address

@0xRizwan
Copy link
Author

/start

Copy link

ubiquibot bot commented Feb 13, 2024

DeadlineWed, Feb 14, 5:01 AM UTC
Registered Wallet 0x9Ea3efa3F1145A46c4eEc34B5a995De570b8050b
Tips:
  • Use /wallet 0x0000...0000 if you want to update your registered payment wallet address.
  • Be sure to open a draft pull request as soon as possible to communicate updates on your progress.
  • Be sure to provide timely updates to us when requested, or you will be automatically unassigned from the task.

@molecula451
Copy link
Contributor

I believe the contracts is being deployed on Ethereum mainnet. For user experience, i would request to see the possibility of L2 deployment. This definately increases number of users using the protocol due to low fees and the users frequently using functions like Minting, Deposit, Withdraw would incur very very low gas as compared to Ethereum.

Hey We are going Mainnet, so consider that do not take in count L2s

@molecula451
Copy link
Contributor

custom erros can also be inside require() that's why the change could be considered a refactor

@0xRizwan
Copy link
Author

Please check PR

Overall gas change from current implementation: 6.6 million which is ~2.3 % change.

Feel free to connect for any clarifications.

@molecula451 molecula451 changed the title Gas optimization for Ubuiquity contracts Gas optimization for Ubiquity contracts Feb 14, 2024
Copy link

ubiquibot bot commented Feb 14, 2024

# These linked pull requests are closed:  <a href="https://github.com/ubiquity/ubiquity-dollar/pull/896">#896</a> 

Copy link

ubiquibot bot commented Feb 14, 2024

! action has an uncaught error

Copy link

ubiquibot bot commented Feb 14, 2024

! action has an uncaught error

@molecula451 molecula451 reopened this Feb 14, 2024
@0x4007
Copy link
Member

0x4007 commented Feb 15, 2024

I'll try salvaging the permits from the logs here.

@0x4007 0x4007 closed this as completed Feb 15, 2024
Copy link

ubiquibot bot commented Feb 15, 2024

+ Evaluating results. Please wait...

@0x4007
Copy link
Member

0x4007 commented Feb 15, 2024

[ 18.3 WXDAI ]

@pavlovcik
Contributions Overview
ViewContributionCountReward
IssueComment33.7
ReviewComment314.6
Conversation Incentives
CommentFormattingRelevanceReward
How long does something like this take to do?

Also @rndquu @git...

1.30.491.3
@0xRizwan Make sure to set your wallet address first. I think th...
1.60.441.6
I'll try debugging the permit flow here. ...
0.80.450.8
> require used with return string message adds more readabilit...
4.4

a:
  count: 1
  score: "1"
  words: 1
code:
  count: 1
  score: "1"
  words: 1
0.754.4
> i think we could perhaps compensate the user for these comment...
4.40.574.4
Yes unfortunately the permit flow is a coin toss right now. I th...
5.8
li:
  count: 1
  score: "1"
  words: 8
0.565.8

[ 29.5 WXDAI ]

@molecula451
Contributions Overview
ViewContributionCountReward
IssueComment418.3
ReviewComment311.2
Conversation Incentives
CommentFormattingRelevanceReward
i'm likely good with `require()` i would focus in gas optimizati...
8.8
li:
  count: 3
  score: "3"
  words: 3
code:
  count: 1
  score: "1"
  words: 1
0.78.8
> custom errors are preferred over require/assert. This definate...
5.4
code:
  count: 1
  score: "1"
  words: 1
0.735.4
> I believe the contracts is being deployed on Ethereum mainnet....
1.40.451.4
custom erros can also be inside `require()` that's why the chang...
2.7
code:
  count: 1
  score: "1"
  words: 1
0.512.7
Please fix the build actions as some are not passing...
10.311
Yeah i think the PR won't make it either as the such refactors s...
7.70.687.7
it looks like it took action on the PR closing but not on the is...
2.50.592.5

[ 21.2 WXDAI ]

@gitcoindev
Contributions Overview
ViewContributionCountReward
ReviewComment121.2
Conversation Incentives
CommentFormattingRelevanceReward
Hi everyone, I am back. I analysed the changes. Now I see where ...
21.2
li:
  count: 3
  score: "3"
  words: 43
0.6121.2

[ 89.8 WXDAI ]

@0xRizwan
Contributions Overview
ViewContributionCountReward
IssueSpecification17.2
IssueComment344.6
ReviewComment238
Conversation Incentives
CommentFormattingRele

@0x4007
Copy link
Member

0x4007 commented Feb 15, 2024

Looks like the qualitative analysis is no longer applying its multiplier. I see on gitcoindev's comment that it clearly is not doing anything: raw score of 21.2 with a relevance of 0.61 should yield 12.932

Looks like I already filed the issue here

@0xRizwan
Copy link
Author

@pavlovcik @molecula451 and team,

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants