Skip to content
Business logic Audit finding Intermediate

Malicious Token Contracts May Lead To Locking Orders

A maker could include a malicious token contract in an order, which would revert when the taker tried to exercise or withdraw, locking the taker's assets. The attacker could then wait until the option expired or the price moved in their favour before allowing transfers.

kirk-baird Follow

Originally disclosed on Code4rena

Submitted by kirk-baird, also found by 0xA5DF, cccz, chatch, csanuragjain, Alex the Entreprenerd, hansfriese, hyh, itsmeSTYJ, Kenshin, pedroais, sashiketh, unforgiven, and xiaoming90_

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L79

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L80

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L81

https://github.com/code-423n4/2022-06-putty/blob/3b6b844bc39e897bd0bbb69897f2deff12dc3893/contracts/src/PuttyV2.sol#L72

Impact

It is possible to prevent an order from executing exercise() or withdraw() by having a malicious token contract included in the order as part of the any of the following fields.

  • baseAsset
  • floorTokens[]
  • erc20Assets[]
  • erc721Assets[]

An attacker as a maker may create an order and set one of these addresses to a malicious contract in the attackers control. The attacker allows the user to fill the order then toggles a variable on the malicious contract which always causes it to revert.

The attacker benefits by preventing orders from being exercise() if they are in an undesirable position (e.g. if they have gone short and the price has gone up). The attacker waits for either the time to expire or the price to go down and allows transfers to occur on their malicious token.

Similar attacks can also be performed over the withdraw() function since this also makes calls to untrusted external addresses. This would allow an attacker to exercise an option then prevent the other user from claiming any of the NFTs or ERC20 tokens that are owed to them.

Proof of Concept

Any of the transfers in exercise make external calls to untrusted addresses.

    function exercise(Order memory order, uint256[] calldata floorAssetTokenIds) public payable {
        /* ~~~ CHECKS ~~~ */

        bytes32 orderHash = hashOrder(order);

        // check user owns the position
        require(ownerOf(uint256(orderHash)) == msg.sender, "Not owner");

        // check position is long
        require(order.isLong, "Can only exercise long positions");

        // check position has not expired
        require(block.timestamp < positionExpirations[uint256(orderHash)], "Position has expired");

        // check floor asset token ids length is 0 unless the position type is put
        !order.isCall
            ? require(floorAssetTokenIds.length == order.floorTokens.length, "Wrong amount of floor tokenIds")
            : require(floorAssetTokenIds.length == 0, "Invalid floor tokenIds length");

        /* ~~~ EFFECTS ~~~ */

        // send the long position to 0xdead.
        // instead of doing a standard burn by sending to 0x000...000, sending
        // to 0xdead ensures that the same position id cannot be minted again.
        transferFrom(msg.sender, address(0xdead), uint256(orderHash));

        // mark the position as exercised
        exercisedPositions[uint256(orderHash)] = true;

        emit ExercisedOrder(orderHash, floorAssetTokenIds, order);

        /* ~~~ INTERACTIONS ~~~ */

        if (order.isCall) {
            // -- exercising a call option

            // transfer strike from exerciser to putty
            // handle the case where the taker uses native ETH instead of WETH to pay the strike
            if (weth == order.baseAsset && msg.value > 0) {
                // check enough ETH was sent to cover the strike
                require(msg.value == order.strike, "Incorrect ETH amount sent");

                // convert ETH to WETH
                // we convert the strike ETH to WETH so that the logic in withdraw() works
                // - because withdraw() assumes an ERC20 interface on the base asset.
                IWETH(weth).deposit{value: msg.value}();
            } else {
                ERC20(order.baseAsset).safeTransferFrom(msg.sender, address(this), order.strike);
            }

            // transfer assets from putty to exerciser
            _transferERC20sOut(order.erc20Assets);
            _transferERC721sOut(order.erc721Assets);
            _transferFloorsOut(order.floorTokens, positionFloorAssetTokenIds[uint256(orderHash)]);
        } else {
            // -- exercising a put option

            // save the floor asset token ids to the short position
            uint256 shortPositionId = uint256(hashOppositeOrder(order));
            positionFloorAssetTokenIds[shortPositionId] = floorAssetTokenIds;

            // transfer strike from putty to exerciser
            ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike);

            // transfer assets from exerciser to putty
            _transferERC20sIn(order.erc20Assets, msg.sender);
            _transferERC721sIn(order.erc721Assets, msg.sender);
            _transferFloorsIn(order.floorTokens, floorAssetTokenIds, msg.sender);
        }
    }

The attacker must control one of these contracts and have it set as a malicious ERC20 / ERC721 function that fails under attacker controlled conditions.

Recommended Mitigation Steps

Consider whitelisting approved ERC20 token or ERC721 address contracts to prevent users setting malicious token contracts. However, this remediation will have a significant admin input / gas trade-offs.

outdoteth (Putty Finance) acknowledged and commented:

Technically this is a valid finding. However we don’t intend to fix this at the contract level. Instead there will be adequate warnings on the UI to inform a user that they should be vigilant for any tokens that are not verified by putty (in addition, the UI will show the unverified token’s logo as a question mark instead of as the token’s logoURI).

Report: Setting malicious or invalid erc721Assets, erc20Assets or floorTokens prevents the option from being exercised.

HickupHH3 (judge) commented:

It’s contingent on the external requirement for the attacker to be in control of a malicious ERC20 or NFT. Hence, medium severity is appropriate: 2-Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.

Pedroais (warden) commented:

I will argue why this issue should be high severity instead of medium.

“It’s contingent on the external requirement for the attacker to be in control of a malicious ERC20 or NFT. ”

Anyone can deploy a malicious contract and pass it as an ERC20 or NFT. This is not an external requirement, anyone can do it. Any malicious contract deployed by the attacker will work.

This issue imposes a risk of asset loss to users without external requirements. The sponsor states unknown tokens will be shown with a question mark in the UI. This is ok but I think the attack is high severity since the user would be reasonable to think if he is accepting an offer for a BAYC (example of an expensive NFT) and some unknown token that in the worse case he should at least get the BAYC. This attack doesn’t require the user to be dumb or act recklessly but just normal functioning of the protocol. The fake token shouldn’t prevent the user from exercising the real BAYC.

A user would be reasonable to expect to at least be able to exercise the real NFT in a case with an option that includes a real NFT and a malicious one. The problem is the malicious NFT can block the exercise of the real NFT. An option can be created using many real and valuable tokens with just 1 malicious token that prevents exercising the real ones.

I hope the judge can consider these arguments and make his decision.

HickupHH3 (judge) commented:

I should have phrased it better. The external requirement isn’t on the attacker being in control of the malicious ERC20 / NFT. As rightfully pointed out, it can be easily done.

The external requirement here is the user deciding to fill an option containing malicious assets. Such options can be considered to be honeypots that users should be made aware of (eg. through documentation, PSAs or warnings to the user). There’s only so much the protocol can do to protect users, with tradeoffs against centralisation risks if the suggestion of whitelisting assets is adopted.

This attack doesn’t require the user to be dumb or act recklessly but just normal functioning of the protocol. The fake token shouldn’t prevent the user from exercising the real BAYC.

Partial exercising of options could be a feature, but opens up new attack surfaces and would be a non-trivial to implement. It is a limitation of the protocol that should be clearly communicated to users.

hyh (warden) reviewed mitigation:

Now addressed on UI/DB level.


The original report as published on Code4rena, by kirk-baird. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

Putty is an on-chain options protocol. A maker creates an order describing an option position, and a taker fills it. The resulting position is an NFT whose owner can later call exercise() to settle the option, or withdraw() to collect the assets owed to them. The order carries several asset fields: baseAsset (the strike asset, an ERC20), floorTokens[], erc20Assets[] and erc721Assets[]. When a position is exercised or withdrawn, the contract transfers these assets to and from the parties involved.

The finding was reported in the Code4rena audit of the Putty codebase (2022-06-putty), against contracts/src/PuttyV2.sol. It was submitted by kirk-baird and independently found by 0xA5DF, cccz, chatch, csanuragjain, Alex the Entreprenerd, hansfriese, hyh, itsmeSTYJ, Kenshin, pedroais, sashik*eth, unforgiven and xiaoming90. The judge rated it medium severity.

Setup

The report describes no accounts, tooling or versions. The precondition is simply that an attacker controls a token contract (ERC20 or ERC721) and can get its address into one of the asset fields of an order. The relevant code is the exercise() function in PuttyV2.sol (lines 389 to 458 in the audited commit), and the report also points at lines 72, 79, 80 and 81 of the same file, which are where the order's asset fields are declared.

Finding it

The researcher noticed that every transfer performed inside exercise() is an external call to an address supplied by the order, and that those addresses are not restricted to known or verified tokens. If any one of them is a contract that reverts, the whole exercise() call reverts with it. The same reasoning applies to withdraw(), which also makes calls to untrusted external addresses.

The four fields that can carry such a contract are:

  • baseAsset
  • floorTokens[]
  • erc20Assets[]
  • erc721Assets[]

Exploitation

Step 1: create the order with a malicious token

An attacker acting as maker creates an order and sets one of the addresses above to a malicious contract under their control.

Step 2: let the taker fill the order

The attacker allows the user to fill the order. At this point the taker holds a position that can be exercised.

Step 3: toggle the malicious contract to revert

The attacker flips a variable on the malicious contract so that any transfer involving it always reverts. From then on, exercise() on that position fails.

Step 4: choose when to release

The attacker keeps the position blocked while it is unfavourable, for example if they have gone short and the price has gone up. They wait for the position to expire or for the price to move back down, then allow transfers on the malicious token again.

The report shows the exercise() function as the proof of concept, noting that any of the transfers in it make external calls to untrusted addresses:

Solidity
    function exercise(Order memory order, uint256[] calldata floorAssetTokenIds) public payable {
        /* ~~~ CHECKS ~~~ */

        bytes32 orderHash = hashOrder(order);

        // check user owns the position
        require(ownerOf(uint256(orderHash)) == msg.sender, "Not owner");

        // check position is long
        require(order.isLong, "Can only exercise long positions");

        // check position has not expired
        require(block.timestamp < positionExpirations[uint256(orderHash)], "Position has expired");

        // check floor asset token ids length is 0 unless the position type is put
        !order.isCall
            ? require(floorAssetTokenIds.length == order.floorTokens.length, "Wrong amount of floor tokenIds")
            : require(floorAssetTokenIds.length == 0, "Invalid floor tokenIds length");

        /* ~~~ EFFECTS ~~~ */

        // send the long position to 0xdead.
        // instead of doing a standard burn by sending to 0x000...000, sending
        // to 0xdead ensures that the same position id cannot be minted again.
        transferFrom(msg.sender, address(0xdead), uint256(orderHash));

        // mark the position as exercised
        exercisedPositions[uint256(orderHash)] = true;

        emit ExercisedOrder(orderHash, floorAssetTokenIds, order);

        /* ~~~ INTERACTIONS ~~~ */

        if (order.isCall) {
            // -- exercising a call option

            // transfer strike from exerciser to putty
            // handle the case where the taker uses native ETH instead of WETH to pay the strike
            if (weth == order.baseAsset && msg.value > 0) {
                // check enough ETH was sent to cover the strike
                require(msg.value == order.strike, "Incorrect ETH amount sent");

                // convert ETH to WETH
                // we convert the strike ETH to WETH so that the logic in withdraw() works
                // - because withdraw() assumes an ERC20 interface on the base asset.
                IWETH(weth).deposit{value: msg.value}();
            } else {
                ERC20(order.baseAsset).safeTransferFrom(msg.sender, address(this), order.strike);
            }

            // transfer assets from putty to exerciser
            _transferERC20sOut(order.erc20Assets);
            _transferERC721sOut(order.erc721Assets);
            _transferFloorsOut(order.floorTokens, positionFloorAssetTokenIds[uint256(orderHash)]);
        } else {
            // -- exercising a put option

            // save the floor asset token ids to the short position
            uint256 shortPositionId = uint256(hashOppositeOrder(order));
            positionFloorAssetTokenIds[shortPositionId] = floorAssetTokenIds;

            // transfer strike from putty to exerciser
            ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike);

            // transfer assets from exerciser to putty
            _transferERC20sIn(order.erc20Assets, msg.sender);
            _transferERC721sIn(order.erc721Assets, msg.sender);
            _transferFloorsIn(order.floorTokens, floorAssetTokenIds, msg.sender);
        }
    }

Step 5: the same trick against withdraw()

The report notes that a similar attack works over withdraw(), since it also calls untrusted external addresses. An attacker could exercise an option and then block the other user from claiming any of the NFTs or ERC20 tokens owed to them.

Root cause

The protocol accepts arbitrary token addresses in an order and calls them during settlement, without any allowlist of approved ERC20 or ERC721 contracts. Because a revert in any one of those calls reverts the whole settlement, a single hostile token in an order gives its controller a switch that can block exercise() and withdraw() for that position.

Impact

An attacker who is the maker can prevent their own order from being exercised while it is in an undesirable position, for example when they are short and the price has risen, and release it once the position expires or the price falls. The same mechanism lets an attacker exercise an option and then stop the counterparty from claiming the NFTs or ERC20 tokens owed to them.

The judge rated this medium, on the basis that assets are not at direct risk but the function of the protocol or its availability could be impacted, or value could leak through a hypothetical attack path with stated assumptions and external requirements. A warden, Pedroais, argued for high severity: anyone can deploy a malicious contract and pass it as an ERC20 or NFT, so control of a malicious token is not a real external requirement. The warden's example was a user accepting an offer for a valuable NFT such as a BAYC together with an unknown token, reasonably expecting to at least receive the BAYC; the malicious token blocks exercise of the real NFT too, so an option containing many valuable tokens plus one malicious token cannot be exercised. The judge clarified that the external requirement is the user deciding to fill an option containing malicious assets, which can be treated as a honeypot that users should be warned about, and that partial exercising could be a feature but would open new attack surfaces and be non-trivial to implement.

Fix

The recommended mitigation is to whitelist approved ERC20 and ERC721 contract addresses so that users cannot set malicious token contracts in an order. The report notes that this remediation carries significant admin input and gas trade-offs.

The Putty team (outdoteth) acknowledged the finding but said they do not intend to fix it at the contract level. Instead the UI will carry adequate warnings telling users to be vigilant about tokens not verified by Putty, and unverified tokens will be shown with a question mark instead of their logoURI. The team's summary of the report: setting malicious or invalid erc721Assets, erc20Assets or floorTokens prevents the option from being exercised. A later review by hyh notes the issue is now addressed at the UI/DB level.

Variants to test

  • Put a reverting ERC20 in baseAsset of a call option and try to exercise: a positive result is that exercise() reverts at the strike transfer.
  • Exercise successfully, then toggle a token used by withdraw() to revert: a positive result is that the counterparty cannot claim the assets owed.
  • Combine one valuable, legitimate NFT with one malicious token in the same order: a positive result is that the malicious token blocks settlement of the legitimate asset as well.

Hunting notes

This class of bug hides wherever a contract iterates over user-supplied token addresses and calls them during settlement, especially in NFT and options protocols that support arbitrary ERC20 and ERC721 collections. During review, look for order or position structs with asset arrays, then check whether any allowlist or verification exists before the transfer helpers are called. The signal is a settlement path whose only checks are ownership, expiry and array lengths, with no validation of the token contracts themselves. The report described a maker-side manipulation (block while short and the price is up, release on expiry or a price drop) and a second path through withdraw() that strands the counterparty's assets.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

Putty is a service that runs on a blockchain (here, Ethereum-style networks). It lets two people make a deal about the future price of something, without either of them having to trust the other. One person, the maker, writes down the deal as an order: what is being traded, what must be paid, and by when. Another person, the taker, accepts that order by filling it. Once filled, the deal becomes a position, which is itself a digital token (an NFT) owned by one address. Whoever owns that position can later exercise it, meaning settle the deal and swap the assets, or withdraw to collect what they are owed.

The security researcher kirk-baird found a way for a dishonest maker to build a deal that looks normal but contains a booby-trapped token. The trap can be switched on at any moment to make every settlement attempt fail. That lets the maker freeze the deal while it is going badly for them, and unfreeze it when it suits them. The same trick can be used to stop the other side from collecting what they are owed after a deal has been settled.

The finding was reported during a Code4rena audit of the Putty codebase (the audit was named 2022-06-putty) and concerns the file contracts/src/PuttyV2.sol. Several other researchers found the same thing independently: 0xA5DF, cccz, chatch, csanuragjain, Alex the Entreprenerd, hansfriese, hyh, itsmeSTYJ, Kenshin, pedroais, sashik*eth, unforgiven and xiaoming90. The judge who rated the submissions gave it medium severity.

A few words you will meet constantly below:

  • Smart contract: a program that lives on a blockchain. It runs exactly as written, and anyone can call it. It cannot be changed after deployment unless it was built to be upgradeable.
  • Token: a smart contract that keeps a ledger of who owns how much of something. An ERC20 token is fungible, like a currency: every unit is the same. An ERC721 token is unique, like a ticket or a piece of art: each one has its own ID.
  • Address: the identifier of an account or contract on the blockchain, a long string starting with 0x.
  • Revert: the blockchain's way of saying "cancel everything". If any step of a transaction reverts, the whole transaction is undone, as if it never happened. It is like a shop till refusing a sale and handing everything back.
  • External call: one contract asking another contract to do something. The calling contract has to wait for the answer, and if the other contract refuses (reverts), the caller fails too.

The setup

The report does not describe any particular accounts, tools or software versions. The only precondition is simple: the attacker controls a token contract (an ERC20 or an ERC721) and can get its address into one of the asset fields of an order.

An order in Putty carries several fields that each name a token contract:

  • baseAsset: the asset used to pay the strike price (the agreed price of the option), an ERC20 token.
  • floorTokens[]: a list of tokens used as a floor for the deal.
  • erc20Assets[]: a list of ERC20 tokens involved.
  • erc721Assets[]: a list of ERC721 tokens (unique items) involved.

The square brackets mean "a list of", so erc20Assets[] is not one token but a collection of them.

The relevant code is the exercise() function in PuttyV2.sol, at lines 389 to 458 of the audited commit. The report also points at lines 72, 79, 80 and 81 of the same file, which is where the order's asset fields are declared.

Finding it

The researcher noticed a pattern. Every transfer performed inside exercise() is an external call to an address that comes from the order itself, and those addresses are not restricted to known or verified tokens. If any one of those addresses is a contract that reverts, the whole exercise() call reverts with it. The same reasoning applies to withdraw(), which also makes calls to untrusted external addresses.

Think of it like a courier who is told to deliver a parcel to an address written on the envelope. If the door at that address never opens, the courier cannot complete the delivery, and the whole delivery job is marked failed. Putty trusts the address written on the envelope.

The four fields that can carry such a contract are:

  • baseAsset
  • floorTokens[]
  • erc20Assets[]
  • erc721Assets[]

Exploitation

Step 1: create the order with a malicious token

An attacker acting as maker creates an order and sets one of the addresses above to a malicious contract under their control.

Step 2: let the taker fill the order

The attacker allows the user to fill the order. At this point the taker holds a position that can be exercised. The trap is armed but not yet sprung.

Step 3: toggle the malicious contract to revert

The attacker flips a variable on the malicious contract so that any transfer involving it always reverts. From then on, exercise() on that position fails.

Step 4: choose when to release

The attacker keeps the position blocked while it is unfavourable, for example if they have gone short and the price has gone up. Going short means betting that the price will fall; if the price rises instead, the bet loses money. By freezing the deal, the attacker avoids having to settle a losing bet. They wait for the position to expire or for the price to move back down, then allow transfers on the malicious token again.

The report shows the exercise() function as the proof of concept, noting that any of the transfers in it make external calls to untrusted addresses:

Solidity
    function exercise(Order memory order, uint256[] calldata floorAssetTokenIds) public payable {
        /* ~~~ CHECKS ~~~ */

        bytes32 orderHash = hashOrder(order);

        // check user owns the position
        require(ownerOf(uint256(orderHash)) == msg.sender, "Not owner");

        // check position is long
        require(order.isLong, "Can only exercise long positions");

        // check position has not expired
        require(block.timestamp < positionExpirations[uint256(orderHash)], "Position has expired");

        // check floor asset token ids length is 0 unless the position type is put
        !order.isCall
            ? require(floorAssetTokenIds.length == order.floorTokens.length, "Wrong amount of floor tokenIds")
            : require(floorAssetTokenIds.length == 0, "Invalid floor tokenIds length");

        /* ~~~ EFFECTS ~~~ */

        // send the long position to 0xdead.
        // instead of doing a standard burn by sending to 0x000...000, sending
        // to 0xdead ensures that the same position id cannot be minted again.
        transferFrom(msg.sender, address(0xdead), uint256(orderHash));

        // mark the position as exercised
        exercisedPositions[uint256(orderHash)] = true;

        emit ExercisedOrder(orderHash, floorAssetTokenIds, order);

        /* ~~~ INTERACTIONS ~~~ */

        if (order.isCall) {
            // -- exercising a call option

            // transfer strike from exerciser to putty
            // handle the case where the taker uses native ETH instead of WETH to pay the strike
            if (weth == order.baseAsset && msg.value > 0) {
                // check enough ETH was sent to cover the strike
                require(msg.value == order.strike, "Incorrect ETH amount sent");

                // convert ETH to WETH
                // we convert the strike ETH to WETH so that the logic in withdraw() works
                // - because withdraw() assumes an ERC20 interface on the base asset.
                IWETH(weth).deposit{value: msg.value}();
            } else {
                ERC20(order.baseAsset).safeTransferFrom(msg.sender, address(this), order.strike);
            }

            // transfer assets from putty to exerciser
            _transferERC20sOut(order.erc20Assets);
            _transferERC721sOut(order.erc721Assets);
            _transferFloorsOut(order.floorTokens, positionFloorAssetTokenIds[uint256(orderHash)]);
        } else {
            // -- exercising a put option

            // save the floor asset token ids to the short position
            uint256 shortPositionId = uint256(hashOppositeOrder(order));
            positionFloorAssetTokenIds[shortPositionId] = floorAssetTokenIds;

            // transfer strike from putty to exerciser
            ERC20(order.baseAsset).safeTransfer(msg.sender, order.strike);

            // transfer assets from exerciser to putty
            _transferERC20sIn(order.erc20Assets, msg.sender);
            _transferERC721sIn(order.erc721Assets, msg.sender);
            _transferFloorsIn(order.floorTokens, floorAssetTokenIds, msg.sender);
        }
    }

Line by line, in plain words:

  1. function exercise(Order memory order, uint256[] calldata floorAssetTokenIds) public payable declares the function. It takes the order details and a list of floor token IDs, and it is payable, meaning the caller can send cryptocurrency along with the call.
  2. bytes32 orderHash = hashOrder(order); turns the order into a short fingerprint, the orderHash, which is used as the position's ID.
  3. require(ownerOf(uint256(orderHash)) == msg.sender, "Not owner"); checks that the person calling is the owner of the position. msg.sender is the caller's address. If not, the call reverts with the message "Not owner".
  4. require(order.isLong, "Can only exercise long positions"); checks the position is a long one. A long position is the side that benefits if the price rises.
  5. require(block.timestamp < positionExpirations[uint256(orderHash)], "Position has expired"); checks the current time (block.timestamp) is before the position's expiry. An expired position cannot be exercised.
  6. The next require checks the number of floor token IDs supplied matches the number of floor tokens in the order, but only for a put option; for a call option it requires the list to be empty. A put option is the mirror of a call: it pays off if the price falls.
  7. transferFrom(msg.sender, address(0xdead), uint256(orderHash)); sends the position NFT to the address 0xdead. The comment explains this is a deliberate burn: sending it to a dead address rather than the zero address ensures the same position ID can never be minted again.
  8. exercisedPositions[uint256(orderHash)] = true; records that this position has been exercised.
  9. emit ExercisedOrder(...) writes a log entry so that outside observers can see the exercise happened.
  10. The if (order.isCall) branch handles a call option. If the strike asset is WETH (wrapped ETH, an ERC20 version of the network's native currency) and the caller sent native ETH, it checks the amount matches the strike and converts it to WETH. Otherwise it pulls the strike from the caller with ERC20(order.baseAsset).safeTransferFrom(...). Note that order.baseAsset is an address taken straight from the order.
  11. Still in the call branch, _transferERC20sOut, _transferERC721sOut and _transferFloorsOut send the assets out to the exerciser. Each of these helpers calls the token contracts named in the order.
  12. The else branch handles a put option. It saves the floor token IDs against the opposite (short) position, sends the strike to the exerciser with ERC20(order.baseAsset).safeTransfer(...), then pulls the assets in with _transferERC20sIn, _transferERC721sIn and _transferFloorsIn.

Step 5: the same trick against withdraw()

The report notes that a similar attack works over withdraw(), since it also calls untrusted external addresses. An attacker could exercise an option and then block the other user from claiming any of the NFTs or ERC20 tokens owed to them. In everyday terms: the attacker gets their side of the deal, then jams the door so the other person cannot collect theirs.

Root cause

The protocol accepts arbitrary token addresses in an order and calls them during settlement, without any allowlist of approved ERC20 or ERC721 contracts. An allowlist is a list of addresses that are explicitly permitted; anything not on it is refused. Because a revert in any one of those calls reverts the whole settlement, a single hostile token in an order gives its controller a switch that can block exercise() and withdraw() for that position.

Impact

An attacker who is the maker can prevent their own order from being exercised while it is in an undesirable position, for example when they are short and the price has risen, and release it once the position expires or the price falls. The same mechanism lets an attacker exercise an option and then stop the counterparty from claiming the NFTs or ERC20 tokens owed to them.

The judge rated this medium, on the basis that assets are not at direct risk but the function of the protocol or its availability could be impacted, or value could leak through a hypothetical attack path with stated assumptions and external requirements. In other words: nobody's funds are stolen outright, but the service can be made to stop working for a particular deal.

A warden (a participant in the audit competition), Pedroais, argued for high severity. Their reasoning: anyone can deploy a malicious contract and pass it as an ERC20 or NFT, so control of a malicious token is not a real external requirement. The warden's example was a user accepting an offer for a valuable NFT such as a BAYC together with an unknown token, reasonably expecting to at least receive the BAYC. The malicious token blocks exercise of the real NFT too, so an option containing many valuable tokens plus one malicious token cannot be exercised. The judge clarified that the external requirement is the user deciding to fill an option containing malicious assets, which can be treated as a honeypot (a trap that looks attractive) that users should be warned about, and that partial exercising could be a feature but would open new attack surfaces and be non-trivial to implement.

Fix

The recommended mitigation is to whitelist approved ERC20 and ERC721 contract addresses so that users cannot set malicious token contracts in an order. The report notes that this remediation carries significant admin input and gas trade-offs. Gas is the fee paid for computation on the blockchain, so checking a list on every transfer costs money, and maintaining the list costs staff time.

The Putty team (outdoteth) acknowledged the finding but said they do not intend to fix it at the contract level. Instead the UI will carry adequate warnings telling users to be vigilant about tokens not verified by Putty, and unverified tokens will be shown with a question mark instead of their logoURI (the token's logo image). The team's summary of the report: setting malicious or invalid erc721Assets, erc20Assets or floorTokens prevents the option from being exercised. A later review by hyh notes the issue is now addressed at the UI/DB level, meaning the warning is handled in the website and its database rather than in the smart contract.

Variants to test

These are the scenarios a reviewer would try, and what a positive result looks like:

  • Put a reverting ERC20 in baseAsset of a call option and try to exercise: a positive result is that exercise() reverts at the strike transfer.
  • Exercise successfully, then toggle a token used by withdraw() to revert: a positive result is that the counterparty cannot claim the assets owed.
  • Combine one valuable, legitimate NFT with one malicious token in the same order: a positive result is that the malicious token blocks settlement of the legitimate asset as well.

Hunting notes

This class of bug hides wherever a contract iterates over user-supplied token addresses and calls them during settlement, especially in NFT and options protocols that support arbitrary ERC20 and ERC721 collections. During review, look for order or position structs with asset arrays, then check whether any allowlist or verification exists before the transfer helpers are called. The signal is a settlement path whose only checks are ownership, expiry and array lengths, with no validation of the token contracts themselves. The report described a maker-side manipulation (block while short and the price is up, release on expiry or a price drop) and a second path through withdraw() that strands the counterparty's assets.

Glossary

  • Smart contract: a program deployed on a blockchain that runs exactly as written and can be called by anyone.
  • Blockchain: a shared, append-only ledger maintained by many computers, where transactions are recorded permanently.
  • Token: a smart contract that tracks ownership of units of an asset.
  • ERC20: the standard for fungible tokens, where every unit is interchangeable, like a currency.
  • ERC721: the standard for non-fungible tokens, where each token has a unique ID, like a ticket or a collectible.
  • NFT: a non-fungible token, an ERC721 token representing a unique item.
  • Address: the identifier of an account or contract on the blockchain, written as a long string starting with 0x.
  • Revert: cancelling a transaction and undoing all its effects, usually because a check failed.
  • External call: one contract invoking another contract and depending on its response.
  • Order: the maker's written description of a deal, including the assets involved and the price.
  • Maker: the person who creates an order.
  • Taker: the person who fills an existing order.
  • Position: the resulting claim created when an order is filled, held as an NFT.
  • Exercise: settling an option position, swapping the assets as agreed.
  • Withdraw: collecting assets owed to a position owner after settlement.
  • Option: a deal giving the right to buy (call) or sell (put) an asset at an agreed price.
  • Call option: an option that pays off if the price rises.
  • Put option: an option that pays off if the price falls.
  • Long: the side of a position that benefits when the price rises.
  • Short: the side of a position that benefits when the price falls.
  • Strike: the agreed price at which an option is settled.
  • Base asset: the token used to pay the strike.
  • Floor token: a token used as a floor for the deal, listed in floorTokens[].
  • Allowlist / whitelist: a list of addresses explicitly permitted; anything else is refused.
  • Honeypot: a trap that looks attractive to lure someone into interacting with it.
  • Gas: the fee paid for computation on the blockchain.
  • WETH: wrapped ETH, an ERC20 token that represents the network's native currency.
  • msg.sender: the address of the account that called the current function.
  • block.timestamp: the timestamp of the current block, used as the current time.
  • logoURI: the web address of a token's logo image, shown in a user interface.
  • UI: user interface, the website or app through which people interact with the protocol.
  • DB: database, the storage behind the website.
  • Code4rena: a platform that runs audit competitions where researchers review code for findings.
  • Warden: a participant in a Code4rena audit competition.
  • Judge: the person in a Code4rena competition who rates the severity of findings.
  • Severity: the rating of how serious a finding is, such as medium or high.
  • BAYC: Bored Ape Yacht Club, a well-known collection of valuable NFTs used as an example in the discussion.

More by kirk-baird

View all

32 more disclosed reports, best first.

More from Putty

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.