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

Secure Beanstalk Invariants #821

Merged
merged 39 commits into from
Apr 30, 2024
Merged

Conversation

funderbrker
Copy link
Contributor

@funderbrker funderbrker commented Apr 9, 2024

This PR implements 3 invariants

fundsSafu

Ensures that Beanstalk contract holds enough assets to pay all users all of their expected existing funds.
This invariant applies to every writing function in Beanstalk. There are a few exceptions in the Diamond system.

noNetFlow

Verifies that no assets have entered or exited Beanstalk during the function execution and that Stalk has not decrease (which should never happen without some underlying asset changes). This applies to the majority of writing functions, excepting functions that are explicitly converting or transferring assets into or out of Beanstalk on behalf of a user. Also excepting diamond features.

noSupplyChange

Verifies that the supply of Bean has not changed during execution. ie there has been no minting or burning. This applies to vast majority of writing functions, excepting the functions that explicitly mint or burn (like sunrise or sow). Also excludes diamond features.

The set of assets checked in these invariants is the list of Silo assets at the beginning of the call. Currently, this includes Beans and LP tokens. The value underlying the LP cannot and should not be verified inside of Beanstalk. The list of covered tokens can be expanded to a known set, but should not be an infinitely scaling set of n possible internal ERC20s.

@funderbrker funderbrker force-pushed the secure-beanstalk-invariants branch from 95752fd to 9b539f6 Compare April 12, 2024 02:53
@funderbrker
Copy link
Contributor Author

Should depot facet have the noSupplyChange invariant?

Currently yes bc its use is intended to be moving control from from Beanstalk to external. Sequences of Beanstalk actions should be achieved using external pipeline or Farm/AdvancedFarm.

@funderbrker funderbrker marked this pull request as ready for review April 16, 2024 04:24
@funderbrker
Copy link
Contributor Author

omw to implement some sort of tests...

Copy link
Contributor

@Brean0 Brean0 left a comment

Choose a reason for hiding this comment

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

Review I. Overall looking on the right track!

protocol/contracts/beanstalk/AppStorage.sol Show resolved Hide resolved
protocol/contracts/beanstalk/Invariable.sol Outdated Show resolved Hide resolved
protocol/contracts/beanstalk/Invariable.sol Outdated Show resolved Hide resolved
protocol/contracts/beanstalk/Invariable.sol Outdated Show resolved Hide resolved
protocol/contracts/beanstalk/Invariable.sol Show resolved Hide resolved
protocol/contracts/beanstalk/farm/DepotFacet.sol Outdated Show resolved Hide resolved
protocol/contracts/beanstalk/init/InitInvariants.sol Outdated Show resolved Hide resolved
protocol/contracts/beanstalk/farm/TokenFacet.sol Outdated Show resolved Hide resolved
protocol/contracts/beanstalk/init/InitInvariants.sol Outdated Show resolved Hide resolved
@funderbrker funderbrker force-pushed the secure-beanstalk-invariants branch from e5b4fdf to 385b9c9 Compare April 29, 2024 10:26
@funderbrker funderbrker force-pushed the secure-beanstalk-invariants branch from 385b9c9 to a38a8e2 Compare April 29, 2024 10:27
@funderbrker funderbrker merged commit 3dec045 into secure-beanstalk Apr 30, 2024
1 of 3 checks passed
@funderbrker funderbrker deleted the secure-beanstalk-invariants branch April 30, 2024 05:28
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.

2 participants