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.
Submitted by juancito, also found by glcanvas, Yanchuan, and volodya
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;
}
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);
}
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.
Alex the Entreprenerd (Judge) commented:
The finding lacks a clear loss of funds, although that may be possible since
ownerOfis 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.
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
- Mint a bond token to an address.
- Check that the bonds mapping owner and the ERC721 ownerOf both return the minting address.
- Transfer the token to a different address using safeTransferFrom.
- 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.