I was wondering if there are any recommendations/ changes on how to write contracts so that they use minimal gas (without having to resort to all the hacks with assembly ).
I am in the progress of migrating the Gnosis Safe contracts to a newer compiler from 0.5.17 and saw that it requires >5% (90k for an ERC20 transfer via the Safe to 96k) additional gas if I upgrade to 0.8.1.
If I upgrade to 0.7.6 I see that the gas usage is actually reduced compared to 0.5.17.
So the primary gas increase comes from the abi v2 encoder. If I switch back to v1 I only need 1% more gas … I am still surprised that this is the case (even if I am turning on the optimizer).
Additionally it seems that the contract size itself is also bigger with 0.8.1 compared to 0.7.6. With 0.8.1 I had to remove code to stay withing the size limit.
I only did the mininmal changes required to get the contract compiling with the corresponding version. If there are recommended changes to avoid some of that gas overhead I would be very much interested.
Note: Here some simple gas tests run with hardhat: