Commit Graph

173 Commits

Author SHA1 Message Date
Ricardo Guilherme Schmidt 4ce5060347
feat(certora): Add StakeMath.conf 2024-11-25 12:24:29 -03:00
Ricardo Guilherme Schmidt cb81a7609c
refactor(certora): Reorganize files, add proper descriptions, fix conf files and add summaries 2024-11-25 12:24:09 -03:00
Ricardo Guilherme Schmidt ff94f5e46c
chore(contracts): Normalize function signatures 2024-11-25 12:22:27 -03:00
Ricardo Guilherme Schmidt 6af73d3883
refactor(StakeManager): Extract Updated StakeManager to its own contract, to remove logic not interesting for first contract.
refactor(StakeManager): Move Epoch logic to EpochMath.sol
refactor(MutliplierPointMath): rename functions
feat(MutliplierPointMath):  Add missing functions from spec
feat(StakeMath): change to use custom errors
fix(StakeMath): fix _estimateLockTime
chore(IStakeConstants): remove unused import
refactor(StakeManager): move Account struct to
IStakeManager
refactor(StakeManager): move Epoch struct to EpochMath
refactor(IStakeManger): move errors to StakeMath
chore(.vscode): Fix remappings on IDE
2024-11-25 10:31:10 -03:00
Ricardo Guilherme Schmidt 99c73be3c4 fix(certora/specs): Make rules work again 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 520e4f8aec chore(certora/confs): lint files 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 5bc7b564e8 choe(MaxMPRule.conf): remove args and settings 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 08b8910503 chore(ci.yml): update certora to 7.17.2 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 377f01903f chore(cerotra/spec): fix rules 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 94858a4eb3 feat(EpochMath): add EpochMath contract and integrate with StakeManager 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 9b7836c8cf refactor(StakeManager): Use maxMP instead of totalMP 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 3f4f6a7aaf chore: update interface and update Solidity version to 0.8.27 across all files 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 2289457daf update math 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 173ce9b15a Update specs and interface 2024-11-15 02:40:11 -03:00
Ricardo Guilherme Schmidt 365551b18e refactor(StakeManager): extract interfaces and rename variables to merge functionalty with StakingRewardStreamer 2024-11-15 02:40:11 -03:00
r4bbit feb6dd1530 fix(specs): make `sumOfMultiplierPointsIsMultiplierpoints` work again
This invariant failed as the prover started making wrong assumptions
about the relationship between anyone's account's `totalMP` and its
`balance`, as well as an account's `bonusMP` and its `balance`.

This commit fixes it by adding the necessary invariants to proof the
property.
2024-11-15 02:40:11 -03:00
r4bbit df0257c343 fix(certora): exclude `stake()` from rule that checks account balance
change

The rule is failing since we've removed the `lockUntil > 0` check in
`stake` and `processAccount` is no longer used in `stake()`.
The rule requires `lockUntil > 0` so it will always fail there and can't
find a non-reverting cases (which makes the rule pass).

The reason it hasn't happened before was because:

The rule required account.lockUntil > 0
Stake required lockUntil > 0 || account balance == 0

Also this commit adds an invariant:

add invariant that account balance == 0 => accountMP == 0
2024-11-15 02:40:11 -03:00
r4bbit c0bf36d14b fix(specs): make `sumOfMultiplierPointsIsMultiplierpoints` work again
This invariant failed as the prover started making wrong assumptions
about the relationship between anyone's account's `totalMP` and its
`balance`, as well as an account's `bonusMP` and its `balance`.

This commit fixes it by adding the necessary invariants to proof the
property.
2024-10-13 08:20:25 -03:00
Ricardo Guilherme Schmidt fc3578ee48 chore(StakeManager.spec): fix wrong Sload requirement 2024-10-13 08:20:25 -03:00
Ricardo Guilherme Schmidt f8d52e27e1 chore(StakeManager.spec): fix spec to don't load totalMP greater than current sumOfMultipliers 2024-10-13 08:20:25 -03:00
r4bbit 9d7aa39d9b fix(certora): exclude `stake()` from rule that checks account balance
change

The rule is failing since we've removed the `lockUntil > 0` check in
`stake` and `processAccount` is no longer used in `stake()`.
The rule requires `lockUntil > 0` so it will always fail there and can't
find a non-reverting cases (which makes the rule pass).

The reason it hasn't happened before was because:

The rule required account.lockUntil > 0
Stake required lockUntil > 0 || account balance == 0

Also this commit adds an invariant:

add invariant that account balance == 0 => accountMP == 0
2024-10-13 08:20:25 -03:00
Ricardo Guilherme Schmidt a34ae066a3 refactor(StakeManager): optimize stake and lock functionality by removing mintBonusMP function 2024-10-13 08:20:25 -03:00
r4bbit 9face30b63 try with standard server instead 2024-10-08 10:14:20 -03:00
r4bbit 7581c2a079 refactor(certora): move rule about MP not greater than max MP into own
spec

This is necessary because we need to run this rule on a custom config to
avoid timeouts.
2024-10-08 10:14:20 -03:00
Ricardo Guilherme Schmidt da6cac4e20 refactor(StakeManager): remove unused startTime field in Epoch struct and optimize epoch finalization and execution 2024-10-03 00:20:17 -03:00
Ricardo Guilherme Schmidt b6a95e3572 refactor(StakeManager): Abstact out codehash verification to better code reusability
chore(StakeManager): move out storage contract and rename it
2024-10-02 23:06:57 -03:00
Ricardo Guilherme Schmidt 769f32f718 refactor(StakeManager): replace epoch.startTime with a global startTime
As now all epochEnd() are multiples of EPOCH_SIZE, we can drop the startTime from the struct Epoch, and avoid storing an information that can be cheaply calculated on the fly.

- Refactored the StakeManager contract to optimize the finalization of epochs and execution of accounts and epochs.
- Replaced the Epoch.startTime with a new global variable startTime to keep track of the start time of the contract.
- Modified the finalizeEpoch function to use a temporary variable for the current epoch and calculate the epoch reward only for the current epoch.
- Updated the migrationInitialize function to set the start time using the new startTime variable.
- Modified the epochEnd function to calculate the end time of the current epoch using the startTime variable.
- Modified the newEpoch function to calculate the number of the next epoch based on the startTime variable.

refactor(StakeManager): set startTime as immutable, load startTime from previousManager at constructor, verify startTime is correct on initializeMigration
2024-09-26 15:41:35 -03:00
Ricardo Guilherme Schmidt 4a261e8b48 refactor(StakeManager): optimize epoch finalization and execution of accounts and epochs
This commit refactors the StakeManager contract to optimize the finalization and execution of epochs. It updates the function finalizeEpoch() to new function finalizeEpoch(uint256 _limitEpoch) that releases rewards for the current epoch and increases the epoch up to the specified limit. This allows for more efficient processing of epochs.

The changes also include updates to the executeEpoch() and executeAccount() functions to utilize the new finalizeEpoch() function. Additionally, a new function newEpoch() is introduced to calculate the last epoch that can be processed based on the current time. Now the executeAccount(account,limit) will also process epochs up to the specified limit.

Added a overload of the executeAccount to process the account up to the newEpoch()

Added a overload of the executeEpoch to allow the process of epochs up to a certain limit.

All methods now that finalizeEpoch will process the epochs up to the newEpoch().

These changes improve the overall performance, user expirience and reliability of the StakeManager contract.

chore(StakeManagerStartMigration.spec): add new function executeEpoch(uint256) to blockedWhenMigrating

fix(StakeManager.sol): Replace the check for pending migration in migrationInitialize with noPendingMigration modifier to avoid code duplication
2024-09-26 15:41:35 -03:00
Ricardo Guilherme Schmidt 142137dee7 fix(StakeManager): fix finalizeEpoch to use last epoch epochEnd and add tests to catch error 2024-09-26 15:41:35 -03:00
Ricardo Guilherme Schmidt 4a545a0ed4 chore(test): fix fuzzing function to properly test whats suppoused to and make it deterministic in amount of calls 2024-09-25 12:41:23 -03:00
Ricardo Guilherme Schmidt 85b88fa757 chore: improve comments and documentation in README.md 2024-09-25 07:00:02 -03:00
Ricardo Guilherme Schmidt 097bd05665 chore: update pull request template and README.md 2024-09-25 11:29:22 +02:00
Ricardo Guilherme Schmidt 653fe5a542 chore: update project description and author information, update README.md 2024-09-25 11:29:22 +02:00
Ricardo Guilherme Schmidt 474e7cacf5 chore(foundry.toml): update fuzzing settings 2024-09-23 06:10:17 -03:00
Ricardo Guilherme Schmidt 2a90b3e6ad chore(.gas-report, .gas-snapshot): update reports 2024-09-19 17:26:17 +02:00
r4bbit 40c5be49bc refactor(certora): introduce shared.spec to reuse helper functions
We have a couple of helper functions redefined in multiple spec files.
This commit introduces a `shared.spec` that provides such functions.

The file is then imported in other spec files, so we can make use of the
functions there.

Closes #87
2024-09-19 14:35:08 +02:00
Ricardo Guilherme Schmidt 3e5361f9be fix(StakeManager): change order of call of mintBonusMP to fix intended behavior. 2024-09-12 11:44:48 +02:00
Ricardo Guilherme Schmidt 0c58dfe241 test(StakeManager): add test to catch bug in minting more bonus MPs when stake with lock 2024-09-12 11:44:48 +02:00
Ricardo Guilherme Schmidt 8683376160 feat(StakeManager): optimizations on processAccount 2024-09-11 20:09:08 +02:00
Ricardo Guilherme Schmidt b19182ad20 chore(StakeManager): remove unnecessary `finalizeEpoch` modifier from `migrateTo`
Fixes #109
2024-09-11 16:43:59 +02:00
Ricardo Guilherme Schmidt 58ca65120f chore(StakeManager: remove irrelevant code from `_mintBonusMP` function
Fixes #108
2024-09-11 16:17:17 +02:00
Ricardo Guilherme Schmidt b2a0d0cf25 fix(StakeManager): use while loop instead of hacky for loop in process account
chore: lint again with foundry updated
2024-09-11 15:18:24 +02:00
Ricardo Guilherme Schmidt 3123df83d9 feat(StakeManager): add test for executing account with limit
chore: lint
2024-09-11 15:18:24 +02:00
Ricardo Guilherme Schmidt 0dd04a179e chore(package.json): fix gas-report command 2024-09-11 15:18:24 +02:00
Ricardo Guilherme Schmidt b312c59177 chore: add adorno command to package.json 2024-09-10 13:05:06 +02:00
r4bbit 5dec595a20 feat(StakeManager): implement multiplier points estimation
This commit introduces the internal accounting logic for accrueing
multiplier points, that will later be used to determine how many
experience points an account is eligible to.

The majority of the work here was done by @3esmit.
2024-09-10 08:51:35 +02:00
r4bbit 2465618007 chore: update pnpm lock 2024-09-10 08:51:35 +02:00
r4bbit f90a3ce365 chore(StakeManager): formatting as foundry changed its mind 2024-08-27 14:46:22 +02:00
r4bbit b62ac5233e chore(CI): update certora-cli to 7.10.2
This should fix a bug in the CLI that causes CI tasks to pass even
though prover runs are emitting errors.
2024-08-27 14:46:22 +02:00
r4bbit ead8db634c chore(ci): update certora CLI in CI
This update the certora cli to the latest version 7.10.1 in CI tasks.
2024-08-05 08:35:47 +02:00