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

test: vaults fuzzing #918

Draft
wants to merge 20 commits into
base: feat/vaults
Choose a base branch
from
Draft

Conversation

sergeyWh1te
Copy link

Test shareRate with fuzzing

Copy link

github-actions bot commented Jan 10, 2025

badge

Hardhat Unit Tests Coverage Summary

Filename                                                       Stmts    Miss  Cover    Missing
-----------------------------------------------------------  -------  ------  -------  ------------------------------------------------------------------------------
contracts/0.4.24/Lido.sol                                        201      13  93.53%   740-789, 946-947
contracts/0.4.24/StETH.sol                                        79       0  100.00%
contracts/0.4.24/StETHPermit.sol                                  15       0  100.00%
contracts/0.4.24/lib/Packed64x4.sol                                5       0  100.00%
contracts/0.4.24/lib/SigningKeys.sol                              36       0  100.00%
contracts/0.4.24/lib/StakeLimitUtils.sol                          37       0  100.00%
contracts/0.4.24/nos/NodeOperatorsRegistry.sol                   512       0  100.00%
contracts/0.4.24/oracle/LegacyOracle.sol                          72       0  100.00%
contracts/0.4.24/utils/Pausable.sol                                9       0  100.00%
contracts/0.4.24/utils/Versioned.sol                               5       0  100.00%
contracts/0.6.12/WstETH.sol                                       17       0  100.00%
contracts/0.8.25/Accounting.sol                                   90      86  4.44%    114-487
contracts/0.8.25/interfaces/ILido.sol                              0       0  100.00%
contracts/0.8.25/interfaces/IOracleReportSanityChecker.sol         0       0  100.00%
contracts/0.8.25/interfaces/IPostTokenRebaseReceiver.sol           0       0  100.00%
contracts/0.8.25/interfaces/IStakingRouter.sol                     0       0  100.00%
contracts/0.8.25/interfaces/IWithdrawalQueue.sol                   0       0  100.00%
contracts/0.8.25/utils/PausableUntilWithRoles.sol                  3       0  100.00%
contracts/0.8.25/vaults/BeaconChainDepositLogistics.sol           21       2  90.48%   57, 60
contracts/0.8.25/vaults/Dashboard.sol                             85       3  96.47%   170, 438, 479
contracts/0.8.25/vaults/Delegation.sol                            73       1  98.63%   340
contracts/0.8.25/vaults/StakingVault.sol                          68       0  100.00%
contracts/0.8.25/vaults/VaultFactory.sol                          22       0  100.00%
contracts/0.8.25/vaults/VaultHub.sol                             151     111  26.49%   125-138, 197-286, 301-504, 518
contracts/0.8.25/vaults/interfaces/IBeaconProxy.sol                0       0  100.00%
contracts/0.8.25/vaults/interfaces/IStakingVault.sol               0       0  100.00%
contracts/0.8.4/WithdrawalsManagerProxy.sol                       61       0  100.00%
contracts/0.8.9/BeaconChainDepositor.sol                          21       2  90.48%   48, 51
contracts/0.8.9/Burner.sol                                        72       0  100.00%
contracts/0.8.9/DepositSecurityModule.sol                        128       0  100.00%
contracts/0.8.9/EIP712StETH.sol                                   16       0  100.00%
contracts/0.8.9/LidoExecutionLayerRewardsVault.sol                16       0  100.00%
contracts/0.8.9/LidoLocator.sol                                   20       0  100.00%
contracts/0.8.9/OracleDaemonConfig.sol                            28       0  100.00%
contracts/0.8.9/StakingRouter.sol                                316       0  100.00%
contracts/0.8.9/WithdrawalQueue.sol                               88       0  100.00%
contracts/0.8.9/WithdrawalQueueBase.sol                          146       0  100.00%
contracts/0.8.9/WithdrawalQueueERC721.sol                         89       0  100.00%
contracts/0.8.9/WithdrawalVault.sol                               21       0  100.00%
contracts/0.8.9/lib/Math.sol                                       4       0  100.00%
contracts/0.8.9/lib/PositiveTokenRebaseLimiter.sol                22      22  0.00%    88-172
contracts/0.8.9/lib/UnstructuredRefStorage.sol                     2       0  100.00%
contracts/0.8.9/oracle/AccountingOracle.sol                      190       2  98.95%   154-155
contracts/0.8.9/oracle/BaseOracle.sol                             89       1  98.88%   397
contracts/0.8.9/oracle/HashConsensus.sol                         263       1  99.62%   1005
contracts/0.8.9/oracle/ValidatorsExitBusOracle.sol                91      91  0.00%    96-461
contracts/0.8.9/proxy/OssifiableProxy.sol                         17       0  100.00%
contracts/0.8.9/sanity_checks/OracleReportSanityChecker.sol      218      56  74.31%   195, 232, 273-324, 413-441, 495-507, 558-561, 569, 578, 586, 697, 702-747, 802
contracts/0.8.9/utils/DummyEmptyContract.sol                       0       0  100.00%
contracts/0.8.9/utils/PausableUntil.sol                           31       0  100.00%
contracts/0.8.9/utils/Versioned.sol                               11       0  100.00%
contracts/0.8.9/utils/access/AccessControl.sol                    23       0  100.00%
contracts/0.8.9/utils/access/AccessControlEnumerable.sol           9       0  100.00%
contracts/common/utils/PausableUntil.sol                          29       1  96.55%   33
contracts/testnets/sepolia/SepoliaDepositAdapter.sol              21      21  0.00%    49-100
TOTAL                                                           3543     413  88.34%

Diff against master

Filename                                                       Stmts    Miss  Cover
-----------------------------------------------------------  -------  ------  --------
contracts/0.4.24/Lido.sol                                        -11     +13  -6.47%
contracts/0.4.24/StETH.sol                                        +7       0  +100.00%
contracts/0.8.25/Accounting.sol                                  +90     +86  +4.44%
contracts/0.8.25/interfaces/ILido.sol                              0       0  +100.00%
contracts/0.8.25/interfaces/IOracleReportSanityChecker.sol         0       0  +100.00%
contracts/0.8.25/interfaces/IPostTokenRebaseReceiver.sol           0       0  +100.00%
contracts/0.8.25/interfaces/IStakingRouter.sol                     0       0  +100.00%
contracts/0.8.25/interfaces/IWithdrawalQueue.sol                   0       0  +100.00%
contracts/0.8.25/utils/PausableUntilWithRoles.sol                 +3       0  +100.00%
contracts/0.8.25/vaults/BeaconChainDepositLogistics.sol          +21      +2  +90.48%
contracts/0.8.25/vaults/Dashboard.sol                            +85      +3  +96.47%
contracts/0.8.25/vaults/Delegation.sol                           +73      +1  +98.63%
contracts/0.8.25/vaults/StakingVault.sol                         +68       0  +100.00%
contracts/0.8.25/vaults/VaultFactory.sol                         +22       0  +100.00%
contracts/0.8.25/vaults/VaultHub.sol                            +151    +111  +26.49%
contracts/0.8.25/vaults/interfaces/IBeaconProxy.sol                0       0  +100.00%
contracts/0.8.25/vaults/interfaces/IStakingVault.sol               0       0  +100.00%
contracts/0.8.9/Burner.sol                                        +1       0  +100.00%
contracts/0.8.9/LidoLocator.sol                                   +2       0  +100.00%
contracts/0.8.9/lib/PositiveTokenRebaseLimiter.sol                 0     +22  -100.00%
contracts/0.8.9/sanity_checks/OracleReportSanityChecker.sol      -14     +56  -25.69%
contracts/common/utils/PausableUntil.sol                         +29      +1  +96.55%
TOTAL                                                           +527    +295  -7.75%

Results for commit: 7d05ee2

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Member

@tamtamchik tamtamchik left a comment

Choose a reason for hiding this comment

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

Great start!

Some suggestions and comments left.

Also, looks like it need to me merged with vaults branch once again, because some tests are failing.

test/0.8.25/vaults/contracts/Protocol__Deployment.t.sol Outdated Show resolved Hide resolved
test/0.8.25/vaults/contracts/Protocol__Deployment.t.sol Outdated Show resolved Hide resolved
test/0.8.25/vaults/contracts/Protocol__Deployment.t.sol Outdated Show resolved Hide resolved
test/0.8.25/vaults/contracts/Protocol__Deployment.t.sol Outdated Show resolved Hide resolved
test/0.8.25/vaults/contracts/ShareRate.t.sol Outdated Show resolved Hide resolved
test/0.8.25/vaults/contracts/ShareRate.t.sol Outdated Show resolved Hide resolved
import {StdUtils} from "forge-std/StdUtils.sol";
import {Vm} from "forge-std/Vm.sol";
import {console2} from "forge-std/console2.sol";
import {Protocol__Deployment, ILido} from "./Protocol__Deployment.t.sol";
Copy link
Member

Choose a reason for hiding this comment

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

Maybe better naming is Protocol__Context so as to put methods related to the protocol interactions later, e.g., adding / removing permissions, impersonating agents, etc...

test/0.8.25/vaults/contracts/ShareRate.t.sol Outdated Show resolved Hide resolved
test/0.8.25/vaults/contracts/ShareRate.t.sol Outdated Show resolved Hide resolved
test/0.8.25/vaults/contracts/ShareRate.t.sol Outdated Show resolved Hide resolved
@folkyatina folkyatina marked this pull request as draft January 19, 2025 11:23
@tamtamchik tamtamchik force-pushed the feat/vaults-fuzzing-share-rate branch from 1d41029 to 7d05ee2 Compare January 20, 2025 12:02
@tamtamchik tamtamchik changed the title feat: test shareRate with fuzzing test: vaults fuzzing Jan 28, 2025
Copy link
Member

@tamtamchik tamtamchik left a comment

Choose a reason for hiding this comment

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

No major issues, at least for now, need to validate boundaries and maybe add more invariants.


// 0.002792 * 10^18
// 0.0073 * 10^18
uint256 constant maxYiedPerOperatorWei = 2_792_000_000_000_000; // which % of slashing could be?
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
uint256 constant maxYiedPerOperatorWei = 2_792_000_000_000_000; // which % of slashing could be?
uint256 constant maxYieldPerOperatorWei = 2_792_000_000_000_000; // which % of slashing could be?

?

// for testing purposes only
pragma solidity ^0.8.0;

import "foundry/lib/forge-std/src/Vm.sol";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import "foundry/lib/forge-std/src/Vm.sol";

Already present below

import {StdCheats} from "forge-std/StdCheats.sol";
import {StdUtils} from "forge-std/StdUtils.sol";
import {Vm} from "forge-std/Vm.sol";
import {console2} from "../../foundry/lib/forge-std/src/console2.sol";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import {console2} from "../../foundry/lib/forge-std/src/console2.sol";
import {console2} from "forge-std/console2.sol";

Copy link
Member

Choose a reason for hiding this comment

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

Better to put it into test/0.8.25/contracts and rename it like SecondOpinionOracle__MockForAccountingFuzzing

@@ -3,8 +3,11 @@

pragma solidity 0.8.9;

import {StakingRouter} from "contracts/0.8.9/StakingRouter.sol";

contract StakingRouter__MockForLidoAccounting {
Copy link
Member

Choose a reason for hiding this comment

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

Noticed that this file is being used in the accounting unit tests. It would be better to clone the file and rename it to StakingRouter__MockForLidoAccountingFuzzing to clarify its purpose. Separating the mocks will simplify mock management and ensure that they do not interfere with other tests.

* forge-config: default.invariant.depth = 256
* forge-config: default.invariant.fail-on-revert = true
*/
function invariant_totalShares() public view {
Copy link
Member

Choose a reason for hiding this comment

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

💡 Maybe add an invariant that lido.getExternalShares = startExternalBalance + mintedExternal - burnedExternal? So we'll know it something is odd inside a math for external shares?

// if (_report.timestamp >= block.timestamp) revert IncorrectReportTimestamp(_report.timestamp, block.timestamp);
vm.warp(_timestamp + 1);

fuzz._lidoExecutionLayerRewardVaultWei = bound(fuzz._lidoExecutionLayerRewardVaultWei, 0, 1_000) * 1 ether;
Copy link
Member

Choose a reason for hiding this comment

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

Providing comments on why the bounding appears as it does would be helpful during reviews and test updates.


function handleOracleReport(FuzzValues memory fuzz) external {
uint256 _timeElapsed = 86_400;
uint256 _timestamp = 1_737_366_566 + _timeElapsed;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a specific timestamp? Can block.timestamp be used?

}

contract AccountingHandler is CommonBase, StdCheats, StdUtils {
struct Ghost {
Copy link
Member

Choose a reason for hiding this comment

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

💡 Maybe add a boundary holder to track minimum and maximum values used in all the runs, so we can review them after the test and ensure we're not missing any potential values chunks?


pragma solidity 0.8.9;

contract SecondOpinionOracle__Mock {
Copy link
Member

Choose a reason for hiding this comment

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

Not sure that we need that mock. We can harness OracleReportSanityChecker and just return true on _askSecondOpinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants