
Securing and optimizing the blockchain: gas optimization, security audits, tokenomics and tech DD
9 Followers
We’ve seen many projects wasting tons of gas checking for enum values. In our last audit, we found a situation where an enum storage ID had to be validated prior to an execution. Do you see why it is extremely inefficient? Let’s check how this code can be improved and optimised👇
We can see how we can perform the same checks just by validating if the queried storage ID is less than 2. This can lead to significant gas improvements even if not performed with assembly, as stated in the following snapshot comparing the differences:
DM us for REAL gas optimisations that will make your code be extremely improved!🙌🏻
As we can see, the previous snippet will check if the storageId parameter is different from the valid Storage IDs and revert in case none of them is valid. However, this can be performed in a more efficient way if we consider the fact that enums are actually uint8 types👀