Skip to content
Business logic Audit finding Intermediate

Fixed Term Bond tokens can be minted with non-rounded expiry

The deploy() function in BondFixedTermTeller.sol does not round the expiry timestamp to the nearest day, unlike the internal _handlePayout() function. This allows tokens to be minted with arbitrary expiry times, which can be exploited by malicious users to pre-deploy tokens at future timestamps and lock in unexpected expiry times.

obront Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-bond-judging/issues/32

Found by

obront

Summary

Fixed Term Tellers intend to mint tokens that expire once per day, to consolidate liquidity and create a uniform experience. However, this rounding is not enforced on the external deploy() function, which allows for tokens expiring at unexpected times.

Vulnerability Detail

In BondFixedTermTeller.sol, new tokenIds are deployed through the _handlePayout() function. The function calculates the expiry (rounded down to the nearest day), uses this expiry to create a tokenId, and — if that tokenId doesn't yet exist — deploys it.

Solidity
...
expiry = ((vesting_ + uint48(block.timestamp)) / uint48(1 days)) * uint48(1 days);

// Fixed-term user payout information is handled in BondTeller.
// Teller mints ERC-1155 bond tokens for user.
uint256 tokenId = getTokenId(payoutToken_, expiry);

// Create new bond token if it doesn't exist yet
if (!tokenMetadata[tokenId].active) {
    _deploy(tokenId, payoutToken_, expiry);
}
...

This successfully consolidates all liquidity into one daily tokenId, which expires (as expected) at the time included in the tokenId.

However, if the deploy() function is called directly, no such rounding occurs:

Solidity
function deploy(ERC20 underlying_, uint48 expiry_)
    external
    override
    nonReentrant
    returns (uint256)
{
    uint256 tokenId = getTokenId(underlying_, expiry_);
    // Only creates token if it does not exist
    if (!tokenMetadata[tokenId].active) {
        _deploy(tokenId, underlying_, expiry_);
    }
    return tokenId;
}

This creates a mismatch between the tokenId time and the real expiry time, as tokenId is calculated by rounding the expiry down to the nearest day:

Solidity
uint256 tokenId = uint256(
    keccak256(abi.encodePacked(underlying_, expiry_ / uint48(1 days)))
);

... while the _deploy() function saves the original expiry:

Solidity
tokenMetadata[tokenId_] = TokenMetadata(
    true,
    underlying_,
    uint8(underlying_.decimals()),
    expiry_,
    0
);

Impact

The deploy() function causes a number of issues:

  1. Tokens can be deployed that don't expire at the expected daily time, which may cause issues with your front end or break user's expectations
  2. Tokens can expire at times that don't align with the time included in the tokenId
  3. Malicious users can pre-deploy tokens at future timestamps to "take over" the token for a given day and lock it at a later time stamp, which then "locks in" that expiry time and can't be changed by the protocol

Code Snippet

https://github.com/sherlock-audit/2022-11-bond/blob/main/src/BondFixedTermTeller.sol#L175-L187

https://github.com/sherlock-audit/2022-11-bond/blob/main/src/BondFixedTermTeller.sol#L243-L250

https://github.com/sherlock-audit/2022-11-bond/blob/main/src/BondFixedTermTeller.sol#L194-L212

Tool used

Manual Review

Recommendation

Include the same rounding process in deploy() as is included in _handlePayout():

Solidity
function deploy(ERC20 underlying_, uint48 expiry_)
        external
        override
        nonReentrant
        returns (uint256)
    {
        expiry = ((vesting_ + uint48(block.timestamp)) / uint48(1 days)) * uint48(1 days);
        uint256 tokenId = getTokenId(underlying_, expiry_);
        ...

Discussion

Evert0x

Message from sponsor


Agree. We implemented rounding of the expiry value provided to deploy to match the calculation in _handlePayouts.

xiaoming9090

Fixed in https://github.com/Bond-Protocol/bonds/commit/54b6833a46b5ae4c3a3ca183b9a55ca8c1266827

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

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 external deploy() function fails to round the expiry timestamp to the nearest day, unlike the internal _handlePayout() function, leading to a mismatch between the tokenId (which uses rounded expiry) and the stored expiry.

Impact

Tokens can be deployed with non-standard expiry times, potentially breaking front-end expectations and allowing malicious users to pre-deploy tokens at future timestamps to lock in an expiry time that cannot be changed by the protocol.

What the attacker needed

Ability to call deploy() function

The fix

The deploy() function should include the same rounding of the expiry timestamp as _handlePayout(), and the sponsor has implemented this fix.

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.

In a bond protocol, tokens are supposed to expire at the same time each day to keep things organised. The function that creates these tokens normally rounds the expiry time down to the nearest day, but a publicly callable function skips this rounding. This means someone can create a token that expires at an odd time, which could confuse users or be abused to control when tokens expire.

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 obront

View all

46 more disclosed reports, best first.

More from Bond Options

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.