Skip to content
Business logic Audit finding Intermediate

Fixed Term Teller tokens can be created with an expiry in the past

The Fixed Term Teller contract checked that a bond token's expiry timestamp was not in the past, but token IDs round timestamps down to the nearest day. An attacker could supply an expiry slightly in the future that rounds down to a past day, allowing them to mint and immediately redeem bond tokens.

obront Follow

Originally disclosed on Sherlock

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

Found by

obront

Summary

The Fixed Term Teller does not allow tokens to be created with a timestamp in the past. This is a fact that protocols using this feature will expect to hold and build their systems around. However, users can submit expiry timestamps slightly in the future, which correlate to tokenIds in the past, which allows them to bypass this check.

Vulnerability Detail

In BondFixedTermTeller.sol, the create() function allows protocols to trade their payout tokens directly for bond tokens. The expectation is that protocols will build their own mechanisms around this. It is explicitly required that they cannot do this for bond tokens that expire in the past, only those that have yet to expire:

Solidity
if (expiry_ < block.timestamp) revert Teller_InvalidParams();

However, because tokenIds round timestamps down to the latest day, protocols are able to get around this check.

Here's an example:

  • The most recently expired token has an expiration time of 1668524400 (correlates to 9am this morning)
  • It is currently 1668546000 (3pm this afternoon)
  • A protocol calls create() with an expiry of 1668546000 + 1
  • This passes the check that expiry_ >= block.timestamp
  • When the expiry is passed to getTokenId() it rounds the time down to the latest day, which is the day corresponding with 9am this morning
  • This expiry associated with this tokenId is 9am this morning, so they are able to redeem their tokens instantly

Impact

Protocols can bypass the check that all created tokens must have an expiry in the future, and mint tokens with a past expiry that can be redeemed immediately.

This may not cause a major problem for Bond Protocol itself, but protocols will be building on top of this feature without expecting this behavior.

Let's consider, for example, a protocol that builds a mechanism where users can stake some asset, and the protocol will trade payout tokens to create bond tokens for them at a discount, with the assumption that they will expire in the future. This issue could create an opening for a savvy user to stake, mint bond tokens, redeem and dump them immediately, buy more assets to stake, and continue this cycle to earn arbitrage returns and tank the protocol's token.

Because there are a number of situations like the one above where this issue could lead to a major loss of funds for a protocol building on top of Bond, I consider this a high severity.

Code Snippet

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

Tool used

Manual Review

Recommendation

Before checking whether expiry_ < block.timestamp, expiry should be rounded to the nearest day:

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

Discussion

Evert0x

Message from sponsor


Agree with this finding. We implemented rounding of the expiry before checking whether it is in the past to both the Fixed Term and Fixed Expiry Tellers (fixed expiry added since we made a change to round these to the nearest day as well).

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 expiry check compared the raw timestamp against the current time, but the token ID calculation rounded the timestamp down to the start of the day, so a future timestamp could map to a past day.

Impact

Protocols can bypass the check that all created tokens must have an expiry in the future, and mint tokens with a past expiry that can be redeemed immediately, potentially leading to arbitrage and loss of funds for protocols building on top.

What the attacker needed

Access to the create() function; ability to submit a custom expiry timestamp

The fix

The expiry should be rounded to the nearest day before checking whether it is in the past, and this was fixed in both the Fixed Term and Fixed Expiry Tellers.

How it was found

  1. Call the create() function with an expiry timestamp that is slightly in the future (e.g., current time plus one second).
  2. The check expiry_ >= block.timestamp passes because the timestamp is in the future.
  3. The expiry is passed to getTokenId(), which rounds it down to the latest day, which may be in the past.
  4. The resulting token ID corresponds to a past expiry, so the tokens can be redeemed immediately.

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.

A smart contract lets people create bond tokens that should only be redeemable in the future. It checks the expiry time, but the token ID is based on the day, not the exact second. By choosing an expiry time just a few seconds ahead, the day used for the token ID can be today or even yesterday, so the token can be redeemed straight away.

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.