Coder Social home page Coder Social logo

optimizations about contracts HOT 7 CLOSED

malik672 avatar malik672 commented on May 27, 2024
optimizations

from contracts.

Comments (7)

malik672 avatar malik672 commented on May 27, 2024

always use pre-increment method when incrementing one of your code went 443 less in gas for one of this reason and its a loop and you don't have to initialize to zero by default variables are already zero when created that cost an additional 8 in gas

from contracts.

malik672 avatar malik672 commented on May 27, 2024

this part here is weird, i think the hardcoding the function selector is better, then using bit manbipulation to add the params to the end of the selector saves more gas and tbh i think this is better using yul
(bool success_, bytes memory data_) = _currency.call( abi.encodeWithSelector(IERC20.transferFrom.selector, _from, _to, _amount) );

from contracts.

malik672 avatar malik672 commented on May 27, 2024
if (_amount == 0) {
            success = true;
            return success;
        }

this tbh is so bad you don't need to do success = true, return success you can just return 1, thats still true

from contracts.

malik672 avatar malik672 commented on May 27, 2024
 `return string(abi.encodePacked(batchUri, "0"));`

you could have done this yourself, if you do not need the same string in the function again you should just encode this using the length and bit manipulation instead of abi.encodePacked which actually creates a clone in memory then encodes it

from contracts.

malik672 avatar malik672 commented on May 27, 2024

the best way to solve this issue, just write in yul, i can't go through the whole codebase

from contracts.

nkrishang avatar nkrishang commented on May 27, 2024

Hey @malik672 👋🏽 appreciate the suggestions. We're starting Solidity optimization work; want to make a PR containing your suggestions? That'd be super helpful.

Regarding custom errors -- we've attempted to introduce them to the codebase before. We'll introduce them to the codebase once we build decent error message rendering for them in our SDK layer.

from contracts.

malik672 avatar malik672 commented on May 27, 2024

thank you, will love to

from 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.