Skip to content
DoS Audit finding Intermediate

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.

sirhashalot Follow

Originally disclosed on Code4rena

Submitted by sirhashalot

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

The root cause of the issue is that the safeSymbol() 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 symbol() functions in the Timeswap ERC20 contracts to revert.

Because this is known to cause issues with tokens that don’t fully follow the ERC20 spec, the safeSymbol() function in the BoringCrypto library has a fix for this. The BoringCrypto safeSymbol() 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-L39

Proof of Concept

The root cause is line 20 of the safeSymbol() function in SafeMetadata.sol

The safeSymbol() function is called in:

Recommended Mitigation Steps

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

Mathepreneur (Timeswap) confirmed and resolved:

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

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 safeSymbol() function assumes the token's symbol return value is a string and does not handle the bytes32 case, so abi.decode() reverts.

Impact

The symbol() functions in four Timeswap convenience contracts could revert for certain asset pairs, making those contracts non-compliant with the ERC20 standard.

What the attacker needed

Asset pair includes a token returning bytes32 symbol

The fix

The safeSymbol() function should be replaced with the BoringCrypto version that includes a returnDataToString() parsing function to handle bytes32 return values; the project confirmed and resolved the issue.

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.

ERC20 tokens are supposed to return their symbol as text, but some older tokens return it as a fixed-size value instead. The code here only handles the text case, so calling symbol() on those tokens fails and the whole function stops with an error. That means the contract does not behave like a normal ERC20 token for those pairs.

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.