Avoid rereading variables cache in memory
When using variables some are being reread several times
s_state not cached and reread
msg.sender reread several times
Gas Savings: Caching especially storage variables leads to gas savings as reading from storage costs 100 gas whereas from memory will cost 3 gas.
Manual Analysis
Escrow.sol line 66 -> this does not save as much gas as not reading from storage but avoids rereading msg.sender
modifier onlyBuyerOrSeller() {
address sender = msg.sender;
if (sender != i_buyer && sender != i_seller) {
revert Escrow__OnlyBuyerOrSeller();
}
_;
}
Escrow.sol line 82 -> s_state read twice from storage second time costs 100 gas if read from memory only 3 gas
modifier inState(State expectedState) {
Escrow curr_state = s_state;
if (curre_state != expectedState) {
revert Escrow__InWrongState(curr_state, expectedState);
}
_;
}
EscrowFactory.sol line 20-53 avoid rereading msg.sender and cache it as it is reused 4 times
It is recommended to ensure when reading and using storage variables they are cached. It is recommended to ensure msg.sender is not reread several times in a function but be cached.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.