Skip to content

Commit

Permalink
fix: exluced proxyAdmin when fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
0xvv committed Dec 6, 2024
1 parent c852012 commit d3d77a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/forge-std
15 changes: 12 additions & 3 deletions src/contracts/StakingContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ contract StakingContract {
}

/// @notice Utility to ban a user, exits the validators provided if account is not OFAC sanctioned
/// @notice Blocks the account from depositing, the account is still alowed to exit & withdraw if not sanctioned
/// @param _account Account to ban
/// @param _publicKeys Public keys to exit
function blockAccount(address _account, bytes calldata _publicKeys) external onlyAdmin {
Expand All @@ -753,10 +754,16 @@ contract StakingContract {
_requestExits(_publicKeys, _account);
}

/// @notice Utility to unban a user
/// @param _account Account to unban
function unblock(address _account) external onlyAdmin {
StakingContractStorageLib.getBlocklist().value[_account] = false;
}

/// @notice Utility to check if an account is blocked or sanctioned
/// @param _account Account to check
/// @return isBlocked True if the account is blocked
/// @return isSanctioned True if the account is sanctioned, always false if not sanctions oracle is set
function isBlockedOrSanctioned(address _account) public view returns (bool isBlocked, bool isSanctioned) {
address sanctionsOracle = StakingContractStorageLib.getSanctionsOracle();
if (sanctionsOracle != address(0)) {
Expand Down Expand Up @@ -810,6 +817,9 @@ contract StakingContract {
StakingContractStorageLib.getExitRequestMap().value[_publicKeyRoot] = _value;
}

/// @notice Function to emit the ExitRequest event for each public key
/// @param publicKeys Concatenated public keys
/// @param owner Address of the expected owner of the public keys
function _requestExits(bytes calldata publicKeys, address owner) internal {
if (publicKeys.length % PUBLIC_KEY_LENGTH != 0) {
revert InvalidPublicKeys();
Expand Down Expand Up @@ -984,7 +994,6 @@ contract StakingContract {
address _dispatcher
) internal {
bytes32 publicKeyRoot = _getPubKeyRoot(_publicKey);
address withdrawer = _getWithdrawer(publicKeyRoot);
_revertIfSanctioned(msg.sender);
bytes32 feeRecipientSalt = sha256(abi.encodePacked(_prefix, publicKeyRoot));
address implementation = StakingContractStorageLib.getFeeRecipientImplementation();
Expand All @@ -1002,7 +1011,7 @@ contract StakingContract {
}
}

function _revertIfSanctionedOrBlocked(address account) internal {
function _revertIfSanctionedOrBlocked(address account) internal view {
address sanctionsOracle = StakingContractStorageLib.getSanctionsOracle();
if (sanctionsOracle != address(0)) {
if (ISanctionsOracle(sanctionsOracle).isSanctioned(account)) {
Expand All @@ -1014,7 +1023,7 @@ contract StakingContract {
}
}

function _revertIfSanctioned(address account) internal {
function _revertIfSanctioned(address account) internal view {
address sanctionsOracle = StakingContractStorageLib.getSanctionsOracle();
if (sanctionsOracle != address(0)) {
if (ISanctionsOracle(sanctionsOracle).isSanctioned(account)) {
Expand Down
12 changes: 9 additions & 3 deletions src/test/StakingContract.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,7 @@ contract StakingContractBehindProxyTest is Test {

SanctionsOracle oracle;

address internal proxyAdmin = address(42);
event ExitRequest(address caller, bytes pubkey);

function setUp() public {
Expand All @@ -2065,17 +2066,17 @@ contract StakingContractBehindProxyTest is Test {
address cldImpl = address(new ConsensusLayerFeeDispatcher(1));
address stakingContractImpl = address(new StakingContract());

stakingContract = StakingContract(payable(address(new TUPProxy(stakingContractImpl, address(12345), ""))));
stakingContract = StakingContract(payable(address(new TUPProxy(stakingContractImpl, proxyAdmin, ""))));

eld = ExecutionLayerFeeDispatcher(
payable(
address(new TUPProxy(eldImpl, address(1), abi.encodeWithSignature("initELD(address)", stakingContract)))
address(new TUPProxy(eldImpl, proxyAdmin, abi.encodeWithSignature("initELD(address)", stakingContract)))
)
);

cld = ConsensusLayerFeeDispatcher(
payable(
address(new TUPProxy(cldImpl, address(1), abi.encodeWithSignature("initCLD(address)", stakingContract)))
address(new TUPProxy(cldImpl, proxyAdmin, abi.encodeWithSignature("initCLD(address)", stakingContract)))
)
);

Expand Down Expand Up @@ -2178,6 +2179,7 @@ contract StakingContractBehindProxyTest is Test {
}

function test_deposit_withsanctions_senderSanctioned(address user) public {
vm.assume(user != proxyAdmin);
oracle.setSanction(user, true);

vm.prank(admin);
Expand All @@ -2192,6 +2194,8 @@ contract StakingContractBehindProxyTest is Test {
}

function test_deposit_withSanctions_SenderClear(address user) public {
vm.assume(user != proxyAdmin);

vm.prank(admin);
stakingContract.setSanctionsOracle(address(oracle));

Expand All @@ -2203,6 +2207,8 @@ contract StakingContractBehindProxyTest is Test {
}

function test_deposit_BlockedUser(address user) public {
vm.assume(user != proxyAdmin);

vm.prank(admin);
stakingContract.blockAccount(user, "");

Expand Down

0 comments on commit d3d77a5

Please sign in to comment.