What happened in the Penpie exploit?

On 3 September 2024 an attacker took about $27M from Penpie, a protocol built on Pendle, by registering a fake Pendle market and re-entering Penpie's reward harvest (The Block; SlowMist). The harvest called into the market to claim rewards, and the attacker's code used that call to deposit into Penpie, which inflated the rewards Penpie calculated for the attacker (SlowMist; Halborn). Pendle paused its own contracts and says it protected about $105M that could also have been drained (The Block).

Last updated . 5 minute read. By the QuillAudits Team.

What is the timeline of the Penpie exploit?

Protocol Penpie
Date 3 September 2024
Chain Ethereum
Loss about $27M
What happened Penpie let anyone register a pool for any market in Pendle's factory, and anyone can create a Pendle market. The attacker created one around a malicious SY contract. When Penpie harvested that market's rewards, the attacker's code deposited flash-loaned liquidity into Penpie during the call, which inflated the rewards Penpie calculated. As the only depositor in the fake market, the attacker withdrew those rewards.
Sources SlowMist, Halborn, The Block
  1. May 2024: Penpie adds a new feature. Its post-mortem later says the feature brought back a problem that an earlier audit had partly caught (The Record).
  2. Hours before the attack: the attacker's wallet receives 10 ETH through Tornado Cash (Invezz).
  3. Before the attack: the attacker creates a Pendle market with a malicious SY contract, registers a Penpie pool for it and deposits into that pool (SlowMist).
  4. 3 September 2024: using flash-loaned agETH and rswETH, the attacker calls Penpie's batch harvest on the fake market and withdraws the inflated rewards (SlowMist), about $27M in all (The Block).
  5. 3 September 2024: Penpie suspends deposits and withdrawals, and Pendle pauses its contracts as a precaution (Cointelegraph).
  6. 4 September 2024, early: Pendle posts its post-mortem, says further breaches were mitigated and unpauses its contracts (The Block).
  7. By 4 September 2024: Penpie offers the attacker a negotiable bounty, no legal action and anonymity in return for the funds. By then 3,000 ETH had gone through Tornado Cash in 30 transactions of 100 ETH (Invezz).
  8. 8 October 2024: Penpie proposes to compensate affected users through a new insurance protocol, Safupie (The Defiant).

What was the reentrancy bug in Penpie?

Two flaws met. First, registration was open. Penpie checked only that a market was listed in Pendle's factory, and anyone can list one by calling createNewMarket, according to Zokyo's report (Cointelegraph Magazine). SlowMist calls it "Penpie's erroneous assumption that all markets created by Pendle Finance are legitimate" (SlowMist).

Second, the harvest made an external call into the market, IPendleMarket(_market).redeemRewards(address(this)) (Application Layer), and nothing stopped a deposit into Penpie while that call ran. Halborn places the reentrancy in _harvestBatchMarketRewards (Halborn). The fake market's SY contract ran the attacker's code during the call. It added flash-loaned agETH and rswETH as liquidity in Pendle markets and deposited the resulting market tokens into Penpie, which inflated the rewards Penpie calculated. As the only depositor in the fake market, the attacker withdrew those rewards, removed the liquidity and kept the agETH and rswETH (SlowMist).

Vulnerable: Penpie's reward harvest, simplified, not the original code (illustrative, not audited code) HarvestSketch.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

interface IERC20Like {
    function balanceOf(address account) external view returns (uint256);
}

interface IMarketLike {
    function redeemRewards(address user) external; // runs code the market's creator wrote
}

interface IMarketFactory {
    function isValidMarket(address market) external view returns (bool);
}

/// Penpie's reward harvest, cut down to the pattern that failed.
contract HarvestSketch {
    IMarketFactory public immutable factory;
    mapping(address => bool) public registered;
    mapping(address => uint256) public rewardsForMarket;
    mapping(address => mapping(address => uint256)) public deposits;

    constructor(IMarketFactory factory_) {
        factory = factory_;
    }

    // Anyone can create a market in the factory, so this only proves the market exists.
    function registerPool(address market) external {
        require(factory.isValidMarket(market), "not a factory market");
        registered[market] = true;
    }

    function harvest(address market, IERC20Like rewardToken) external {
        require(registered[market], "unknown market");
        uint256 balanceBefore = rewardToken.balanceOf(address(this));
        // The market's code runs here and can call deposit() before this returns.
        IMarketLike(market).redeemRewards(address(this));
        // Everything that arrived during the call, deposits included, counts as a reward.
        rewardsForMarket[market] += rewardToken.balanceOf(address(this)) - balanceBefore;
    }

    function deposit(address market, uint256 amount) external {
        require(registered[market], "unknown market");
        // ... pull `amount` of the market's token from msg.sender
        deposits[market][msg.sender] += amount;
    }
}

The general fix for this pattern is one lock shared by every function that moves tokens or reads the balances a reward count depends on, plus a registration step that a person reviews. The sketch below shows both. It is not Penpie's own patch.

Fixed: one shared lock and reviewed registration, simplified (illustrative, not audited code) HarvestSketchFixed.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

interface IERC20Like {
    function balanceOf(address account) external view returns (uint256);
}

interface IMarketLike {
    function redeemRewards(address user) external;
}

contract HarvestSketchFixed {
    address public immutable owner;
    mapping(address => bool) public registered;
    mapping(address => uint256) public rewardsForMarket;
    mapping(address => mapping(address => uint256)) public deposits;
    uint256 private locked = 1;

    // One lock for every function that moves tokens or changes what harvest() measures.
    modifier nonReentrant() {
        require(locked == 1, "reentrant call");
        locked = 2;
        _;
        locked = 1;
    }

    constructor() {
        owner = msg.sender;
    }

    // Markets are added after review, not by whoever created them.
    function registerPool(address market) external {
        require(msg.sender == owner, "only owner");
        registered[market] = true;
    }

    function harvest(address market, IERC20Like rewardToken) external nonReentrant {
        require(registered[market], "unknown market");
        uint256 balanceBefore = rewardToken.balanceOf(address(this));
        IMarketLike(market).redeemRewards(address(this));
        rewardsForMarket[market] += rewardToken.balanceOf(address(this)) - balanceBefore;
    }

    function deposit(address market, uint256 amount) external nonReentrant {
        require(registered[market], "unknown market");
        // ... pull `amount` of the market's token from msg.sender
        deposits[market][msg.sender] += amount;
    }
}

Zokyo, one of Penpie's earlier auditors, says permissionless pool registration arrived about a year after its audit, when only the owner multisig could register a pool, and that a later audit covered only the new registration contracts (Cointelegraph Magazine). Penpie's post-mortem, as The Record reports it, says a full audit should have followed the new features (The Record). Our guide to reviewing changes since your last audit covers that step, and reentrancy covers the bug class.

How much did Penpie lose?

About $27M. Penpie confirmed $27,348,259 worth of ETH taken (The Record). The Block, citing Lookonchain, reported about $27.3M swapped into 11,109 ETH (The Block), and Invezz reported over 11,113 ETH (Invezz). Pendle says it protected about $105M more that could have been drained (The Block).

What happened after the Penpie exploit?

Penpie offered a negotiable bounty, no legal action and anonymity for the return of the funds (Invezz). The attacker did not return them and began laundering them through Tornado Cash (Halborn). On 8 October 2024 Penpie proposed to compensate affected users through a new insurance protocol, Safupie (The Defiant).

What would a proof-of-concept-first audit test here?

The question to test is whether anything a market does during the harvest call can change what the harvest counts. An auditor would register a mock market the way an outsider could, give it a reward hook that calls back into the staking contract, and assert that the rewards credited equal what the market actually paid. For this mock that is zero, so the only safe outcomes are no credit or a revert.

Mock market and test sketch for a re-entrant harvest (illustrative, not audited code) HarvestCountsOnlyPaidRewardsTest.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;

interface IStaking {
    function harvest(address market, address rewardToken) external;
    function deposit(address market, uint256 amount) external;
    function rewardsForMarket(address market) external view returns (uint256);
}

/// A market whose reward hook pays nothing and calls back into the staking contract instead.
contract ReenteringMarket {
    IStaking internal immutable staking;
    address internal immutable realMarket;
    uint256 internal immutable amount;

    constructor(IStaking staking_, address realMarket_, uint256 amount_) {
        staking = staking_;
        realMarket = realMarket_;
        amount = amount_;
    }

    function redeemRewards(address) external {
        staking.deposit(realMarket, amount);
    }
}

/// Foundry-style test. setUp() deploys the staking contract, registers a ReenteringMarket
/// through the public path and gives it market tokens to deposit.
contract HarvestCountsOnlyPaidRewardsTest {
    IStaking internal staking;
    address internal fakeMarket;
    address internal rewardToken;

    function test_depositDuringHarvestIsNotCountedAsReward() external {
        uint256 before = staking.rewardsForMarket(fakeMarket);
        try staking.harvest(fakeMarket, rewardToken) {
            // The mock paid no rewards, so nothing may be credited.
            require(staking.rewardsForMarket(fakeMarket) == before, "a deposit was counted as a reward");
        } catch {
            // Reverting on the re-entrant deposit is also safe.
        }
    }
}
  • Register the mock through the same path an outsider would use. If registration is open, the mock is in scope.
  • From inside the hook, try every function the callback can reach: deposit, withdraw and a second harvest.
  • Repeat the test for every place the contract measures a balance before and after an external call.

A QuillShield full audit covers the whole Solidity codebase in scope in a Foundry project, so a path that crosses contracts is reviewed together. A separate reviewer agent tries to disprove each finding before you see it, and on full audits each finding that holds up comes with a proof of concept. Each pull request is then checked against the audit's security graph. We have not run QuillShield on Penpie's code, so this page makes no claim about what it would report there. Run a full audit: sign-up is free, and new accounts get $50 in credit, good for up to half of an order. The audit readiness checklist covers what to prepare first.

FAQ

Was Pendle hacked?

No. The exploit drained Penpie's contracts. Pendle paused its own contracts as a precaution, unpaused them after its post-mortem, and says it protected about $105M (The Block).

Was the Penpie exploit a flash loan attack?

Flash loans of agETH and rswETH supplied the liquidity the attacker deposited during the harvest (SlowMist). The flaws were the open market registration and a harvest that let a deposit made during its own external call inflate the rewards.

Did the attacker return the funds?

Not according to the sources this page uses. The attacker began laundering the funds through Tornado Cash (Halborn; Invezz).

Sources

QuillShield is building the security layer between AI and money, so you can keep shipping between audits.

Sign-up is free, and new accounts get $50 in credit, good for up to half of an order.

  1. 1Sign up and import a repo
  2. 2See the exact price before anything is charged
  3. 3Approve it, and the audit starts