Skip to content
Business logic Audit finding Intermediate

Pendle Uses Wrong Return Value For swapExactTokensForTokens()

The Pendle lend function incorrectly uses the first element of the array returned by swapExactTokensForTokens as the output amount, when it actually represents the input amount. This causes the number of PT tokens minted to the caller to be wrong, likely over- or under-stated depending on the exchange rate.

kirk-baird Follow

Originally disclosed on Code4rena

Submitted by kirk-baird, also found by 0x52, cccz, csanuragjain, kenzo, and WatchPug

The function swapExactTokensForTokens() will return and array with the 0 index being the input amount follow by each output amount. The 0 index is incorrectly used in Pendle lend() function as the output amount. As a result the value of returned will be the invalid (i.e. the input rather than the output).

Since this impacts how many PTs will be minted to the msg.sender, the value will very likely be significantly over or under stated depending on the exchange rate. Hence the msg.sender will receive an invalid number of PT tokens.

Proof of Concept

            address[] memory path = new address[](2);
            path[0] = u;
            path[1] = principal;

            returned = IPendle(pendleAddr).swapExactTokensForTokens(a - fee, r, path, address(this), d)[0];

Recommended Mitigation Steps

The amount of principal returned should be index 1 of the array returned by swapExactTokensForTokens().

sourabhmarathe (Illuminate) confirmed


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.

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

Impact

The caller will receive an invalid number of PT tokens, likely significantly over- or under-stated depending on the exchange rate.

What the attacker needed

None

The fix

The amount of principal returned should be index 1 of the array returned by swapExactTokensForTokens().

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.

When you swap tokens, the function returns a list of amounts: the first is what you put in, the rest are what you got out. The code mistakenly took the first number (your input) as the output, so it calculated the wrong reward. This meant users could get too many or too few PT tokens.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by kirk-baird

View all

32 more disclosed reports, best first.

More from Illuminate contest

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.