Skip to content
Business logic Audit finding Intermediate

Solmate safetransfer and safetransferfrom does not check the codesize of the token address, which may lead to fund loss

The safeTransfer and safeTransferFrom functions from Solmate do not verify that the token address contains contract code. An attacker could call these functions on an address without code, causing the protocol to falsely record a successful transfer and leading to miscalculated funds and potential loss.

djxploit Follow

Originally disclosed on Code4rena

Submitted by djxploit, also found by brgltd

In getloan() and replayloan(), the safetransfer and safetransferfrom doesn’t check the existence of code at the token address. This is a known issue while using solmate’s libraries. Hence this may lead to miscalculation of funds and may lead to loss of funds , because if safetransfer() and safetransferfrom() are called on a token address that doesn’t have contract in it, it will always return success, bypassing the return value check. Due to this protocol will think that funds has been transferred and successful , and records will be accordingly calculated, but in reality funds were never transferred. So this will lead to miscalculation and possibly loss of funds

Proof of Concept

https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/TRSRY.sol#L110 https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/TRSRY.sol#L99

Recommended Mitigation Steps

Use openzeppelin’s safeERC20 or implement a code existence check.

ind-igo (Olympus) confirmed and commented:

Confirmed. Will implement this. Thank you.


The original report as published on Code4rena, by djxploit. 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

Likely, the safeTransfer and safeTransferFrom functions from Solmate do not check whether the token address has code, so calls to non-contract addresses return success without transferring tokens.

Impact

This may lead to miscalculation of funds and possibly loss of funds, as the protocol records transfers that never occurred.

What the attacker needed

Token address without contract code

The fix

Use OpenZeppelin's safeERC20 or implement a code existence check.

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.

When a smart contract sends tokens, it usually calls a function on the token's contract. If the token address is not actually a contract (for example, a regular wallet address), the call still succeeds but does nothing. The protocol then thinks the transfer happened and updates its records, even though no tokens moved. This can lead to wrong balances and lost funds.

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 djxploit

View all

4 more disclosed reports, best first.

More from Olympus DAO contest

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.