Giter Club home page Giter Club logo

Comments (2)

Amxx avatar Amxx commented on June 13, 2024

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.

CodeSandwich avatar CodeSandwich commented on June 13, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.