atlas icon indicating copy to clipboard operation
atlas copied to clipboard

Gas optimization: replace error messages with custom errors code

Open haythemsellami opened this issue 2 years ago • 3 comments

Solidity 0.8 support custom error codes, using custom error codes will always consume 4bytes(the error code selector) when reverting, which will be more gas efficient vs using long error messages in string.

haythemsellami avatar Aug 30 '23 13:08 haythemsellami

I'm trying to read the codebase and learn more about it, this is may not be that urgent, but can work on it if the team approve the idea!

haythemsellami avatar Aug 30 '23 14:08 haythemsellami

This is something we've hotly debated internally.

Our experience has been that block explorers have trouble displaying custom error codes to users, or in our case, searchers. This leads to many searchers coming into our discord and asking why their transaction reverted. The flip side of this is that Atlas is intended for Eth Mainnet, where the gas savings will be more notable than for our MEV relay on Polygon PoS.

I did add a few custom errors in the most recent PR but was planning on going back and changing them. You do make a good point.

One other thing to consider - Atlas uses multiple try/catch layers. What would your thoughts be on using custom errors for all the deep errors but then using regular errors only for the ones that are intended to bubble up to the top?

thogard785 avatar Sep 01 '23 08:09 thogard785

This is something we've hotly debated internally.

Our experience has been that block explorers have trouble displaying custom error codes to users, or in our case, searchers. This leads to many searchers coming into our discord and asking why their transaction reverted. The flip side of this is that Atlas is intended for Eth Mainnet, where the gas savings will be more notable than for our MEV relay on Polygon PoS.

I did add a few custom errors in the most recent PR but was planning on going back and changing them. You do make a good point.

One other thing to consider - Atlas uses multiple try/catch layers. What would your thoughts be on using custom errors for all the deep errors but then using regular errors only for the ones that are intended to bubble up to the top?

Yeah using regular errors for specific cases could work work, but I think is is better to be consistent across all the codebase and use on way only.

AFAIK at least for ethereum mainnet, etherscan and other block explorer handle well custom errors.

haythemsellami avatar Sep 11 '23 10:09 haythemsellami

Hey @haythemsellami thanks for the suggestion. We did end up standardising on custom errors in the end.

Code is almost locked for v1 and we're nearing the end of an audit process, so going to close this issue.

BenSparksCode avatar Jul 01 '24 06:07 BenSparksCode