Skip to content

Create SafeMath32.sol #1484

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

Closed
wants to merge 4 commits into from
Closed

Create SafeMath32.sol #1484

wants to merge 4 commits into from

Conversation

wbt
Copy link

@wbt wbt commented Oct 25, 2018

This PR creates a library that serves the same functions as SafeMath, but for uint32s instead of uint256s. Now, those of us doing math with uint32s can do so safely!
Only variable types, the contract name, and the description on line 5 have changed from SafeMath.sol.

wbt added 4 commits October 25, 2018 17:02
For testing SafeMath32.
Tightly based on SafeMathMock.sol
Based tightly on SafeMath.test.js
@wbt
Copy link
Author

wbt commented Oct 25, 2018

The new tests are the same as the tests being applied to SafeMath. However, the validation tests for the last commit finished before the tests for the one before it. Checking on the Coveralls server UI it looks like the coverage check wasn't run after the tests were added:
coveralls not measuring after last commit

Apologies for not renaming the branch as descriptively as is conventional.

@frangio
Copy link
Contributor

frangio commented Jan 25, 2019

Hi @wbt! Thanks for contributing. Unfortunately we've decided in the past to only support 256 bit arithmetic. Since that is the native word size in the EVM and everything else is emulated by Solidity, we don't see any situation where 32 bit arithmetic should be used.

If you have an example situation where you think 32 bit arithmetic is justified, please let us know!

@frangio frangio closed this Jan 25, 2019
@wbt
Copy link
Author

wbt commented Jan 25, 2019

I use 32-bit unsigned integers quite a bit because they are approximately a quarter of the storage cost when packed in, while still being sufficiently large for practical application purposes. Storage is costly in the EVM!

@frangio
Copy link
Contributor

frangio commented Jan 28, 2019

Do you have some sample code to demonstrate the gas savings? Let's continue the discussion in #1625.

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.

2 participants