Skip to content
DoS Audit finding Intermediate

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.

sirhashalot Follow

Originally disclosed on Code4rena

Submitted by sirhashalot

The safeName() function, found in the SafeMetadata.sol contract and called in 4 Timeswap Convenience contracts in the name() functions, can cause a revert. This could make the 4 contracts not compliant with the ERC20 standard for certain asset pairs, because the name() function should return a string and not revert.

The root cause of the issue is that the safeName() function assumes the return type of any ERC20 token to be a string. If the return value is not a string, abi.decode() will revert, and this will cause the name() functions in the Timeswap ERC20 contracts to revert. There are some tokens that aren’t compliant, such as Sai from Maker, which returns a bytes32 value: https://kauri.io/#single/dai-token-guide-for-developers/#token-info

Because this is known to cause issues with tokens that don’t fully follow the ERC20 spec, the safeName() function in the BoringCrypto library has a fix for this. The BoringCrypto safeName() function is similar to the one in Timeswap but it has a returnDataToString() function that handles the case of a bytes32 return value for a token name: https://github.com/boringcrypto/BoringSolidity/blob/ccb743d4c3363ca37491b87c6c9b24b1f5fa25dc/contracts/libraries/BoringERC20.sol#L15-L47

Proof of Concept

The root cause is line 12 of the safeName() function in SafeMetadata.sol

The safeName() function is called in:

Recommended Mitigation Steps

Use the BoringCrypto safeName() function code to handle the case of a bytes32 return value: https://github.com/boringcrypto/BoringSolidity/blob/ccb743d4c3363ca37491b87c6c9b24b1f5fa25dc/contracts/libraries/BoringERC20.sol#L15-L47

Mathepreneur (Timeswap) confirmed and resolved:

https://github.com/Timeswap-Labs/Timeswap-V1-Convenience/pull/60

The original report as published on Code4rena, by sirhashalot. 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 safeName() function assumes the token's name() returns a string and uses abi.decode() without handling other return types like bytes32.

Impact

The four contracts could revert when name() is called for tokens that return bytes32, making them non-compliant with ERC20 and potentially causing a denial of service for those asset pairs.

What the attacker needed

Token returns bytes32 for name()

The fix

The safeName() function should be updated to handle bytes32 return values, as done in the BoringCrypto library.

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.

Some digital tokens don't follow the usual rule for how they report their name. The code here expects a text string, but if a token gives a different format, the code crashes. This crash stops four contracts from working properly for those tokens.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by sirhashalot

View all

10 more disclosed reports, best first.

More from Timeswap contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.