Comments (2)
Thank you @CodeSandwich for this idea.
Backward compatibility is a must for us (because of the upgradeable version). Its good that you approach provides that feature! This limitation of balances to 2**255-1 is an issue though. We will want to avoid silent errors that may arrive if balances overflow into the mask. That will have to be checked ... and checks add gas cost for everyone ...
I'm curious about the gas cost increase from loading and applying the mask. There is a minority cases where that indeed will save cost, but there is also a majority of cases where that will slightly increasse the costs as well.
I'll try to find banwidth to research that
from openzeppelin-contracts.
I'm curious about the gas cost increase from loading and applying the mask. There is a minority cases where that indeed will save cost, but there is also a majority of cases where that will slightly increasse the costs as well.
I don't think that you should be worried about the gas cost and savings balance. The mask is a constant, so it's loaded by pushing a value to the stack, with the binary operation it will probably cost less than 10 gas in total. The savings on the other hand is 17,100 gas when the storage slot doesn't need to be set from 0
to non-0
. This isn't an uncommon case for ERC-20 to drain a balance or an approval to zero, and then make it non-zero again.
This limitation of balances to 2**255-1 is an issue though. We will want to avoid silent errors that may arrive if balances overflow into the mask. That will have to be checked ... and checks add gas cost for everyone ...
I agree that this is an issue, and it may affect the consumers of OZ. I don't think that gas usage is a problem though, at least not on the OZ level. The only place where a new check is needed is in _update
, where _totalSupply += value;
is performed. The compiler already catches values larger than 2^256-1
, but now we would need to catch values larger than 2^255-1
. The nice side effect is that we would start emitting an explicit error when somebody mints too much, instead of the cryptic overflow panic. (It may be worth implementing regardless of this gas improvement)
Thanks for looking into it!
from openzeppelin-contracts.
Related Issues (20)
- Mark AccessManagerUpgradeable abstract or implement initializer function HOT 1
- Fix API documentation broken links in the doc-site
- Make `_moveDelegateVotes` internal in Votes.sol HOT 1
- Request to Add Upgradable Interfaces in contracts/interfaces Directory of the OpenZeppelin Contracts Upgradeable Repository HOT 2
- Semi abstracted nonce support
- Low level call library HOT 3
- UUPSUpgradeable is not ERC1882 (draft) compatible, but rather only ERC1967 compatible. HOT 2
- ERC1967Utils and/or UUPSUpgradeable should enforce that only ADMIN is allowed to upgrade the implementation HOT 1
- I Can't verified contract in Coredao HOT 1
- `ERC1155`: reorder of `KeyType`s in `_balances` HOT 3
- Meta: FAQ
- Feature Request: removeAt(index) in EnumerableSet
- LUSD on PulseChain Minting Function HOT 1
- Loop gas optimisation HOT 1
- Weird Error in Openzeppelin AI Wiz HOT 1
- Use crate.io/typos to repalce CodeSpell for CI typo check
- Agency contract optimization HOT 3
- Create2 doesn't bubble up returndata on revert HOT 1
- Propose Function is missing Optional Parameters
- Procedurally generate packing libraries
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openzeppelin-contracts.