code-423n4 / 2021-12-defiprotocol-findings

0 stars 0 forks source link

Function changePublisher, changeLicenseFee, and setNewMaxSupply can be refactored for efficiency and clarity #162

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

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-L173

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

Tools Used

Visual Studio Code, Remix

Recommended Mitigation Steps

See POC for details.