#Solidity Trick for Gas Optimization:
Since version 0.8.0, Solidity automatically checks for overflow in each arithmetic operation, making them naturally more expensive
If you are sure a variable will never overflow (Ex: a loop), use the unchecked block to save gas
Fast Coding or Clean Coding?
Clean code is good but sometimes you might be in a rush or you just need to test something quickly
In my experience, it's both
When you are in a rush create a semi-readable working code
Then, when it's suitable, improve it
What do you think?
That's why it's called a re-entrancy attack
Stay tuned to know how to protect against these hacks.
If you enjoyed this thread:
1. Follow me @JeremyTheWizard for more of these
2. RT the tweet below to share this thread with your audience
What do all these hacks have in common?
- The DAO: $50mln
- Fei Protocol: $80mln
- Cream Finance: $18.8ml
- Uniswap/Lendf.Me: 25$mln
- The list can go on forever...
All these hacks were re-entrancy attacks!
So what is a re-entrancy attack? Read below for a short overview
What do all these hacks have in common?
- The DAO: $50mln
- Fei Protocol: $80mln
- Cream Finance: $18.8ml
- Uniswap/Lendf.Me: 25$mln
- The list can go on forever...
All these hacks were re-entrancy attacks!
So what is a re-entrancy attack? Read below for a short overview
The external contract then usually calls back the main contract.
Doing so never allows the code after the line where the exploiter contract was called to be run.
You can imagine all the problems that could cause.
Solidity Gas Optimization Trick:
Each slot can store up to 256 bits
Data that is bigger spans multiple slots
For data smaller than a slot, solidity tries to stack it together
But here's the catch...
For this to work, we have to put the same type of variables together