MetalSwap NFT Staking Pool
Smart Contract Security Assessment
May 30, 2024
SUMMARY
ABSTRACT
Dedaub was commissioned to perform a security audit of the MetalSwap protocol. A number of issues were found, of which 3 were high severity, 7 were of medium severity and 4 were of low severity; 4 centralisation concerns were also identified by the audit. The auditors also strongly recommended the development of a comprehensive test suite to ensure the correct working of the protocol, as one is currently absent.
BACKGROUND
Users who deposit liquidity in a Uniswap V3 pool obtain an NFT corresponding to their position. The MetalSwap protocol allows users to stake this NFT in order to earn rewards provided by MetalSwap. Rewards are distributed according to the fees earned by the position as a proportion of all fees earned by the NFTs staked on MetalSwap. The MetalSwap protocol has the ability to boost rewards, and is also able to modify the price range of a staked NFT position at the user’s request.
SETTING & CAVEATS
This audit report mainly covers the contracts of the (at the time) private repository nft-staking-pool of the MetalSwap protocol, at commit number:
3e0810414fdb690b9b9b8fee6615d1956cdec512
Two auditors worked on the codebase for 5 days on the following contracts:
- LoopExecutionCollectAssign.sol
- NFTStakingPool.sol
The issues found in the smart contracts were subsequently resolved by the team in commit number 1c5d8bd5e7e8440bda4bfa06a09f5f00ac1871a8
. A test suite was added in commit number c6e30196c84528ba1ad4cfacf431218db216ac5a
and was also reviewed.
The audit’s main target is security threats, i.e., what the community understanding would likely call "hacking", rather than the regular use of the protocol. Functional correctness (i.e. issues in "regular use") is a secondary consideration. Typically it can only be covered if we are provided with unambiguous (i.e. full-detail) specifications of what is the expected, correct behavior. In terms of functional correctness, we often trusted the code’s calculations and interactions, in the absence of any other specification. Functional correctness relative to low-level calculations (including units, scaling and quantities returned from external protocols) is generally most effectively done through thorough testing rather than human auditing.
PROTOCOL-LEVEL CONSIDERATIONS
The protocol consists of two contracts, a monolithic contract called NFTStakingPool
of 1786 LOC which provides the main functionality and a supporting contract called LoopExecutionCollectAssign
of 98 LOC. The NFTStakingPool
contract contains a large number of contract variables, many of which can be changed through admin controlled functionality at runtime. A mix of zero-indexed and one-indexed arrays are used, requiring the developer to frequently switch between these two representations. Non-trivial functionality and calculations are present and the contract variables often need to maintain certain relationships to one another. The audit found several issues of varying severity which would have been caught had a test suite been present. We note that the developers have made an effort to cover various edge cases programmatically, however we strongly recommend that the team develop a strong test suite with good coverage before deployment in order to verify that the protocol behaves as expected.
VULNERABILITIES & FUNCTIONAL ISSUES
This section details issues affecting the functionality of the contract. Dedaub generally categorizes issues according to the following severities, but may also take other considerations into account such as impact or difficulty in exploitation:
- User or system funds can be lost when third-party systems misbehave.
- DoS, under specific conditions.
- Part of the functionality becomes unusable due to a programming error.
- Breaking important system invariants but without apparent consequences.
- Buggy functionality for trusted users where a workaround exists.
- Security issues which may manifest when the system evolves.
Issue resolution includes “dismissed” or “acknowledged” but no action taken, by the client, or “resolved”, per the auditors.