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

Feature/withdrawals PoC #446

Closed
wants to merge 127 commits into from
Closed

Feature/withdrawals PoC #446

wants to merge 127 commits into from

Conversation

TheDZhon
Copy link
Contributor

Hazardous areas, be careful

Remove:
- Aragon vault recovery
- Insurance fund
- EL rewards setter (use setProtocolContracts)
- staking limit views

Update docs about Eth2 and Ethereum 2.0
Copy link
Contributor Author

@TheDZhon TheDZhon left a comment

Choose a reason for hiding this comment

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

Just a bunch of review comments

contracts/0.4.24/Lido.sol Outdated Show resolved Hide resolved
contracts/0.4.24/Lido.sol Outdated Show resolved Hide resolved
/// @dev Credentials which allows the DAO to withdraw Ether on the 2.0 side
bytes32 internal constant WITHDRAWAL_CREDENTIALS_POSITION = keccak256("lido.Lido.withdrawalCredentials");

/// @dev Amount of eth in deposit buffer to reserve for withdrawals
bytes32 internal constant WITHDRAWAL_RESERVE_POSITION = keccak256("lido.Lido.withdrawalReserve");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

BUFFERED_ETHER_WITHDRAWALS_RESERVE_POSITION?

Copy link
Member

Choose a reason for hiding this comment

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

Imo, it's a bit overkill. Too long and still not really clear. Should figure out some concise abstraction here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, let's find another one later

contracts/0.4.24/Lido.sol Outdated Show resolved Hide resolved
@@ -458,59 +472,53 @@ contract Lido is ILido, StETH, AragonApp {
emit ELRewardsWithdrawalLimitSet(_limitPoints);
}

function getBufferWithdrawalsReserve() public returns (uint256) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

getBufferedEtherWithdrawalsReserve?

contracts/0.4.24/Lido.sol Outdated Show resolved Hide resolved
contracts/0.4.24/Lido.sol Outdated Show resolved Hide resolved

for (uint256 i = 0; i < _requestIdToFinalizeUpTo.length; i++) {
uint256 lastIdToFinalize = _requestIdToFinalizeUpTo[i];
require(lastIdToFinalize >= withdrawal.finalizedRequestsCounter(), "BAD_FINALIZATION_PARAMS");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the future: should check the block of the request

contracts/0.4.24/Lido.sol Outdated Show resolved Hide resolved

uint256 lockedEtherAccumulator = 0;

for (uint256 i = 0; i < _requestIdToFinalizeUpTo.length; i++) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like all storage-access ops are performed within a loop.

Maybe worth move out them (I know that currently every oracle report is supposed to invoke only a single iteration, though, may change in the future).

Copy link
Member

Choose a reason for hiding this comment

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

Yep, it's naive implementation and subject to further optimisation.

Copy link
Member

Choose a reason for hiding this comment

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

Rechecked it and didn't get which ops can be moved out exactly. Can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, the major consideration was about burnShares.
Other possible directions:

  • require(lastIdToFinalize >= withdrawal.finalizedRequestsCounter(), "BAD_FINALIZATION_PARAMS") (don't call each iteration)
  • withdrawal.calculateFinalizationParams (accept vector params)
  • withdrawal.finalize.value(transferToWithdrawalBuffer) (accept vector params)

/// The bitmask of the oracle members that pushed their reports
bytes32 internal constant REPORTS_BITMASK_POSITION = keccak256("lido.CommitteeQuorum.reportsBitmask");

///! STRUCTURED STORAGE OF THE CONTRACT
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe go with unstructured since we use a contemporary solidity version
https://gist.github.com/skozin/344d9c7d2270cac0c3f9373c2f43c846

}


function _handleMemberReport(address _reporter, bytes memory _report)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can simplify if forbid <50% participation quorum

}


function _handleMemberReport(address _reporter, bytes memory _report)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe should emit an event

return MEMBER_NOT_FOUND;
}

function _clearReporting() internal {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe should emit an event either

// decision
uint256 newDepositBufferWithdrawalsReserve;
uint256[] requestIdToFinalizeUpTo;
uint256[] finalizationPooledEtherAmount;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be reduced to the single value (holding the ratio)

)
external
{
assert(1 == ((1 << (MAX_MEMBERS - 1)) >> (MAX_MEMBERS - 1))); // static assert
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe rewrite this to be more readable?

MemberReport calldata _report
) external {
BeaconSpec memory beaconSpec = _getBeaconSpec();
bool hasEpochAdvanced = _validateAndUpdateExpectedEpoch(_report.epochId, beaconSpec);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like the same member can advance the epoch preventing for reports finalization
maybe address this by setting cooldown time or checking the epoch number against block number / timestamp?

}


function _doWorkAfterReportingToLido(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

_handleStETHRebase

internal
view
{
// TODO: update sanity checks
Copy link
Contributor Author

Choose a reason for hiding this comment

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

100%

contracts/0.8.9/OrderedCallbacksArray.sol Outdated Show resolved Hide resolved
);

event CommitteeMemberReported(
address[] stakingModules,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should evaluate data packing efficiency

contracts/0.8.9/WithdrawalQueue.sol Outdated Show resolved Hide resolved
contracts/0.8.9/WithdrawalQueue.sol Outdated Show resolved Hide resolved
contracts/0.8.9/WithdrawalQueue.sol Outdated Show resolved Hide resolved
contracts/0.8.9/WithdrawalQueue.sol Show resolved Hide resolved
contracts/0.8.9/WithdrawalQueue.sol Show resolved Hide resolved
contracts/0.8.9/WithdrawalQueue.sol Show resolved Hide resolved
contracts/0.8.9/WithdrawalQueue.sol Outdated Show resolved Hide resolved
contracts/0.8.9/WithdrawalQueue.sol Show resolved Hide resolved
contracts/0.8.9/WithdrawalQueue.sol Outdated Show resolved Hide resolved
using LimitUnstructuredStorage for bytes32;

event ValidatorExitRequest(
address indexed stakingModule,
Copy link
Contributor Author

@TheDZhon TheDZhon Jan 5, 2023

Choose a reason for hiding this comment

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

decided to go with module id, not address

@folkyatina
Copy link
Member

Closing as it's merged into #482. To be continued in a new branch

@folkyatina folkyatina closed this Jan 12, 2023
@folkyatina folkyatina deleted the feature/withdrawals-poc branch January 17, 2023 09:38
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.

3 participants