Open code423n4 opened 2 years ago
ye0lde
Reducing redundant code and state variable references can reduce gas usage and improve code clarity.
The changePublisher function: https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L157-L173
changePublisher
I suggest this refactoring:
function changePublisher(address newPublisher) onlyPublisher public override { require(newPublisher != address(0)); if (pendingPublisher.publisher != address(0) && pendingPublisher.publisher == newPublisher) { require(block.timestamp >= pendingPublisher.timestamp + TIMELOCK_DURATION); pendingPublisher.publisher = address(0); emit ChangedPublisher(publisher = newPublisher); } else { pendingPublisher.timestamp = block.timestamp; emit NewPublisherSubmitted(pendingPublisher.publisher = newPublisher); } }
Similar changes can be made to these functions: https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L175-L192 https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L194-L212
Visual Studio Code, Remix
See POC for details.
Handle
ye0lde
Vulnerability details
Impact
Reducing redundant code and state variable references can reduce gas usage and improve code clarity.
Proof of Concept
The
changePublisher
function: https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L157-L173I suggest this refactoring:
Similar changes can be made to these functions: https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L175-L192 https://github.com/code-423n4/2021-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Basket.sol#L194-L212
Tools Used
Visual Studio Code, Remix
Recommended Mitigation Steps
See POC for details.