My contract has a lot of uint256 constant fields that are later used for various calculations. I am close to reaching the maximum allowed contract size and I am looking for optimizations.

I see that having some fields as uint8 instead of uint256 reduces size of the bytecode but at the same time, knowing that for uint8 operations need to downscale and cost more gas I don't want to trade contract bytecode size and the cost of deployment paid once for more expensive day-to-day contract function calls.

Is there any solution allowing storing smaller fields in non 256-bit slots and not paying the cost of downscaling later, during every single operation using those fields?

  • 1
    In my experience constants are not much of a problem when optimizations are enabled in the compiler. I'd suggest to remove unneeded functions, using libraries, or splitting functionality in several contracts.
    – Ismael
    Nov 2 '19 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.