Skip to content
Access control Audit finding Advanced

A malicious borrower can hijack any NFT with permit() function he rents.

ReNFT does not account for rented ERC-721 tokens that implement the ERC-4494 permit() function, so a malicious borrower can sign a permit approval for their own address and have the rental safe (the token owner) validate it via EIP-1271. This lets the attacker approve themselves and transfer the rented NFT out of the safe, hijacking it from the lender.

sin1st3r__ Follow

Originally disclosed on Code4rena

Submitted by sin1st3r__

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


  1. ERC-4494: Permit for ERC-721 NFTs: ERC721-Permit is very similar to ERC20-permit (EIP-2612). ERC721 Permit adds a new permit() function. It allows user can sign an ERC721 approve transaction off-chain producing a signature that anyone could use and submit to the permit function. When permit is executed, it will execute the approve function. This allows for meta-transaction support of ERC721 transfers, but it also simply gets rid of the annoyance of needing two transactions: approve and transferFrom. Additionally, ERC721-Permit, just like ERC20 permit, prevents misuse and replay attacks. A replay attack is when a valid signature is used several times or in places where it’s not intended to be used in.

    You can find an implementation of it here, by uniswap: https://github.com/Uniswap/v3-periphery/blob/main/contracts/base/ERC721Permit.sol


The Vulnerability & Exploitation Steps


ReNFT doesn’t account for ERC721 implementing the permit() function, allowing a malicious borrower to hijack the token by producing a signature and feeding it to the permit() function requesting it to approve his address to transfer the token

Exploitation Steps

  1. The attacker rents the NFT token in his rental safe
  2. The attacker creates a signature which he will need to feed to the permit() function. The signature is a signed data including info like: 1. the deadline (until when the signature would be valid), 2. the token ID he wants to approve his address to spend, 3. the spender, in this case it’s the attacker’s address (Look at the PoC to see how it’s generated)
  3. The attacker calls permit() funtion and gives it the signature along with the deadline, approved address and the spender.
  4. The permit() function will reach out to the attacker’s rental safe (since it is the owner of the token and since it’s a smart contract verifying the signature (EIP-1271) ), asking it if the signature is valid
  5. The rental safe will verify the signature and confirm that it’s the attacker (owner of the safe) who signed the transaction
  6. permit() will approve the attacker’s address to spend the token on behalf of the attacker’s safe (token is owned by the safe)
  7. Attacker will then transfer the token out of his safe.

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_NFT_Permit_Exploit -vvv

Note: All of my 7 PoCs throughout my reports include the SetupExploit.sol. Please do not rely on the previous SetupExploit.sol file if you already had one from another PoC run in the tests/ folder. In some PoCs, there are slight modifications done in that file to properly set up the test infrastructure needed for the exploit

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 {Test} from "@forge-std/Test.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 {Safe} from "@safe-contracts/Safe.sol";
// import {BaseExternal} from "@test/fixtures/external/BaseExternal.sol";
import {SafeProxyFactory} from "@safe-contracts/proxies/SafeProxyFactory.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 {HandlerContext} from "@safe-contracts/handler/HandlerContext.sol";
import {CompatibilityFallbackHandler} from "@safe-contracts/handler/CompatibilityFallbackHandler.sol";

import {ISignatureValidator} from "@safe-contracts/interfaces/ISignatureValidator.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";

import {Seaport} from "@seaport-core/Seaport.sol";
import {ConduitController} from "@seaport-core/conduit/ConduitController.sol";
import {ConduitControllerInterface} from "@seaport-types/interfaces/ConduitControllerInterface.sol";
import {ConduitInterface} from "@seaport-types/interfaces/ConduitInterface.sol";

import "@forge-std/console.sol";

// Deploys all Seaport protocol contracts
contract External_Seaport is Test {
    // seaport protocol contracts
    Seaport public seaport;
    ConduitController public conduitController;
    ConduitInterface public conduit;

    // conduit owner and key
    Vm.Wallet public conduitOwner;
    bytes32 public conduitKey;

    function setUp() public virtual {
        // generate conduit owner wallet
        conduitOwner = vm.createWallet("conduitOwner");

        // deploy conduit controller
        conduitController = new ConduitController();

        // deploy seaport
        seaport = new Seaport(address(conduitController));

        // create a conduit key (first 20 bytes must be conduit creator)
        conduitKey = bytes32(uint256(uint160(conduitOwner.addr))) << 96;

        // create a new conduit
        vm.prank(conduitOwner.addr);
        address conduitAddress = conduitController.createConduit(
            conduitKey,
            conduitOwner.addr
        );

        // set the conduit address
        conduit = ConduitInterface(conduitAddress);

        // open a channel for seaport on the conduit
        vm.prank(conduitOwner.addr);
        conduitController.updateChannel(address(conduit), address(seaport), true);

        // label the contracts
        vm.label(address(seaport), "Seaport");
        vm.label(address(conduitController), "ConduitController");
        vm.label(address(conduit), "Conduit");
    }
}

// Deploys the Create2Deployer contract
contract External_Create2Deployer is Test {
    Create2Deployer public create2Deployer;

    function setUp() public virtual {
        // Deploy the create2 deployer contract
        create2Deployer = new Create2Deployer();

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

// Deploys all Gnosis Safe protocol contracts
contract External_Safe is Test {
    SafeL2 public safeSingleton;
    SafeProxyFactory public safeProxyFactory;

    CompatibilityFallbackHandler public fallbackHandler;

    function setUp() public virtual {
        // Deploy safe singleton contract
        safeSingleton = new SafeL2();

        // Deploy safe proxy factory
        safeProxyFactory = new SafeProxyFactory();

        // Deploy the compatibility token handler
        fallbackHandler = new CompatibilityFallbackHandler();

        // Label the contracts
        vm.label(address(safeSingleton), "SafeSingleton");
        vm.label(address(safeProxyFactory), "SafeProxyFactory");
        vm.label(address(fallbackHandler), "TokenCallbackHandler");
    }
}

contract BaseExternal is External_Create2Deployer, External_Seaport, External_Safe {
    // This is an explicit entrypoint for all external contracts that the V3 protocol depends on.
    //
    // It contains logic for:
    // - setup of the Create2Deployer contract
    // - setup of all Seaport protocol contracts
    // - setup of all Gnosis Safe protocol contracts
    //
    // The inheritance chain is as follows:
    // External_Create2Deployer + External_Seaport + External_Safe
    // --> BaseExternal

    function setUp()
        public
        virtual
        override(External_Create2Deployer, External_Seaport, External_Safe)
    {
        // set up dependencies
        External_Create2Deployer.setUp();
        External_Seaport.setUp();
        External_Safe.setUp();
    }
}

// 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(fallbackHandler),
                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();
    }
}

// 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(
            erc721Considerations,
            erc1155Considerations,
            erc20Considerations
        );

        // Create order metadata
        _createOrderMetadata(orderType);
    }

    // Creates an offerer on the order to create
    function _createOfferer(ProtocolAccount memory offerer) private {
        orderToCreate.offerer = offerer;
    }

    // Creates offer items which are good for most tests
    function _createOfferItems(
        uint256 erc721Offers,
        uint256 erc1155Offers,
        uint256 erc20Offers
    ) private {
        // generate the ERC721 offer items
        for (uint256 i = 0; i < erc721Offers; ++i) {
            // create the offer item
            orderToCreate.offerItems.push(
                OfferItemLib
                    .empty()
                    .withItemType(ItemType.ERC721)
                    .withToken(address(erc721s[i]))
                    .withIdentifierOrCriteria(usedOfferERC721s[i])
                    .withStartAmount(1)
                    .withEndAmount(1)
            );

            // mint an erc721 to the offerer
            erc721s[i].mint(orderToCreate.offerer.addr);

            // update the used token so it cannot be used again in the same test
            usedOfferERC721s[i]++;
        }

        // generate the ERC1155 offer items
        for (uint256 i = 0; i < erc1155Offers; ++i) {
            // create the offer item
            orderToCreate.offerItems.push(
                OfferItemLib
                    .empty()
                    .withItemType(ItemType.ERC1155)
                    .withToken(address(erc1155s[i]))
                    .withIdentifierOrCriteria(usedOfferERC1155s[i])
                    .withStartAmount(100)
                    .withEndAmount(100)
            );

            // mint an erc1155 to the offerer
            erc1155s[i].mint(orderToCreate.offerer.addr, 100);

            // update the used token so it cannot be used again in the same test
            usedOfferERC1155s[i]++;
        }

        // generate the ERC20 offer items
        for (uint256 i = 0; i < erc20Offers; ++i) {
            // create the offer item
            orderToCreate.offerItems.push(
                OfferItemLib
                    .empty()
                    .withItemType(ItemType.ERC20)
                    .withToken(address(erc20s[i]))
                    .withStartAmount(100)
                    .withEndAmount(100)
            );
        }
    }

    // Creates consideration items that are good for most tests
    function _createConsiderationItems(
        uint256 erc721Considerations,
        uint256 erc1155Considerations,
        uint256 erc20Considerations
    ) private {
        // generate the ERC721 consideration items
        for (uint256 i = 0; i < erc721Considerations; ++i) {
            // cre

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 protocol's rental safe and guard logic do not block or account for ERC-721 tokens exposing a permit() approval function, so the borrower-controlled safe can be tricked into approving the borrower.

Impact

A malicious borrower could hijack any rented NFT whose contract implements permit(), stealing it from the lender.

What the attacker needed

The rented NFT implements permit(); attacker can rent the NFT; attacker controls their rental safe

How it was found

  1. The attacker rents the NFT into their rental safe.
  2. The attacker creates a signed permit message approving their own address for the token.
  3. The attacker calls permit() with the signature, deadline, approved address and spender.
  4. The permit() function asks the attacker's rental safe, as token owner, to validate the signature via EIP-1271.
  5. The safe confirms the attacker (its owner) signed, and permit() approves the attacker's address.
  6. The attacker transfers the token out of the safe.

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.

Some NFTs support a feature called permit, where the owner can approve someone to move the token using a signed message instead of a normal on-chain approval. When you rent an NFT through this protocol, the rented token sits in a smart contract wallet (a safe) that you control. Because the protocol never blocked this permit feature, the borrower can sign an approval themselves, the safe accepts it, and the borrower walks away with the NFT.

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

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.