Skip to content
Business logic Audit finding Advanced

LienToken.transferFrom There is a possibility of malicious attack

The LienToken contract restricts transfers to public vault addresses, but an attacker can predict a public vault's address and front-run its creation by transferring a private vault's LienToken to that address. This corrupts the public vault's accounting variables, causing it to malfunction.

bin2chen Follow

Originally disclosed on Code4rena

Submitted by bin2chen

https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/LienToken.sol#L366-L368

Corrupt multiple key properties of public vault, causing vault not to function properly.

Proof of Concept

When LienToken.makePayment()/buyoutLien()/payDebtViaClearingHouse() If it corresponds to PublicVault, it will make multiple changes to the vault, such as: yIntercept, slope, last, epochData, etc.

If LienToken corresponds to PublicVault, then ownerOf(lienId) = PublicVault address

When the LienToken is a private vault, it is possible to transfer the owner of the LienToken.

As the above seems, if the private vault is transferred to the PublicVault address will result in the wrong modification of the yIntercept, slope, last, epochData, etc.

So we restrict the to in transferFrom to not be a PublicVault address

  function transferFrom(
    address from,
    address to,
    uint256 id
  ) public override(ERC721, IERC721) {

    if (_isPublicVault(s, to)) {  //***@audit when to == PublicVault address , will revert
      revert InvalidState(InvalidStates.PUBLIC_VAULT_RECIPIENT);
    }

However, such a restriction does not prevent an attacker from transferring PrivateVault’s LienToken to PublicVault. Because the address is predictable when the vault contract is created, a malicious user can predict the vault address, front-run, and transfer PrivateVault’s LienToken to the predicted PublicVault address before the public vault is created, thus bypassing this restriction

Assumptions:

  1. alice creates PrivateVault, and creates multiple PrivateVault’s LienToken
  2. alice monitors bob’s creation of the PublicVault transaction, i.e., AstariaRouter.newPublicVault(), and then predicts the address of the newly generated treasure chest

Note: newPublicVAult() although the use of create(), but still can predict the address

see:https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed

The address for an Ethereum contract is deterministically computed from the address of its creator (sender) and how many transactions the creator has sent (nonce). The sender and nonce are RLP encoded and then hashed with Keccak-256.

  1. front-run , and transfer LienToken to public vault predict address
  2. bob’s public vault created success and do some loan
  3. alice do makePayment() to Corrupt bob’s public vault

Recommended Mitigation Steps

The corresponding vault address is stored in s.lienMeta[id].orginOwner when the LienToken is created, this is not modified. Get the vault address from this variable, not from ownerOf(id).

androolloyd (Astaria) confirmed


The original report as published on Code4rena, by bin2chen. 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 transfer restriction checks the recipient address at transfer time, but the recipient vault may not yet exist, so a predicted address bypasses the check.

Impact

The public vault's key accounting variables (yIntercept, slope, last, epochData) could be corrupted, causing the vault to not function properly.

What the attacker needed

Attacker creates a PrivateVault and LienTokens; attacker can front-run vault creation; victim creates a PublicVault

The fix

The vault address should be stored in s.lienMeta[id].orginOwner at LienToken creation and used instead of ownerOf(id).

How it was found

  1. Alice creates a PrivateVault and multiple LienTokens for it.
  2. Alice monitors Bob's transaction to create a PublicVault and predicts the new vault's address.
  3. Alice front-runs and transfers her LienToken to the predicted public vault address.
  4. Bob's public vault is created and processes some loans.
  5. Alice calls makePayment() to corrupt Bob's public vault.

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 called LienToken tracks ownership of loans. The code tries to stop people sending these tokens to a public vault, but an attacker can guess the vault's future address and send the token there before the vault exists. When the vault is created, it already owns a token it should not, which breaks its internal accounting.

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 bin2chen

View all

139 more disclosed reports, best first.

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.