Open code423n4 opened 2 years ago
Tomio
By using interface in createPair function the gas cost 172 more expensive than using address type.
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
Remix - Ethereum IDE
We want to use interface for readability of the contract.
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:
Tools Used
Remix - Ethereum IDE