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

Use uint128 in everything possible #22

Closed
wants to merge 1 commit into from
Closed

Conversation

3esmit
Copy link

@3esmit 3esmit commented Sep 14, 2023

Fixes #19

Description

Maybe is not the ideal, as it is increasing gas cost for everything due casting from uint256 => uint128, which carry checks on solidity. Maybe if we use unchecked{}?
But then whats the purpose of this?

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Added natspec comments?
  • Ran forge snapshot?
  • Ran pnpm lint?
  • Ran forge test?

Copy link
Collaborator

@0x-r4bbit 0x-r4bbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So given that we're aiming for making this as inexpensive as possible, I wonder if we should really add these changes.

What are we gaining here, besides using less storage?

At the moment it really looks like this is just being more expensive?

@3esmit
Copy link
Author

3esmit commented Sep 15, 2023

We are not using less storage, nor more. This changes add verifications on solidity. If we put a number bigger than an uint128 it will throw when casting.

@0x-r4bbit
Copy link
Collaborator

We are not using less storage,

I can run the storage layout tool over it, but given that we've changed a lot of storage variables from uint256 to uint128, two values now fits into a single slot, where as otherwise every variable would occupy an entire slot.

Am I missing anything?

@3esmit
Copy link
Author

3esmit commented Sep 15, 2023

The storage was already uint128. What you mean is memory?

@0x-r4bbit
Copy link
Collaborator

These two are storage slots:

https://github.com/vacp2p/minime/pull/22/files#diff-89a231d7cc8434098e72bc9cd102408632360d03352b29a2c53d49b9fa34659aL71-R74

But you're right, it's just these two, everything else is not

Copy link
Collaborator

@0x-r4bbit 0x-r4bbit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna let this be your call.
Not sure these changes are an actual improvement. But that's fine by me.

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

Successfully merging this pull request may close these issues.

Difference between calculated and stored uint sizes can lead to overflows
2 participants