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

Solid IStakingModule interface #574

Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9adb386
Use structs in StakingModule. Rework getValidatorsKeysStats method
Psirex Feb 8, 2023
579be0b
Refactor IStakingModule interface
Psirex Feb 8, 2023
5931b3f
Update tests
Psirex Feb 8, 2023
df2e0e1
Rename invalidateReadyToDepositValidators
Psirex Feb 8, 2023
6258912
Rename "keys" -> "validators" across the codebase
Psirex Feb 8, 2023
47578d7
Update NodeOperatorsRegistry ValidatorsReport views
Psirex Feb 9, 2023
4dc1218
Add getNodeOperatorIds to IStakingModule interface
Psirex Feb 9, 2023
b2b3727
Add StakingModulesDataAggregator contract
Psirex Feb 9, 2023
7a8ae1b
Update ABIs
Psirex Feb 9, 2023
fd30a72
rename provideDepositsData to obtainDepositData
Psirex Feb 9, 2023
f4e6615
Add more detailed comments to getValidatorsReport views in the NodeOp…
Psirex Feb 9, 2023
c9a3e62
Rename depositsDataNonce to depositNonce
Psirex Feb 9, 2023
c952094
Rename invalidateDepositsData to invalidateDepositData
Psirex Feb 9, 2023
92864f0
Merge branch 'feature/shapella-upgrade' into feature/shapella-upgrade…
Psirex Feb 9, 2023
d98395b
Use new ValidatorsReport fields in StakingRouter
Psirex Feb 9, 2023
17227a7
Remove StakingModulesDataAggregator contract
Psirex Feb 9, 2023
2aa991d
Rename getDepositNonce() to getNonce()
Psirex Feb 10, 2023
6a1ed2a
Update ValidatorsReport fields
Psirex Feb 10, 2023
44111a3
Add updateRefundedValidatorsCount() method
Psirex Feb 10, 2023
9ddeaf5
finishUpdatingExitedValidatorsCount() -> onAllValidatorsCountersUpdat…
Psirex Feb 10, 2023
0d59b8f
Rename invalidateDepositData() to onWithdrawalCredentialsChanged()
Psirex Feb 10, 2023
4aa1299
Add missing doc comments to the IStakinModule
Psirex Feb 10, 2023
01fad86
Merge branch 'feature/shapella-upgrade' into feature/shapella-upgrade…
Psirex Feb 10, 2023
d795ffc
Remove FIXME from NodeOperatorsRegistry
Psirex Feb 10, 2023
eb38e3b
After-merge node-operators-registry test fixes
Psirex Feb 10, 2023
ea278f3
Replace getValidatorsReport() methods
Psirex Feb 10, 2023
47fdf2d
Rename onAllValidatorsCountersUpdated to onAllValidatorCountersUpdated
Psirex Feb 10, 2023
0e42d35
Merge branch 'feature/shapella-upgrade' into feature/shapella-upgrade…
Psirex Feb 10, 2023
aab9e44
Fix typo in NodeOperatorRegistry
Psirex Feb 10, 2023
500019d
Rename keys to validators in var names in the StakingRouter
Psirex Feb 10, 2023
6232e97
Update getNonce() comment in NodeOperatorsRegistry
Psirex Feb 10, 2023
9279f11
Add methods for batched node operator and staking module reports rece…
Psirex Feb 10, 2023
888eed7
Add updateRefundedValidatorsCount to StakingRouter
Psirex Feb 10, 2023
d5cf565
Add commented var names into tuple decoding
Psirex Feb 10, 2023
1f7ad2c
Use uint256 type in external/public methods
Psirex Feb 10, 2023
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
10 changes: 5 additions & 5 deletions contracts/0.4.24/Lido.sol
Original file line number Diff line number Diff line change
Expand Up @@ -628,16 +628,16 @@ contract Lido is Versioned, StETHPermit, AragonApp {
uint256 unaccountedEth = _getUnaccountedEther();
/// @dev transfer ether to SR and make deposit at the same time
/// @notice allow zero value of depositableEth, in this case SR will simply transfer the unaccounted ether to Lido contract
uint256 depositedKeysCount = IStakingRouter(locator.stakingRouter()).deposit.value(depositableEth)(
uint256 depositsCount = IStakingRouter(locator.stakingRouter()).deposit.value(depositableEth)(
_maxDepositsCount,
_stakingModuleId,
_depositCalldata
);
assert(depositedKeysCount <= depositableEth / DEPOSIT_SIZE );
assert(depositsCount <= depositableEth / DEPOSIT_SIZE );

if (depositedKeysCount > 0) {
uint256 depositedAmount = depositedKeysCount.mul(DEPOSIT_SIZE);
DEPOSITED_VALIDATORS_POSITION.setStorageUint256(DEPOSITED_VALIDATORS_POSITION.getStorageUint256().add(depositedKeysCount));
if (depositsCount > 0) {
uint256 depositedAmount = depositsCount.mul(DEPOSIT_SIZE);
DEPOSITED_VALIDATORS_POSITION.setStorageUint256(DEPOSITED_VALIDATORS_POSITION.getStorageUint256().add(depositsCount));

_markAsUnbuffered(depositedAmount);
assert(_getUnaccountedEther() == unaccountedEth);
Expand Down
223 changes: 107 additions & 116 deletions contracts/0.4.24/nos/NodeOperatorsRegistry.sol

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions contracts/0.4.24/test_helpers/NodeOperatorsRegistryMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,11 @@ contract NodeOperatorsRegistryMock is NodeOperatorsRegistry {
return _getSigningKeysAllocationData(_keysCount);
}

function testing_requestValidatorsKeysForDeposits(uint256 _keysToAllocate)
function testing_obtainDepositData(uint256 _keysToAllocate)
external
returns (uint256 loadedValidatorsKeysCount, bytes memory publicKeys, bytes memory signatures)
{
(loadedValidatorsKeysCount, publicKeys, signatures) =
this.requestValidatorsKeysForDeposits(_keysToAllocate, new bytes(0));
(loadedValidatorsKeysCount, publicKeys, signatures) = this.obtainDepositData(_keysToAllocate, new bytes(0));
emit ValidatorsKeysLoaded(loadedValidatorsKeysCount, publicKeys, signatures);
}

Expand Down
22 changes: 11 additions & 11 deletions contracts/0.8.9/DepositSecurityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface IStakingRouter {
function resumeStakingModule(uint256 _stakingModuleId) external;
function getStakingModuleIsDepositsPaused(uint256 _stakingModuleId) external view returns (bool);
function getStakingModuleIsActive(uint256 _stakingModuleId) external view returns (bool);
function getStakingModuleKeysOpIndex(uint256 _stakingModuleId) external view returns (uint256);
function getStakingModuleNonce(uint256 _stakingModuleId) external view returns (uint256);
function getStakingModuleLastDepositBlock(uint256 _stakingModuleId) external view returns (uint256);
}

Expand Down Expand Up @@ -199,7 +199,7 @@ contract DepositSecurityModule {
}

/**
* Returns number of valid guardian signatures required to vet (depositRoot, keysOpIndex) pair.
* Returns number of valid guardian signatures required to vet (depositRoot, nonce) pair.
*/
function getGuardianQuorum() external view returns (uint256) {
return quorum;
Expand Down Expand Up @@ -364,7 +364,7 @@ contract DepositSecurityModule {

/**
* Returns whether LIDO.deposit() can be called, given that the caller will provide
* guardian attestations of non-stale deposit root and `keysOpIndex`, and the number of
* guardian attestations of non-stale deposit root and `nonce`, and the number of
* such attestations will be enough to reach quorum.
*/
function canDeposit(uint256 stakingModuleId) external view validStakingModuleId(stakingModuleId) returns (bool) {
Expand All @@ -378,7 +378,7 @@ contract DepositSecurityModule {
*
* Reverts if any of the following is true:
* 1. IDepositContract.get_deposit_root() != depositRoot.
* 2. StakingModule.getKeysOpIndex() != keysOpIndex.
* 2. StakingModule.getNonce() != nonce.
* 3. The number of guardian signatures is less than getGuardianQuorum().
* 4. An invalid or non-guardian signature received.
* 5. block.number - StakingModule.getLastDepositBlock() < minDepositBlockDistance.
Expand All @@ -387,14 +387,14 @@ contract DepositSecurityModule {
* Signatures must be sorted in ascending order by index of the guardian. Each signature must
* be produced for keccak256 hash of the following message (each component taking 32 bytes):
*
* | ATTEST_MESSAGE_PREFIX | blockNumber | blockHash | depositRoot | stakingModuleId | keysOpIndex |
* | ATTEST_MESSAGE_PREFIX | blockNumber | blockHash | depositRoot | stakingModuleId | nonce |
*/
function depositBufferedEther(
uint256 blockNumber,
bytes32 blockHash,
bytes32 depositRoot,
uint256 stakingModuleId,
uint256 keysOpIndex,
uint256 nonce,
bytes calldata depositCalldata,
Signature[] calldata sortedGuardianSignatures
) external validStakingModuleId(stakingModuleId) {
Expand All @@ -409,10 +409,10 @@ contract DepositSecurityModule {
require(block.number - lastDepositBlock >= minDepositBlockDistance, "too frequent deposits");
require(blockHash != bytes32(0) && blockhash(blockNumber) == blockHash, "unexpected block hash");

uint256 onchainKeysOpIndex = STAKING_ROUTER.getStakingModuleKeysOpIndex(stakingModuleId);
require(keysOpIndex == onchainKeysOpIndex, "keys op index changed");
uint256 onchainNonce = STAKING_ROUTER.getStakingModuleNonce(stakingModuleId);
require(nonce == onchainNonce, "nonce changed");

_verifySignatures(depositRoot, blockNumber, blockHash, stakingModuleId, keysOpIndex, sortedGuardianSignatures);
_verifySignatures(depositRoot, blockNumber, blockHash, stakingModuleId, nonce, sortedGuardianSignatures);

LIDO.deposit(maxDepositsPerBlock, stakingModuleId, depositCalldata);
}
Expand All @@ -422,11 +422,11 @@ contract DepositSecurityModule {
uint256 blockNumber,
bytes32 blockHash,
uint256 stakingModuleId,
uint256 keysOpIndex,
uint256 nonce,
Signature[] memory sigs
) internal view {
bytes32 msgHash = keccak256(
abi.encodePacked(ATTEST_MESSAGE_PREFIX, blockNumber, blockHash, depositRoot, stakingModuleId, keysOpIndex)
abi.encodePacked(ATTEST_MESSAGE_PREFIX, blockNumber, blockHash, depositRoot, stakingModuleId, nonce)
);

address prevSignerAddr = address(0);
Expand Down
Loading