Skip to content
Access control Audit finding Advanced

Attacker contract can avoid being blocked by BlockList.sol

The blocklist only blocks addresses that are contracts, checked by code length. An attacker can use a contract that self-destructs and is recreated at the same address with CREATE2 to bypass the blocklist and interact with the system.

JohnSmith Follow

Originally disclosed on Code4rena

Submitted by JohnSmith, also found by ayeslick, reassor, rokinot, and scaraven

To block an address it must pass the isContract(address) check: https://github.com/code-423n4/2022-08-fiatdao/blob/main/contracts/features/Blocklist.sol#L25

contracts/features/Blocklist.sol
25:         require(_isContract(addr), "Only contracts");

Which just checks code length at the address provided.

contracts/features/Blocklist.sol
37:     function _isContract(address addr) internal view returns (bool) {
38:         uint256 size;
39:         assembly {
40:             size := extcodesize(addr)
41:         }
42:         return size > 0;
43:     }

Attacker can interact with the system and selfdestruct his contract, and with help of CREATE2 recreate it at same address when he needs to interact with the system again.

Proof of concept

Below is a simple example of salted contract creation, which you can test against _isContract(address) function.

pragma solidity 0.8.15;

contract BlockList {
    function _isContract(address addr) external view returns (bool) {
        uint256 size;
        assembly {
            size := extcodesize(addr)
        }
        return size > 0;
    }
}

contract AttackerContract {
  function destroy() external {
    selfdestruct(payable(0));
  }
}

contract AttackerFactory {
    function deploy() external returns (address) {
        return address(new AttackerContract{salt: bytes32("123")}());
    }
}

Recommended Mitigation Steps

One of the goals of Ethereum is for humans and smart contracts to both be treated equally. This leads into a future where smart contracts interact seamlessly with humans and other contracts. It might change in the future , but for now an arbitrary address is ambiguous. We should consider blacklisting addresses without checking if they are contracts.

lacoop6tu (FIAT DAO) commented:

Duplicate of #168

Justin Goro (judge) commented:

This is a valid attack vector that undermines the blocking mechanism and is not a duplicate of #168.

lacoop6tu (FIAT DAO) commented:

IMO this is more acknowledged in this case, the only interaction possible is locking LP tokens first so if someone then selfdestructs, another attacker could create a contract with that address and take ownership (and quitLock for example) similar to what happened with optimism and wintermute.

Justin Goro (judge) commented:

The reason it’s maintained as a medium risk is because there is a bit of circumventing of protocol restrictions. But as you indicated, it’s not serious enough that marking it acknowledged is irresponsible.

elnilz (FIAT DAO) acknowledged

IllIllI (warden) reviewed mitigation:

The sponsor acknowledges that the BlockList can be bypassed, but states that “the only interaction possible is locking LP tokens first”. However, looking at the code, the checkBlocklist modifier is applied to not just createLock(), but increaseAmount(), increaseUnlockTime(), and delegate(). An attacker can bypass the block list for every one of these functions by making their SmartWallet a specially-constructed create2() contract that does external calls to an other contract in its constructor, for instructions on what to execute, before self-destructing. Whenever the attacker wants to interact with the token, they update their external instruction-providing contract with the action to take, re-create the attack contract. It’s not clear why the block list is only for contracts, and if it can be bypassed by using this method, or by transferring the tokens to an EOA.

In discussions of the issue, the sponsor clarified that the BlockList’s purpose is to prevent lock tokenization, and acknowledged that using an updated BlockList that blocks specific EOAs may be required if an attacker uses the features described above to work around being blocked.


The original report as published on Code4rena, by JohnSmith. 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 blocklist relies on checking whether an address has code, which can be bypassed by temporarily removing the code via self-destruct and recreating the contract at the same address.

Impact

An attacker could bypass the blocklist and interact with functions such as createLock, increaseAmount, increaseUnlockTime, and delegate, potentially locking LP tokens and later taking ownership if the contract is recreated.

What the attacker needed

Ability to deploy contracts; use of CREATE2; self-destruct capability

The fix

The blocklist should consider blocking addresses without checking if they are contracts, and may need to block specific externally owned accounts.

How it was found

  1. Deploy a contract at a known address using CREATE2 with a salt.
  2. Interact with the system using that contract.
  3. Self-destruct the contract to remove its code.
  4. Recreate the contract at the same address using CREATE2 when needed again.

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 is a program on the blockchain that lives at an address. The blocklist tried to block bad actors by only allowing contracts to be blocked, but a contract can be removed and later recreated at the same address, so the block can be avoided.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by JohnSmith

View all

2 more disclosed reports, best first.

More from FIAT DAO veFDT contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.