Skip to content
Business logic Audit finding Intermediate

The owner of RPDX Decaying Bonds is not updated on token transfers

The RdpxDecayingBonds contract stores a bond owner in a mapping that is set only at mint and never updated on token transfers. An attacker could transfer a bond token, leaving the stored owner stale, which may mislead integrations and cause loss of funds.

juancito Follow with glcanvas, Yanchuan and 1 other

Originally disclosed on Code4rena

Submitted by juancito, also found by glcanvas, Yanchuan, and volodya

https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/decaying-bonds/RdpxDecayingBonds.sol#L36-L44

https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/decaying-bonds/RdpxDecayingBonds.sol#L122

The RdpxDecayingBonds contract keeps track of a bonds mapping with bonds information including the bond token owner. When the token is transfered, the bonds[bondId].owner value should be updated, but it isn’t.

Impact

The owner value will be bricked when a token is transfered, as it can’t be changed by any means.

Any integration relying on this value will make wrong trusted assumptions related to the bond token owner, potentially leading to critical issues as loss of funds, because of the importance of the owner attribute has.

Ranking it as Medium, as there is no direct loss of funds within the current scope, but bricks the contract functionality, as there is no way to fix it.

Proof of Concept

The owner attribute of the bonds mapping is set on each mint(), but its value is never updated:

  // Array of bonds
  mapping(uint256 => Bond) public bonds;

  // Structure to store the bond information
  struct Bond {
    address owner; // @audit
    uint256 expiry;
    uint256 rdpxAmount;
  }

RdpxDecayingBonds.sol#L36-L44

  function mint(
    address to,
    uint256 expiry,
    uint256 rdpxAmount
  ) external onlyRole(MINTER_ROLE) {
    _whenNotPaused();
    require(hasRole(MINTER_ROLE, msg.sender), "Caller is not a minter");
    uint256 bondId = _mintToken(to);
@>  bonds[bondId] = Bond(to, expiry, rdpxAmount); // @audit

    emit BondMinted(to, bondId, expiry, rdpxAmount);
  }

RdpxDecayingBonds.sol#L122

Coded Proof of Concept

This test shows how the owner remains the same on the bonds transfer after performing a transfer.

Add this test to the tests/RdpxDecayingBondsTest.t.sol file, and run forge test --mt "testSameOwnerOnTransfer":

  function testSameOwnerOnTransfer() public {
    // Mint a token
    rdpxDecayingBonds.mint(address(this), 1223322, 5e18);

    // The tokenId is 1
    // This can be confirmed by the fact that it changes its `ownerOf()` result on the OZ ERC721 after the transfer
    uint256 tokenId = 1;

    // Check the bond token owner before the transfer
    // Check for both via the `bonds` mapping, and the OZ `ownerOf()` function
    (address ownerBeforeTransfer,,) = rdpxDecayingBonds.bonds(tokenId);
    assertEq(ownerBeforeTransfer, address(this));
    assertEq(rdpxDecayingBonds.ownerOf(tokenId), address(this));

    // Transfer token
    rdpxDecayingBonds.safeTransferFrom(address(this), address(420), tokenId);

    // The `owner` changes on the OZ `ownerOf` function, while it remains the same on the `bonds` mapping
    (address ownerAfterTransfer,,) = rdpxDecayingBonds.bonds(tokenId);
    assertEq(ownerAfterTransfer, address(this));                        // @audit remains the same after the transfer
    assertEq(rdpxDecayingBonds.ownerOf(tokenId), address(420));
  }

Recommended Mitigation Steps

Either update the owner value on each token transfer, or remove it, as the owner of the token is already tracked via the OZ ERC721 contract.

psytama (Dopex) confirmed

Alex the Entreprenerd (Judge) commented:

The finding lacks a clear loss of funds, although that may be possible since ownerOf is used for internal checks.

The code breaks the implementation of EIP721, and may also cause losses + issues with integrations.

I think Medium Severity is appropriate.


The original report as published on Code4rena, by juancito. 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 contract maintains a separate owner field in its bonds mapping but does not override the ERC721 transfer hooks to update it, so the field becomes stale after any transfer.

Impact

The stale owner value could cause integrations to make wrong assumptions about the bond owner, potentially leading to loss of funds, though the report notes there is no direct loss within the current scope.

What the attacker needed

A bond token must be minted; the token must be transferred

The fix

The owner value should be updated on each token transfer, or removed entirely since the ERC721 ownerOf already tracks ownership.

How it was found

  1. Mint a bond token to an address.
  2. Check that the bonds mapping owner and the ERC721 ownerOf both return the minting address.
  3. Transfer the token to a different address using safeTransferFrom.
  4. Check that ownerOf returns the new address while the bonds mapping owner still returns the old address.

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.

This contract is like a digital certificate that records who owns a bond. When the certificate is sold or given away, the official record of the owner is not updated, so it still shows the old person. Anyone relying on that record could be tricked into thinking the old owner still controls the bond.

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 juancito

View all

14 more disclosed reports, best first.

More from Dopex

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.