Skip to content

Conversation

@riccardo-ssvlabs
Copy link
Contributor

No description provided.

) external onlyStrategyOwner(strategyId) {
if (obligationPercentage > MAX_PERCENTAGE) revert ICore.InvalidPercentage();
if (obligationPercentage <= obligations[strategyId][bApp][token]) revert ICore.InvalidPercentage();

Copy link
Contributor

@mtabasco mtabasco Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check new condition when going from 0% to >0%

if (obligations[strategyId][bApp][token] == 0 && obligationPercentage > 0) {
    usedTokens[strategyId][token] += 1;
}

or add a check if the obligation does not exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find Marco!

obligations[strategyId][bApp][token] = obligationPercentage;
}

obligationsCounter[strategyId][bApp] += 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think obligationsCounter should be incremented only if obligationPercentage != 0, as it represents the total obligations created in a strategy, right?
maybe also don't emit the next event. So:

if (obligationPercentage != 0) {
    usedTokens[strategyId][token] += 1;
    obligations[strategyId][bApp][token] = obligationPercentage;
}

obligationsCounter[strategyId][bApp] += 1;
emit ObligationCreated(strategyId, bApp, token, obligationPercentage);

/// @notice Withdraw ETH from the strategy
/// @param strategyId The ID of the strategy
/// @param amount The amount to withdraw
function fastWithdrawETH(uint256 strategyId, uint256 amount) external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential candidate to use nonReentrant modifier.
We need to add a test to simulate a reentrancy attack.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was planning to have timebox task to try and break the contract, testing reentrancy and more.

* If the counter is 0, the token is unused and we can allow fast withdrawal.
*/
mapping(uint256 strategyId => mapping(address token => uint32 servicesCounter)) public usedTokens;
mapping(uint256 strategyId => mapping(address token => uint32 bAppsCounter)) public usedTokens;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please double check each action that sets an obligation from >0 to 0 or 0 to >0 also updates usedTokens

@riccardo-ssvlabs riccardo-ssvlabs merged commit f223d5a into main Jan 28, 2025
2 checks passed
@riccardo-ssvlabs riccardo-ssvlabs deleted the test/strategy-initial branch February 3, 2025 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants