Existing user’s locked JPEG could be overwritten by new user, causing permanent loss of JPEG funds
A user's locked JPEG tokens could be overwritten when another user finalizes a proposal for the same NFT index, because the lock schedule is stored by NFT index and not by user. The original user then cannot withdraw their locked JPEGs, causing permanent loss of funds.
Submitted by hickuphh3, also found by 0x1f8b, AuditsAreUS, Foundation, Kthere, Meta0xNull, rayn, and WatchPug
NFTVault.sol#L375 JPEGLock.sol#L54-L62
A user’s JPEG lock schedule can be overwritten by another user’s if he (the other user) submits and finalizes a proposal to change the same NFT index’s value.
The existing user will be unable to withdraw his locked JPEGs, resulting in permanent lock up of JPEG in the locker contract.
Proof of Concept
usersuccessfully proposes and finalizes a proposal to change his NFT’s collateral value- Another user (
owner) does the same for the same NFT index userwill be unable to withdraw his locked JPEG because schedule has been overwritten
Insert this test case into NFTVault.ts.
it.only("will overwrite existing user's JPEG lock schedule", async () => {
// 0. setup
const index = 7000;
await erc721.mint(user.address, index);
await nftVault
.connect(dao)
.setPendingNFTValueETH(index, units(50));
await jpeg.transfer(user.address, units(150000));
await jpeg.connect(user).approve(locker.address, units(500000));
await jpeg.connect(owner).approve(locker.address, units(500000));
// 1. user has JPEG locked for finalization
await nftVault.connect(user).finalizePendingNFTValueETH(index);
// 2. owner submit proposal to further increase NFT value
await nftVault
.connect(dao)
.setPendingNFTValueETH(index, units(100));
// 3. owner finalizes, has JPEG locked
await nftVault.connect(owner).finalizePendingNFTValueETH(index);
// user schedule has been overwritten
let schedule = await locker.positions(index);
expect(schedule.owner).to.equal(owner.address);
// user tries to unstake
// wont be able to because schedule was overwritten
await timeTravel(days(366));
await expect(locker.connect(user).unlock(index)).to.be.revertedWith("unauthorized");
});
Recommended Mitigation Steps
- Release the tokens of the existing schedule. Simple and elegant.
// in JPEGLock#lockFor()
LockPosition memory existingPosition = positions[_nftIndex];
if (existingPosition.owner != address(0)) {
// release jpegs to existing owner
jpeg.safeTransfer(existingPosition.owner, existingPosition.lockAmount);
}
- Revert in
finalizePendingNFTValueETH()there is an existing lock schedule. This is less desirable IMO, as there is a use-case for increasing / decreasing the NFT value.
spaghettieth (JPEG’d) confirmed
spaghettieth (JPEG’d) resolved and commented:
Fixed in jpegd/core#3.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The lock position is stored per NFT index without checking for an existing owner, so a new lock overwrites the previous one.
Impact
The original user's locked JPEG tokens become permanently stuck in the contract, causing loss of funds.
What the attacker needed
Two users lock JPEG for the same NFT index; the second user finalizes after the first
The fix
The lock function should release any existing schedule's tokens to its owner before creating a new one, or finalization should revert if a lock already exists; the project says it was fixed.
How it was found
- A user finalizes a proposal to change an NFT's collateral value, locking JPEG tokens.
- Another user submits a proposal to further increase the same NFT's value.
- The second user finalizes the proposal, locking their own JPEG tokens.
- The lock schedule for that NFT index now belongs to the second user.
- The first user tries to unlock after the lock period but the transaction reverts as unauthorized.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you lock tokens in a contract, the contract records who locked them. Here, that record was keyed only by the NFT's number, so a second person locking tokens for the same NFT replaced the first person's record. The first person's tokens were still in the contract but the contract no longer knew they belonged to them, so they could not get them back.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.