solmate icon indicating copy to clipboard operation
solmate copied to clipboard

use custom error combined with bytes32 instead of using require with strings

Open malik672 opened this issue 1 year ago • 0 comments

contract test {//deployment cost: 109638 in gas cost
    error notEqual(bytes32);
     function red(uint a) public pure {//224 in gas cost if successful and 287 if it reverts
        if(a != 20){
          revert notEqual(bytes32("authorized"));
        }
    }
}

contract test1 {//deployment cost: 113364 in gas cost
    function red(uint a) public pure {//224 in gas cost if successful and 323 if it reverts
        require(a == 20, "unauthorized");
    }
}

i've not tested this with the code base , the total loc of the codebase are way too much and takes too much time to compile on my computer

malik672 avatar Oct 03 '23 06:10 malik672