Skip to content
Business logic Audit finding Intermediate

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.

hickuphh3 Follow

Originally disclosed on Code4rena

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

  1. user successfully proposes and finalizes a proposal to change his NFT’s collateral value
  2. Another user (owner) does the same for the same NFT index
  3. user will 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

  1. 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);
}
  1. 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.


The original report as published on Code4rena, by hickuphh3. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. A user finalizes a proposal to change an NFT's collateral value, locking JPEG tokens.
  2. Another user submits a proposal to further increase the same NFT's value.
  3. The second user finalizes the proposal, locking their own JPEG tokens.
  4. The lock schedule for that NFT index now belongs to the second user.
  5. 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.

More by hickuphh3

View all

43 more disclosed reports, best first.

More from JPEG'd contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.