Single sided liquidity can’t be used to lock LP tokens in the farm manager
When providing single-sided liquidity with an unlocking duration, the contract calls itself to deposit the swapped amount, causing the receiver check to fail because the sender is the contract address. This prevents users from locking LP tokens in the farm manager in a single action, breaking a core functionality.
0xAlix2 Follow with 0xRajkumar, Abdessamed and 3 others
Originally disclosed on Code4rena
Submitted by 0xAlix2, also found by 0xRajkumar, Abdessamed, carrotsmuggler, Egis_Security, and Tigerfrake
/contracts/pool-manager/src/liquidity/commands.rs#L282-L286
Finding description and impact
When users provide liquidity into different pools, they call the provide_liquidity function, they are also allowed to pass unlocking_duration, if provided, the minted LP shares are locked in the farm manager for extra rewards, see here. The protocol doesn’t allow users to open positions in the farm manager on behalf of other users, from the docs:
Note: It’s only possible to lock an LP position in the farm for the same user providing the liquidity, and not do it on behalf of another user.
It gets validated using the following:
// check if receiver is the same as the sender of the tx
ensure!(
receiver == info.sender.to_string(),
ContractError::Unauthorized
);
On the other hand, when providing single-sided liquidity, half of the deposited amount is swapped to the other asset and then deposited, the process is as follows: provide_liquidity -> swap -> rely -> provide_liquidity.
However, the issue here is that the second provide_liquidity gets called from the contract itself, i.e., info.sender is the contract address itself, which forces the above receiver validation to revert wrongly.
This blocks users from depositing single-sided liquidity and locks the LP tokens in the farm manager in a single action, breaking a core functionality.
Proof of Concept
Add the following test in contracts/pool-manager/src/tests/integration_tests.rs#locking_lp:
#[test]
fn cant_open_position_with_single_side_liquidity() {
let mut suite = TestingSuite::default_with_balances(
vec![
coin(10_000_000u128, "uwhale".to_string()),
coin(10_000_000u128, "uluna".to_string()),
coin(10_000u128, "uusd".to_string()),
coin(10_000u128, "uom".to_string()),
],
StargateMock::new("uom".to_string(), "8888".to_string()),
);
let creator = suite.creator();
let user = suite.senders[1].clone();
suite
.instantiate_default()
.add_one_epoch()
.create_pool(
&creator,
vec!["uwhale".to_string(), "uluna".to_string()],
vec![6u8, 6u8],
PoolFee {
protocol_fee: Fee {
share: Decimal::zero(),
},
swap_fee: Fee {
share: Decimal::zero(),
},
burn_fee: Fee {
share: Decimal::zero(),
},
extra_fees: vec![],
},
PoolType::ConstantProduct,
Some("whale.uluna".to_string()),
vec![coin(1000, "uusd"), coin(8888, "uom")],
|result| {
result.unwrap();
},
)
.provide_liquidity(
&creator,
"o.whale.uluna".to_string(),
None,
None,
None,
None,
vec![
Coin {
denom: "uwhale".to_string(),
amount: Uint128::from(1_000_000u128),
},
Coin {
denom: "uluna".to_string(),
amount: Uint128::from(1_000_000u128),
},
],
|result| {
result.unwrap();
},
)
.provide_liquidity(
&user,
"o.whale.uluna".to_string(),
Some(86_400u64),
None,
None,
None,
vec![Coin {
denom: "uwhale".to_string(),
amount: Uint128::from(1_000u128),
}],
|result| {
let err = result.unwrap_err().downcast::<ContractError>().unwrap();
match err {
ContractError::Unauthorized => {}
_ => panic!("Wrong error type, should return ContractError::Unauthorized"),
}
},
);
}
Recommended mitigation steps
Modify the receiver validation in the if let Some(unlocking_duration) = unlocking_duration block, to bypass the condition if the sender is the contract itself.
ensure!(
receiver == info.sender.to_string() || info.sender == env.contract.address,
ContractError::Unauthorized
);
To ensure that this doesn’t cause any flaws, a receiver validation should be added to the if is_single_asset_provision block, to ensure that the sent receiver is valid, is it enough to do the following:
ensure!(
receiver == info.sender.to_string(),
ContractError::Unauthorized
);
jvr0x (MANTRA) confirmed
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
The receiver validation assumes the sender is always the original user, but during single-sided liquidity provision the contract calls itself, making the sender the contract address.
Impact
Users cannot deposit single-sided liquidity and lock LP tokens in the farm manager in one action, breaking a core functionality.
What the attacker needed
A pool exists; user provides single-sided liquidity; user specifies unlocking_duration
The fix
Modify the receiver validation to allow the contract address as sender when locking, and add a receiver validation in the single-asset provision block.
How it was found
- Create a pool and provide initial liquidity.
- Call provide_liquidity with a single asset and an unlocking_duration.
- Observe the transaction reverts with Unauthorized error.
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 add money to a trading pool, you can choose to lock your share for extra rewards. The contract checks that the person locking the share is the same as the person adding the money. But for one-sided deposits, the contract temporarily acts as the sender, so the check fails and the whole action is blocked.
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.