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

feat(RewardsStreamerMP): introduce leave() function #78

Merged
merged 2 commits into from
Dec 1, 2024

Conversation

0x-r4bbit
Copy link
Collaborator

@0x-r4bbit 0x-r4bbit commented Nov 28, 2024

This function allows users to leave() the system if they can't or
don't want to trust the stake manager. This is the case when the owner
of the stake manager performs an upgrade.

In case of such an upgrade, the stake manager will be marked as not
trusted which prevents the user from staking, unstaking, locking etc.

The user can then either explicitly trust stake manager (will happen in
future changes) to enable the vault's functionality again, or, leave()
the system at which point it will try to perform a benign leave()
operation and then move the funds out of the vault.

Closes #66

@0x-r4bbit 0x-r4bbit force-pushed the feat/leave-upgradable branch from 0477df4 to 175e3b5 Compare November 29, 2024 10:19
@0x-r4bbit 0x-r4bbit changed the base branch from proxy-upgradability to feat/upgradeability November 29, 2024 10:20
@0x-r4bbit 0x-r4bbit changed the title Upgradability and trust assumptions feat(RewardsStreamerMP): introduce leave() function Nov 29, 2024
@0x-r4bbit 0x-r4bbit force-pushed the feat/leave-upgradable branch from 175e3b5 to 3e6c25e Compare November 29, 2024 10:32
@0x-r4bbit 0x-r4bbit force-pushed the feat/leave-upgradable branch from 3e6c25e to ec2dc08 Compare November 29, 2024 10:56
@@ -136,13 +189,11 @@ contract StakeVault is Ownable {
}

function _stake(uint256 _amount, uint256 _seconds, address _source) internal {
stakeManager.stake(_amount, _seconds);
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for reordering this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just o adhere to CEI pattern. I think this should've been the case from the get go.


import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";

contract StakeManagerProxy is ERC1967Proxy {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this contract going to be deployed? If not, it should be an interface, or at least abstract.
I think that having the IStakeManagerProxy should be enough. Why we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need a contract that exposes the implementation address of the ERC1967 proxy via a public function.
Otherwise StakeVault is unable to determine the implementation address of the StakeManager as there's no way to get the value of a storage slot of an external contract within the EVM.

That proxy implementation here is the one that will be deployed for every stakemanager.

@@ -29,7 +31,7 @@ contract RewardsStreamerMPTest is Test {
bytes memory initializeData =
abi.encodeCall(RewardsStreamerMP.initialize, (address(this), address(stakingToken), address(rewardToken)));
address impl = address(new RewardsStreamerMP());
address proxy = address(new ERC1967Proxy(impl, initializeData));
address proxy = address(new StakeManagerProxy(impl, initializeData));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we use the default proxy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@0x-r4bbit 0x-r4bbit force-pushed the feat/upgradeability branch from a30eb94 to 816f72b Compare December 1, 2024 07:00
@0x-r4bbit 0x-r4bbit changed the base branch from feat/upgradeability to main December 1, 2024 07:07
This function allows users to `leave()` the system if they can't or
don't want to trust the stake manager. This is the case when the owner
of the stake manager performs an upgrade.

In case of such an upgrade, the stake manager will be marked as not
trusted which prevents the user from staking, unstaking, locking etc.

The user can then either explicitly trust stake manager (will happen in
future changes) to enable the vault's functionality again, or, `leave()`
the system at which point it will try to perform a benign `leave()`
operation and then move the funds out of the vault.

Closes #66
…k overflow

If there's a malicious upgrade which causes a stack overflow error when
`leave()` is called, the user of the vault should still be able to get
their funds out.

This commit adds a test that proofs this is happening.
@0x-r4bbit 0x-r4bbit force-pushed the feat/leave-upgradable branch from dfe8929 to 09fc92d Compare December 1, 2024 07:13
@0x-r4bbit 0x-r4bbit merged commit 4968ad4 into main Dec 1, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Allow accounts to exit the system
2 participants