8000 feat: add solvency test for staking vault by tamtamchik · Pull Request #997 · lidofinance/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add solvency test for staking vault #997

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

Merged
merged 13 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
run: forge --version

- name: Run fuzzing and invariant tests
run: forge test -vvv
run: forge test
54 changes: 54 additions & 0 deletions test/0.8.25/vaults/staking-vault/RandomLib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import "@openzeppelin/contracts-v5.2/utils/math/Math.sol";

library RandomLib {
using Math for uint256;

uint256 private constant Q96 = 2 ** 96;
uint256 private constant D18 = 1e18;

struct Storage {
uint256 seed;
}

function rand(Storage storage s) internal returns (uint256) {
s.seed = uint256(keccak256(abi.encodePacked(block.timestamp, block.prevrandao, s.seed)));
return s.seed;
}

function randInt(Storage storage s, uint256 maxValue) internal returns (uint256) {
return rand(s) % (maxValue + 1);
}

function randInt(Storage storage s, uint256 minValue, uint256 maxValue) internal returns (uint256) {
if (maxValue < minValue) {
revert("RandomLib: maxValue < minValue");
}
return (rand(s) % (maxValue - minValue + 1)) + minValue;
}

function randFloatX96(Storage storage s, uint256 minValue, uint256 maxValue) internal returns (uint256) {
return randInt(s, minValue * Q96, maxValue * Q96);
}

function randBool(Storage storage s) internal returns (bool) {
return rand(s) & 1 == 1;
}

function randAddress(Storage storage s) internal returns (address) {
return address(uint160(rand(s)));
}

function randAmountD18(Storage storage s) internal returns (uint256 result) {
uint256 result_x96 = randFloatX96(s, D18, 10 * D18);
if (randBool(s)) {
uint256 b_x96 = randFloatX96(s, 1, 1e6);
result = result_x96.mulDiv(b_x96, Q96) / Q96;
} else {
uint256 b_x96 = randFloatX96(s, 1e1, 1e10);
result = result_x96.mulDiv(Q96, b_x96) / Q96;
}
}
}
Loading
Loading
0