Omniscia Kyo Finance Audit
NonfungiblePositionManager Code Style Findings
NonfungiblePositionManager Code Style Findings
NPM-01C: Inefficient Initialization of Position
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | NonfungiblePositionManager.sol:L101 |
Description:
The creation of a new position via the NonfungiblePositionManager::mint
function is presently inefficient as the operation will result in multiple storage writes of 0
even though the only variables that need to be initialized are the growth control variables.
Example:
contracts/univ3-periphery/NonfungiblePositionManager.sol
93function mint(MintParams calldata params) external payable override checkDeadline(params.deadline) returns (uint256 tokenId, uint128 liquidity, uint256 amount0, uint256 amount1) {94 IUniswapV3Pool pool;95 (liquidity, amount0, amount1, pool) = addLiquidity(AddLiquidityParams({token0: params.token0, token1: params.token1, fee: params.fee, recipient: address(this), tickLower: params.tickLower, tickUpper: params.tickUpper, amount0Desired: params.amount0Desired, amount1Desired: params.amount1Desired, amount0Min: params.amount0Min, amount1Min: params.amount1Min}));96
97 _mint(params.recipient, (tokenId = _nextId++));98
99 _positions[tokenId] = Position({nonce: 0, operator: address(0), pool: pool, tickLower: params.tickLower, tickUpper: params.tickUpper, liquidity: 0, liquidityStaked: 0, feeGrowthInside0LastX128: 0, feeGrowthInside1LastX128: 0, rewardGrowthInsideLastX128: 0, tokensOwed0: 0, tokensOwed1: 0, rewardsOwed: 0});100
101 _updatePosition(tokenId);102 _positions[tokenId].liquidity += liquidity;103
104 emit IncreaseLiquidity(tokenId, liquidity, amount0, amount1);105}
Recommendation:
We advise the growth control variables to be initialized directly similarly to the original Uniswap V3 implementation, greatly optimizing the code's gas cost.
Alleviation (17c8d4e59f398021156f6f9657ff278aae0462ae):
The Kyo Finance team evaluated this exhibit but opted to acknowledge it in the current iteration of the codebase.