code-423n4 / 2021-09-wildcredit-findings

0 stars 0 forks source link

Using msg.sender or cached locals in emits instead of state variables saves gas #88

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

0xRajeev

Vulnerability details

Impact

Using msg.sender or cached local variables in emits instead of state variables set to msg.sender values saves gas by avoiding expensive SLOADs that cost 2100 gas after Berlin upgrade.

Proof of Concept

Use msg.sender instead of owner: https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/external/Ownable.sol#L17

Use cached local variable instead of pendingOwner: https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/external/Ownable.sol#L36-L38

Tools Used

Manual Analysis

Recommended Mitigation Steps

Use msg.sender or cached locals in emits instead of state variables