code-423n4 / 2022-01-timeswap-findings

2 stars 0 forks source link

can reduce gas in function createPair by replacing interface with address #144

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Tomio

Vulnerability details

Impact

By using interface in createPair function the gas cost 172 more expensive than using address type.

Proof of Concept

Before: https://github.com/code-423n4/2022-01-timeswap/blob/main/Timeswap/Timeswap-V1-Core/contracts/TimeswapFactory.sol#L47

After:

contract test {

mapping(address => mapping(address => address)) public getPair;

function createPair(address asset, address collateral) external returns (address pair) {
        require(asset != collateral, 'E103');
        require(asset != address(0) && collateral != address(0), 'E101');
        require(getPair[asset][collateral] == address(0), 'E104');

        //pair = new TimeswapPair{salt: keccak256(abi.encode(asset, collateral))}(asset, collateral, fee, protocolFee);

        getPair[asset][collateral] = pair;

        //emit CreatePair(asset, collateral, pair);
    }
}   
//25784 before 
//25612 after

Tools Used

Remix - Ethereum IDE

Mathepreneur commented 2 years ago

We want to use interface for readability of the contract.