Skip to content

Code4rena

Timeswap contest

Every publicly disclosed report for Timeswap contest and what kind of bugs they were.

disclosed reports
31
most reported class
Business logic
bug classes found
5
first disclosure
2022
Find Timeswap contest on bugbounty.fyi Current scope, rewards and status, if it runs a public program.

Disclosed reports

Newest first. Only what Timeswap contest chose to make public.

Business logic

Burning a ERC1155Enumerable token doesn’t remove it from the enumeration

The ERC1155Enumerable contract checks the total supply before decreasing it when burning tokens, so the last token is never removed from the enumeration. This causes totalSupply and tokenByIndex to return incorrect values and allows duplicate entries if the token is minted again.

Timeswap contest

Medium
Smart contracts

unexpected overflow for FullMath.add512() which can result in irregular behavior

The add512 function in FullMath has an insufficient overflow check that can be bypassed when the high words sum to a value that overflows but the check only reverts if addendA1 > sum1. An attacker could manipulate leverage and deleverage functions to receive more tokens than expected.

Timeswap contest

Medium
Business logic

TimeswapV2LiquidityToken should not use totalSupply()+1 as tokenId

The TimeswapV2LiquidityToken contract assigns new token IDs using totalSupply() + 1, which can decrease when tokens are burned, causing different liquidity positions to receive the same token ID. An attacker could manipulate balances by exploiting this collision, though the current ERC1155Enumerable bug prevents it from being exploitable.

Timeswap contest

High
Business logic

Rebalance logic is wrong and this distorts the pool’s important states

The rebalance function used the wrong pool balance variable when calculating fees for a specific transaction type, leading to incorrect state updates including setting a balance to zero. An attacker could call the permissionless rebalance function to break the pool's invariant and potentially take profit.

Timeswap contest

High
Business logic

_currentIndex is incorrectly updated; breaking the ERC1155 enumerable implementation

The ERC1155Enumerable implementation incorrectly updates internal state when minting and burning tokens, causing the total supply and token indices to never decrease. An attacker could exploit this to break the enumerable functionality, leading to incorrect token tracking and potential denial of service.

Timeswap contest

Medium
Audit finding

sqrtDiscriminant can be calculated wrong

The square root function used in the pool's leverage and deleverage calculations returns incorrect results when rounding up, especially for small values. This can cause users to receive wrong amounts of long or short tokens, leading to financial loss for users and lost fees for the protocol.

Timeswap contest

Medium
Business logic

Fee on transfer tokens will not behave as expected

The contract checks token balances against expected targets after transfers, but fee-on-transfer tokens cause the received amount to be less than the target, making mint() and swap() revert. This prevents the protocol from supporting such tokens, contrary to the whitepaper's claim of working with any ERC20 pair.

Timeswap contest

Medium
RCE

NPM Dependency confusion. Unclaimed NPM Package and Scope/Org

The npm scope and package name used by the Timeswap project were unclaimed on the public registry, so an attacker could register them and publish a malicious package with a higher version number. Anyone installing the project's dependencies could then run the attacker's code on their machine.

Timeswap contest

Medium
DoS

The pay() function can still be DOSed

The pay() function in TimeswapPair can be front-run by an attacker who repays a tiny amount of the victim's debt, causing the victim's full repayment to underflow and revert. This blocks users from repaying their full debt, a denial-of-service.

Timeswap contest

Medium
Smart contracts

Underflown variable in borrowGivenDebtETHCollateral function

The borrowGivenDebtETHCollateral function initialises a uint256 excess variable to zero and then subtracts dueOut.collateral from it inside an unchecked block, causing an underflow. This means the function never correctly transfers excess ETH to the user and always reverts when maxCollateral exceeds dueOut.collateral.

Timeswap contest

Medium
Smart contracts

In the lend() function state updates are made after the callback

The lend() function in TimeswapPair.sol makes an external callback to the caller before updating key state variables such as totalClaims, bonds, insurance and reserves. This violates the checks-effects-interactions pattern and could allow cross-function reentrancy, potentially enabling an attacker to exploit the protocol's composability with other contracts.

Timeswap contest

High
Business logic

TimeswapPair.sol#borrow() Improper implementation allows attacker to increase pool.state.z to a large value

The borrow function allows the caller to specify an arbitrary zIncrease value, which is added to the pool's state.z without being tied to the actual collateral provided. An attacker can borrow a tiny amount (1 wei) with a huge zIncrease, then repay the loan and recover the collateral, artificially inflating state.z and later exploiting the inflated insurance token value to drain collateral from defaulted loans.

Timeswap contest

High
DoS

safeDecimals can revert causing DoS

The safeDecimals function in SafeMetadata.sol uses a length check of >= 32 before calling abi.decode, which reverts if the returned data is longer than 32 bytes. An attacker could cause a denial of service by using a token whose decimals() call returns more than 32 bytes of data, making any function that calls safeDecimals revert.

Timeswap contest

Medium
Business logic

burn() doesn’t call ERC721 _burn()

The burn() function in CollateralizedDebt.sol does not call the ERC721 _burn() function, so the ERC721 token representing a collateral position is not destroyed when a user burns their position and receives their funds. An attacker could continue to hold the ERC721 token after burning, potentially allowing them to reuse or misrepresent the position.

Timeswap contest

Medium
Audit finding

borrow() function has state updates after a callback to msg.sender

The borrow() function in TimeswapPair.sol makes an external callback to msg.sender before completing state updates, violating the checks-effects-interactions pattern. This could enable cross-function reentrancy attacks, potentially allowing an attacker to manipulate collateral, debt, or reserves.

Timeswap contest

High
DoS

safeName() can revert causing DoS

The safeName() function assumes ERC20 token name() returns a string, but some tokens return bytes32, causing abi.decode() to revert. This makes four Timeswap convenience contracts revert when name() is called, breaking ERC20 compliance for certain asset pairs.

Timeswap contest

Medium
XSS

XSS via SVG Construction contract

The NFTTokenURIScaffold contract generates an SVG image that includes the ERC20 token symbol without sanitisation. An attacker can create a token with a malicious symbol containing JavaScript, and when the SVG is viewed on a website, the script executes, leading to XSS.

Timeswap contest

Medium
DoS

DOS pay function

The pay() function subtracts the amount paid from the user's recorded debt, and the contract uses Solidity 0.8 or later, so any subtraction that goes below zero reverts. An attacker can front-run a user who is repaying their full debt by paying a tiny amount toward that user's debt first, which makes the user's payment exceed the remaining debt and causes the transaction to revert.

Timeswap contest

Medium
Audit finding

pay() function has callback to msg.sender before important state updates

The pay() function in TimeswapPair.sol makes an external callback to msg.sender before updating reserves, violating checks-effects-interactions. An attacker could exploit cross-function reentrancy to manipulate state during the callback.

Timeswap contest

High
DoS

safeSymbol() can revert causing DoS

The safeSymbol() function assumes every ERC20 token returns its symbol as a string, so tokens that return a bytes32 value cause abi.decode() to revert. This makes the symbol() functions in four Timeswap convenience contracts revert, breaking ERC20 compliance for those asset pairs.

Timeswap contest

Medium
Smart contracts

no reentrancy guard on mint() function that has a callback

The mint() function in CollateralizedDebt.sol calls _safeMint(), which invokes a callback to the recipient address. Without a reentrancy guard, a malicious recipient could re-enter the function during that callback, potentially causing unexpected behaviour.

Timeswap contest

Medium
Business logic

users might pay enormous amounts of gas

When a user mints liquidity for a pair that does not exist, the contract deploys a new pair contract, which is very expensive on Ethereum. The user ends up paying thousands of dollars in gas fees.

Timeswap contest

Medium
Business logic

Convenience contract fails to function if asset or collateral is an ERC20 token with fees

The Convenience contract sends a flat token amount when calling the Pair contract, but if the token charges a transfer fee, the Pair receives less than expected and reverts. This makes the Convenience contract unusable with fee-on-transfer tokens, and outgoing transfers may deliver less collateral to the borrower.

Timeswap contest

Medium
Business logic

Manipulation of the Y State Results in Interest Rate Manipulation

The TimeswapPair.mint function lacked constraints on user input, allowing an attacker to manipulate the pool's interest rate by making a tiny mint. This could hyper-inflate the interest rate, harming liquidity providers and other pool members.

Timeswap contest

High