Skip to content
Business logic Audit finding Advanced

Vault can be created for not-yet-existing ERC20 tokens, which allows attackers to set traps to steal NFTs from Borrowers

The protocol's token transfer helper does not verify that a token address contains contract code, so transfers to non-existent tokens silently succeed. An attacker could create vaults for token addresses not yet deployed and later profit when a real token is deployed at that address and users deposit into the trap vault.

pwnforce Follow

Originally disclosed on Code4rena

Submitted by pwnforce

There is a subtle difference between the implementation of solmate’s SafeTransferLib and OZ’s SafeERC20: OZ’s SafeERC20 checks if the token is a contract or not, solmate’s SafeTransferLib does not. See: https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol#L9 Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller. As a result, when the token’s address has no code, the transaction will just succeed with no error. This attack vector was made well-known by the qBridge hack back in Jan 2022.

In AstariaRouter, Vault, PublicVault, VaultImplementation, ClearingHouse, TransferProxy, and WithdrawProxy, the safetransfer and safetransferfrom don’t check the existence of code at the token address. This is a known issue while using solmate’s libraries.

Hence this can lead to miscalculation of funds and also 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. 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 loss of funds.

Attack scenario (example):

It’s becoming popular for protocols to deploy their token across multiple networks and when they do so, a common practice is to deploy the token contract from the same deployer address and with the same nonce so that the token address can be the same for all the networks.

A sophisticated attacker can exploit it by taking advantage of that and setting traps on multiple potential tokens to steal from the borrowers. For example: 1INCH is using the same token address for both Ethereum and BSC; Gelato’s $GEL token is using the same token address for Ethereum, Fantom and Polygon.

  • ProjectA has TokenA on another network;
  • ProjectB has TokenB on another network;
  • ProjectC has TokenC on another network;
  • A malicious strategist (Bob) can create new PublicVaults with amounts of 10000E18 for TokenA, TokenB, and TokenC.
  • A few months later, ProjectB lunched TokenB on the local network at the same address;
  • Alice as a liquidator deposited 11000e18 TokenB into the vault;
  • The attacker (Bob) can withdraw to receive most of Alice’s added TokenB.

Proof of Concept

https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/AstariaRouter.sol#L490 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/AstariaRouter.sol#L795 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/Vault.sol#L66 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/Vault.sol#L72 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/PublicVault.sol#L384 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/VaultImplementation.sol#L394 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/VaultImplementation.sol#L406 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/ClearingHouse.sol#L143 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/ClearingHouse.sol#L161 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/TransferProxy.sol#L34 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/WithdrawProxy.sol#L269 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/WithdrawProxy.sol#L281 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/WithdrawProxy.sol#L298

Recommended Mitigation Steps

This issue won’t exist if OpenZeppelin’s SafeERC20 is used instead.

androolloyd (Astaria) commented:

The protocol has no enforcement of the assets that can be listed, only tokens that are known should be interacted with by users and UI implementations.

SantiagoGregory (Astaria) confirmed

Picodes (judge) decreased severity to Medium and commented:

Keeping this report as medium due to the credibility of the attack path described.


The original report as published on Code4rena, by pwnforce. 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 protocol used a token transfer library that does not check whether the token address actually contains contract code, so calls to empty addresses return success without moving funds.

Impact

An attacker could steal tokens deposited by other users into a trap vault, though the protocol team argued that only known tokens should be used by users and the UI.

What the attacker needed

Attacker can create vaults; victim deposits into trap vault; token deployed later at same address

The fix

The issue should be fixed by using OpenZeppelin's SafeERC20, which checks that the token address contains code.

How it was found

  1. A malicious strategist creates new PublicVaults for token addresses that do not yet have code on the local network.
  2. Later, a real project deploys its token at one of those same addresses.
  3. A user deposits that token into the vault.
  4. The attacker withdraws and receives most of the deposited tokens.

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 can call another address to move tokens, but if that address has no code yet, the call still reports success. The protocol trusted that success message and updated its records as if real tokens had moved. An attacker could set up a vault for a token that does not exist yet, wait for the real token to appear at that address, and then take funds from anyone who deposits.

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 from Astaria 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.