stake.link

stake.link
DeFiHardhatBridge
27,500 USDC
View results
Submission Details
Severity: medium
Invalid

SDLPoolPrimary:: `balances` mapping is not updated when a lock is unlcoked

Summary

The balances mapping is not updated when a lock is unlocked.

Vulnerability Details

There is a mapping: mapping(address => uint256) internal balances; which keeps track of total number of locks of an address/user. When _storeNewLock() is called in SDLPoolPrimary contract the balances mapping is updated i.e increased by 1, but when a lock is unlocked the mapping is not updated i.e is decreased by 1. So the lock presents even after unlocking the lock.

POC

Run this test:

it('balances mapping is not updated', async () => {
//@audit
await sdlToken.transferAndCall(
// locked token
sdlPool.address,
toEther(1000),
ethers.utils.defaultAbiCoder.encode(['uint256', 'uint64'], [0, 100 * DAY])
)
await sdlToken.transferAndCall(
// locked token
sdlPool.address,
toEther(1000),
ethers.utils.defaultAbiCoder.encode(['uint256', 'uint64'], [0, 100 * DAY])
)
assert.equal((await sdlPool.balanceOf(accounts[0])).toNumber(), 2)
await time.increase(80 * DAY)
await sdlPool.initiateUnlock(1)
await time.increase(100 * DAY)
assert.equal((await sdlPool.balanceOf(accounts[0])).toNumber(), 2)
await time.increase(200 * DAY)
assert.equal((await sdlPool.balanceOf(accounts[0])).toNumber(), 2)
})

Impact

Outdated state in contract.

Tools Used

Manual analysis

Recommendations

Add this balances[msg.sender] -= 1 in initiateUnlock().

Updates

Lead Judging Commences

0kage Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.