Skip to content

Commit e18e871

Browse files
committed
Merge remote-tracking branch 'origin/nicka/oz-audit-fixes-oeth-withdrawal-queue' into nicka/oz-audit-oeth-withdrawal-queue-L-03
2 parents 0e99b4a + f82a54d commit e18e871

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

contracts/contracts/vault/OETHVaultCore.sol

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,24 @@ contract OETHVaultCore is VaultCore {
395395
override
396396
returns (uint256 balance)
397397
{
398+
if (_asset != weth) {
399+
return 0;
400+
}
401+
402+
// Get the WETH in the vault and the strategies
398403
balance = super._checkBalance(_asset);
399404

400-
if (_asset == weth) {
401-
WithdrawalQueueMetadata memory queue = withdrawalQueueMetadata;
402-
// Need to remove WETH that is reserved for the withdrawal queue
403-
if (balance + queue.claimed >= queue.queued) {
404-
return balance + queue.claimed - queue.queued;
405-
}
405+
WithdrawalQueueMetadata memory queue = withdrawalQueueMetadata;
406+
407+
// If the vault becomes insolvent enough that the total value in the vault and all strategies
408+
// is less than the outstanding withdrawals.
409+
// For example, there was a mass slashing event and most users request a withdrawal.
410+
if (balance + queue.claimed < queue.queued) {
411+
return 0;
406412
}
413+
414+
// Need to remove WETH that is reserved for the withdrawal queue
415+
return balance + queue.claimed - queue.queued;
407416
}
408417

409418
/**
@@ -446,29 +455,14 @@ contract OETHVaultCore is VaultCore {
446455
emit AssetAllocated(weth, depositStrategyAddr, allocateAmount);
447456
}
448457

449-
/// @dev The total value of all assets held by the vault and all its strategies
458+
/// @dev The total value of all WETH held by the vault and all its strategies
450459
/// less any WETH that is reserved for the withdrawal queue.
451-
/// For OETH, this is just WETH in the vault and strategies.
452460
///
453461
// If there is not enough WETH in the vault and all strategies to cover all outstanding
454462
// withdrawal requests then return a total value of 0.
455463
function _totalValue() internal view override returns (uint256 value) {
456-
value = _totalValueInVault() + _totalValueInStrategies();
457-
458-
// Need to remove WETH that is reserved for the withdrawal queue.
459-
WithdrawalQueueMetadata memory queue = withdrawalQueueMetadata;
460-
// reserved for the withdrawal queue = cumulative queued total - total claimed
461-
uint256 reservedForQueue = queue.queued - queue.claimed;
462-
463-
if (value < reservedForQueue) {
464-
// This can happen if the vault becomes insolvent enough that the
465-
// total value in the vault and all strategies is less than the outstanding withdrawals.
466-
// For example, there was a mass slashing event and most users request a withdrawal.
467-
return 0;
468-
}
469-
470-
// Adjust the total value by the amount reserved for the withdrawal queue
471-
return value - reservedForQueue;
464+
// As WETH is the only asset, just return the WETH balance
465+
return _checkBalance(weth);
472466
}
473467

474468
/// @dev Only WETH is supported in the OETH Vault so return the WETH balance only

contracts/test/vault/oeth-vault.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,11 @@ describe("OETH Vault", function () {
21492149
// 100 from mints - 99 outstanding withdrawals - 2 from slashing = -1 value which is rounder up to zero
21502150
expect(await fixture.oethVault.totalValue()).to.equal(0);
21512151
});
2152+
it("Should have check balance of zero", async () => {
2153+
const { oethVault, weth } = fixture;
2154+
// 100 from mints - 99 outstanding withdrawals - 2 from slashing = -1 value which is rounder up to zero
2155+
expect(await oethVault.checkBalance(weth.address)).to.equal(0);
2156+
});
21522157
it("Fail to allow user to create a new request due to too many outstanding requests", async () => {
21532158
const { oethVault, matt } = fixture;
21542159

0 commit comments

Comments
 (0)