Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: restrict staking module name length to 31 bytes #725

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions contracts/0.8.9/StakingRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ contract StakingRouter is AccessControlEnumerable, BeaconChainDepositor, Version
uint256 public constant FEE_PRECISION_POINTS = 10 ** 20; // 100 * 10 ** 18
uint256 public constant TOTAL_BASIS_POINTS = 10000;
uint256 public constant MAX_STAKING_MODULES_COUNT = 32;
uint256 public constant MAX_STAKING_MODULE_NAME_LENGTH = 32;
/// @dev restrict the name size with 31 bytes to storage in a single slot
uint256 public constant MAX_STAKING_MODULE_NAME_LENGTH = 31;

constructor(address _depositContract) BeaconChainDepositor(_depositContract) {}

Expand Down Expand Up @@ -1057,10 +1058,9 @@ contract StakingRouter is AccessControlEnumerable, BeaconChainDepositor, Version
/// reduced, 1e4 precision.
function getTotalFeeE4Precision() external view returns (uint16 totalFee) {
/// @dev The logic is placed here but in Lido contract to save Lido bytecode
uint256 E4_BASIS_POINTS = 10000; // Corresponds to Lido.TOTAL_BASIS_POINTS
(, , , uint96 totalFeeInHighPrecision, uint256 precision) = getStakingRewardsDistribution();
// Here we rely on (totalFeeInHighPrecision <= precision)
totalFee = uint16((totalFeeInHighPrecision * E4_BASIS_POINTS) / precision);
totalFee = _toE4Precision(totalFeeInHighPrecision, precision);
}

/// @notice Helper for Lido contract (DEPRECATED)
Expand All @@ -1071,15 +1071,14 @@ contract StakingRouter is AccessControlEnumerable, BeaconChainDepositor, Version
returns (uint16 modulesFee, uint16 treasuryFee)
{
/// @dev The logic is placed here but in Lido contract to save Lido bytecode
uint256 E4_BASIS_POINTS = 10000; // Corresponds to Lido.TOTAL_BASIS_POINTS
(
uint256 modulesFeeHighPrecision,
uint256 treasuryFeeHighPrecision,
uint256 precision
) = getStakingFeeAggregateDistribution();
// Here we rely on ({modules,treasury}FeeHighPrecision <= precision)
modulesFee = uint16((modulesFeeHighPrecision * E4_BASIS_POINTS) / precision);
treasuryFee = uint16((treasuryFeeHighPrecision * E4_BASIS_POINTS) / precision);
modulesFee = _toE4Precision(modulesFeeHighPrecision, precision);
treasuryFee = _toE4Precision(treasuryFeeHighPrecision, precision);
}

/// @notice returns new deposits allocation after the distribution of the `_depositsCount` deposits
Expand Down Expand Up @@ -1314,4 +1313,8 @@ contract StakingRouter is AccessControlEnumerable, BeaconChainDepositor, Version
result.slot := position
}
}

function _toE4Precision(uint256 _value, uint256 _precision) internal pure returns (uint16) {
return uint16((_value * TOTAL_BASIS_POINTS) / _precision);
}
}
4 changes: 2 additions & 2 deletions test/0.8.9/staking-router/staking-router.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,10 @@ contract('StakingRouter', ([deployer, lido, admin, appManager, stranger]) => {
`StakingModuleWrongName()`
)

// check length > 32 symbols
// check length > 31 symbols
await assert.revertsWithCustomError(
router.addStakingModule(
'#'.repeat(33),
'#'.repeat(32),
stakingModule1.address,
stakingModulesParams[0].targetShare,
stakingModulesParams[0].stakingModuleFee,
Expand Down