Skip to content

Commit

Permalink
Fix audit issue 8.1.9
Browse files Browse the repository at this point in the history
Fix audit issue 8.1.11

Fix audit issue 8.1.6 for ynLSD

Fix audit issue 8.1.1

Fix audit issue 8.1.10
  • Loading branch information
xhad committed Mar 29, 2024
1 parent ced5c5f commit 3e545fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/StakingNodesManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ contract StakingNodesManager is
uint256 totalDepositAmount = newValidators.length * DEFAULT_VALIDATOR_STAKE;
ynETH.withdrawETH(totalDepositAmount); // Withdraw ETH from depositPool

uint256 validatorsLength = newValidators.length;
for (uint256 i = 0; i < validatorsLength; i++) {
for (uint256 i = 0; i < newValidators.length; i++) {

ValidatorData calldata validator = newValidators[i];
if (usedValidators[validator.publicKey]) {
Expand All @@ -251,10 +250,12 @@ contract StakingNodesManager is
*/
function validateNodes(ValidatorData[] calldata newValidators) public view {

uint256 nodeCount = nodes.length;

for (uint256 i = 0; i < newValidators.length; i++) {
uint256 nodeId = newValidators[i].nodeId;

if (nodeId >= nodes.length) {
if (nodeId >= nodeCount) {
revert InvalidNodeId(nodeId);
}
}
Expand Down
28 changes: 16 additions & 12 deletions src/ynLSD.sol
Original file line number Diff line number Diff line change
Expand Up @@ -289,22 +289,25 @@ contract ynLSD is IynLSD, ynBase, ReentrancyGuardUpgradeable, IynLSDEvents {
view
returns (uint256[] memory assetBalances)
{
assetBalances = new uint256[](assets.length);
IStrategy[] memory assetStrategies = new IStrategy[](assets.length);
uint256 assetsCount = assets.length;

assetBalances = new uint256[](assetsCount);
IStrategy[] memory assetStrategies = new IStrategy[](assetsCount);

// Add balances for funds held directly in ynLSD.
for (uint256 i = 0; i < assets.length; i++) {
assetStrategies[i] = strategies[assets[i]];
for (uint256 i = 0; i < assetsCount; i++) {
IERC20 asset = assets[i];
assetStrategies[i] = strategies[asset];

uint256 balanceThis = assets[i].balanceOf(address(this));
uint256 balanceThis = asset.balanceOf(address(this));
assetBalances[i] += balanceThis;
}

// Add balances contained in each LSDStakingNode, including those managed by strategies.
for (uint256 i; i < nodes.length; i++ ) {

ILSDStakingNode node = nodes[i];
for (uint256 j = 0; j < assets.length; j++) {
for (uint256 j = 0; j < assetsCount; j++) {

IERC20 asset = assets[j];
uint256 balanceNode = asset.balanceOf(address(node));
Expand Down Expand Up @@ -355,15 +358,16 @@ contract ynLSD is IynLSD, ynBase, ReentrancyGuardUpgradeable, IynLSDEvents {
onlyRole(LSD_STAKING_NODE_CREATOR_ROLE)
returns (ILSDStakingNode) {

if (nodes.length >= maxNodeCount) {
uint256 nodeId = nodes.length;

if (nodeId >= maxNodeCount) {
revert TooManyStakingNodes(maxNodeCount);
}

BeaconProxy proxy = new BeaconProxy(address(upgradeableBeacon), "");
ILSDStakingNode node = ILSDStakingNode(payable(proxy));

uint256 nodeId = nodes.length;
initializeLSDStakingNode(node);
initializeLSDStakingNode(node, nodeId);

nodes.push(node);

Expand All @@ -377,12 +381,12 @@ contract ynLSD is IynLSD, ynBase, ReentrancyGuardUpgradeable, IynLSDEvents {
* @dev This function checks the current initialized version of the node and performs initialization if it hasn't been done.
* For future versions, additional conditional blocks should be added to handle version-specific initialization.
* @param node The ILSDStakingNode instance to be initialized.
* @param nodeId The ID of the staking node.
*/
function initializeLSDStakingNode(ILSDStakingNode node) virtual internal {
function initializeLSDStakingNode(ILSDStakingNode node, uint256 nodeId) virtual internal {

uint64 initializedVersion = node.getInitializedVersion();
if (initializedVersion == 0) {
uint256 nodeId = nodes.length;
node.initialize(
ILSDStakingNode.Init(IynLSD(address(this)), nodeId)
);
Expand Down Expand Up @@ -438,7 +442,7 @@ contract ynLSD is IynLSD, ynBase, ReentrancyGuardUpgradeable, IynLSDEvents {

// Reinitialize all nodes to ensure compatibility with the new implementation.
for (uint256 i = 0; i < nodeCount; i++) {
initializeLSDStakingNode(nodes[i]);
initializeLSDStakingNode(nodes[i], nodeCount);
}

emit UpgradedStakingNodeImplementationContract(address(_implementationContract), nodeCount);
Expand Down
3 changes: 1 addition & 2 deletions test/foundry/mocks/TestYnLSDV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import "../../../src/interfaces/ILSDStakingNode.sol";
import "./TestLSDStakingNodeV2.sol";

contract TestYnLSDV2 is ynLSD {
function initializeLSDStakingNode(ILSDStakingNode node) override internal {
function initializeLSDStakingNode(ILSDStakingNode node, uint256 nodeId) override internal {

uint64 initializedVersion = node.getInitializedVersion();
if (initializedVersion == 0) {
uint256 nodeId = nodes.length;
node.initialize(
ILSDStakingNode.Init(IynLSD(address(this)), nodeId)
);
Expand Down

0 comments on commit 3e545fd

Please sign in to comment.