From 6eebbb92adec1e8e46c1329ce10169189b79e5b6 Mon Sep 17 00:00:00 2001 From: adu Date: Mon, 8 Jul 2024 17:03:03 +0800 Subject: [PATCH] slither: remove unused state variables --- slither.config.json | 2 +- src/core/Bootstrap.sol | 2 + src/core/ClientGatewayLzReceiver.sol | 2 + src/core/CustomProxyAdmin.sol | 1 + src/core/ExoCapsule.sol | 4 +- src/core/ExocoreGateway.sol | 1 + src/core/NativeRestakingController.sol | 1 + src/libraries/BeaconChainProofs.sol | 68 +---------------------- src/storage/ClientChainGatewayStorage.sol | 4 ++ src/storage/ExocoreGatewayStorage.sol | 6 +- src/storage/GatewayStorage.sol | 5 -- 11 files changed, 18 insertions(+), 78 deletions(-) diff --git a/slither.config.json b/slither.config.json index 6eb1721c..8f098a6c 100644 --- a/slither.config.json +++ b/slither.config.json @@ -1,5 +1,5 @@ { - "detectors_to_exclude": "pragma,assembly,solc-version,naming-convention,incorrect-equality,uninitialized-local,timestamp,low-level-calls,unimplemented-functions,too-many-digits,similar-names,calls-loop,arbitrary-send-eth,reentrancy-no-eth,reentrancy-benign,reentrancy-events,unused-state,incorrect-shift-in-assembly,dead-code", + "detectors_to_exclude": "pragma,assembly,solc-version,naming-convention,timestamp,low-level-calls,too-many-digits,similar-names,calls-loop,reentrancy-benign,reentrancy-events,dead-code", "filter_paths": "lib/|test/|mocks/|BytesLib|script/", "solc_remaps": [ "forge-std/=lib/forge-std/src/", diff --git a/src/core/Bootstrap.sol b/src/core/Bootstrap.sol index 5df18c86..980ffefa 100644 --- a/src/core/Bootstrap.sol +++ b/src/core/Bootstrap.sol @@ -158,6 +158,7 @@ contract Bootstrap is _addWhitelistTokens(tokens); } + // slither-disable-next-line reentrancy-no-eth function _addWhitelistTokens(address[] calldata tokens) internal { for (uint256 i; i < tokens.length; i++) { address token = tokens[i]; @@ -473,6 +474,7 @@ contract Bootstrap is } // implementation of ILSTRestakingController + // slither-disable-next-line reentrancy-no-eth function depositThenDelegateTo(address token, uint256 amount, string calldata operator) external payable diff --git a/src/core/ClientGatewayLzReceiver.sol b/src/core/ClientGatewayLzReceiver.sol index 72fb87ac..7fe717e4 100644 --- a/src/core/ClientGatewayLzReceiver.sol +++ b/src/core/ClientGatewayLzReceiver.sol @@ -22,6 +22,7 @@ abstract contract ClientGatewayLzReceiver is PausableUpgradeable, OAppReceiverUp _; } + // slither-disable-next-line reentrancy-no-eth function _lzReceive(Origin calldata _origin, bytes calldata payload) internal virtual override whenNotPaused { if (_origin.srcEid != EXOCORE_CHAIN_ID) { revert UnexpectedSourceChain(_origin.srcEid); @@ -183,6 +184,7 @@ abstract contract ClientGatewayLzReceiver is PausableUpgradeable, OAppReceiverUp emit DepositThenDelegateResult(delegateSuccess, delegator, operator, token, amount); } + // slither-disable-next-line reentrancy-no-eth function afterReceiveAddWhitelistTokensRequest(bytes calldata requestPayload) public onlyCalledFromThis diff --git a/src/core/CustomProxyAdmin.sol b/src/core/CustomProxyAdmin.sol index e73ebf0e..d6aa20ac 100644 --- a/src/core/CustomProxyAdmin.sol +++ b/src/core/CustomProxyAdmin.sol @@ -18,6 +18,7 @@ contract CustomProxyAdmin is Initializable, ProxyAdmin { bootstrapper = newBootstrapper; } + // slither-disable-next-line reentrancy-no-eth function changeImplementation(address proxy, address implementation, bytes memory data) public virtual { require(msg.sender == bootstrapper, "CustomProxyAdmin: sender must be bootstrapper"); require(msg.sender == proxy, "CustomProxyAdmin: sender must be the proxy itself"); diff --git a/src/core/ExoCapsule.sol b/src/core/ExoCapsule.sol index cca7db0f..7b5a9899 100644 --- a/src/core/ExoCapsule.sol +++ b/src/core/ExoCapsule.sol @@ -154,9 +154,7 @@ contract ExoCapsule is Initializable, ExoCapsuleStorage, IExoCapsule { function withdraw(uint256 amount, address payable recipient) external onlyGateway { require(recipient != address(0), "ExoCapsule: recipient address cannot be zero or empty"); - require( - amount >0 && amount <= withdrawableBalance, "ExoCapsule: invalid withdrawal amount" - ); + require(amount > 0 && amount <= withdrawableBalance, "ExoCapsule: invalid withdrawal amount"); withdrawableBalance -= amount; (bool sent,) = recipient.call{value: amount}(""); diff --git a/src/core/ExocoreGateway.sol b/src/core/ExocoreGateway.sol index 3cb594e7..952d2c1a 100644 --- a/src/core/ExocoreGateway.sol +++ b/src/core/ExocoreGateway.sol @@ -169,6 +169,7 @@ contract ExocoreGateway is super.setPeer(clientChainId, clientChainGateway); } + // slither-disable-next-line reentrancy-no-eth function addWhitelistTokens( uint32 clientChainId, bytes32[] calldata tokens, diff --git a/src/core/NativeRestakingController.sol b/src/core/NativeRestakingController.sol index 301df90b..8b7dd3e9 100644 --- a/src/core/NativeRestakingController.sol +++ b/src/core/NativeRestakingController.sol @@ -46,6 +46,7 @@ abstract contract NativeRestakingController is } // slither-disable-next-line encode-packed-collision + // slither-disable-next-line reentrancy-no-eth function createExoCapsule() public whenNotPaused nativeRestakingEnabled returns (address) { require( address(ownerToCapsule[msg.sender]) == address(0), diff --git a/src/libraries/BeaconChainProofs.sol b/src/libraries/BeaconChainProofs.sol index 59d4d5d7..08e6a8c2 100644 --- a/src/libraries/BeaconChainProofs.sol +++ b/src/libraries/BeaconChainProofs.sol @@ -13,47 +13,12 @@ library BeaconChainProofs { // constants are the number of fields and the heights of the different merkle trees used in merkleizing // beacon chain containers - uint256 internal constant NUM_BEACON_BLOCK_HEADER_FIELDS = 5; uint256 internal constant BEACON_BLOCK_HEADER_FIELD_TREE_HEIGHT = 3; - uint256 internal constant NUM_BEACON_BLOCK_BODY_FIELDS = 11; uint256 internal constant BEACON_BLOCK_BODY_FIELD_TREE_HEIGHT = 4; - uint256 internal constant NUM_BEACON_STATE_FIELDS = 21; uint256 internal constant BEACON_STATE_FIELD_TREE_HEIGHT = 5; - uint256 internal constant NUM_ETH1_DATA_FIELDS = 3; - uint256 internal constant ETH1_DATA_FIELD_TREE_HEIGHT = 2; - - uint256 internal constant NUM_VALIDATOR_FIELDS = 8; - uint256 internal constant VALIDATOR_FIELD_TREE_HEIGHT = 3; - - uint256 internal constant NUM_EXECUTION_PAYLOAD_HEADER_FIELDS = 15; - uint256 internal constant EXECUTION_PAYLOAD_HEADER_FIELD_TREE_HEIGHT = 4; - - uint256 internal constant NUM_EXECUTION_PAYLOAD_FIELDS = 15; - uint256 internal constant EXECUTION_PAYLOAD_FIELD_TREE_HEIGHT = 4; - - // HISTORICAL_ROOTS_LIMIT = 2**24, so tree height is 24 - uint256 internal constant HISTORICAL_ROOTS_TREE_HEIGHT = 24; - - // HISTORICAL_BATCH is root of state_roots and block_root, so number of leaves = 2^1 - uint256 internal constant HISTORICAL_BATCH_TREE_HEIGHT = 1; - - // SLOTS_PER_HISTORICAL_ROOT = 2**13, so tree height is 13 - uint256 internal constant STATE_ROOTS_TREE_HEIGHT = 13; - uint256 internal constant BLOCK_ROOTS_TREE_HEIGHT = 13; - - //HISTORICAL_ROOTS_LIMIT = 2**24, so tree height is 24 - uint256 internal constant HISTORICAL_SUMMARIES_TREE_HEIGHT = 24; - - //Index of block_summary_root in historical_summary container - uint256 internal constant BLOCK_SUMMARY_ROOT_INDEX = 0; - - uint256 internal constant NUM_WITHDRAWAL_FIELDS = 4; - // tree height for hash tree of an individual withdrawal container - uint256 internal constant WITHDRAWAL_FIELD_TREE_HEIGHT = 2; - uint256 internal constant VALIDATOR_TREE_HEIGHT = 40; // MAX_WITHDRAWALS_PER_PAYLOAD = 2**4, making tree height = 4 @@ -65,45 +30,15 @@ library BeaconChainProofs { // in beacon block header // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#beaconblockheader - uint256 internal constant SLOT_INDEX = 0; - uint256 internal constant PROPOSER_INDEX_INDEX = 1; uint256 internal constant STATE_ROOT_INDEX = 3; uint256 internal constant BODY_ROOT_INDEX = 4; // in beacon state // https://github.com/ethereum/consensus-specs/blob/dev/specs/capella/beacon-chain.md#beaconstate - uint256 internal constant HISTORICAL_BATCH_STATE_ROOT_INDEX = 1; - uint256 internal constant BEACON_STATE_SLOT_INDEX = 2; - uint256 internal constant LATEST_BLOCK_HEADER_ROOT_INDEX = 4; - uint256 internal constant BLOCK_ROOTS_INDEX = 5; - uint256 internal constant STATE_ROOTS_INDEX = 6; - uint256 internal constant HISTORICAL_ROOTS_INDEX = 7; - uint256 internal constant ETH_1_ROOT_INDEX = 8; uint256 internal constant VALIDATOR_TREE_ROOT_INDEX = 11; - uint256 internal constant EXECUTION_PAYLOAD_HEADER_INDEX = 24; - uint256 internal constant HISTORICAL_SUMMARIES_INDEX = 27; - - // in validator - // https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#validator - uint256 internal constant VALIDATOR_PUBKEY_INDEX = 0; - uint256 internal constant VALIDATOR_WITHDRAWAL_CREDENTIALS_INDEX = 1; - uint256 internal constant VALIDATOR_BALANCE_INDEX = 2; - uint256 internal constant VALIDATOR_SLASHED_INDEX = 3; - uint256 internal constant VALIDATOR_WITHDRAWABLE_EPOCH_INDEX = 7; - - // in execution payload header - uint256 internal constant TIMESTAMP_INDEX = 9; - uint256 internal constant WITHDRAWALS_ROOT_INDEX = 14; //in execution payload uint256 internal constant WITHDRAWALS_INDEX = 14; - // in withdrawal - uint256 internal constant WITHDRAWAL_VALIDATOR_INDEX_INDEX = 1; - uint256 internal constant WITHDRAWAL_VALIDATOR_AMOUNT_INDEX = 3; - - //In historicalBatch - uint256 internal constant HISTORICALBATCH_STATEROOTS_INDEX = 1; - //Misc Constants /// @notice The number of slots each epoch in the beacon chain @@ -113,10 +48,9 @@ library BeaconChainProofs { uint64 internal constant SECONDS_PER_SLOT = 12; /// @notice Number of seconds per epoch: 384 == 32 slots/epoch * 12 seconds/slot + // slither-disable-next-line unused-state uint64 internal constant SECONDS_PER_EPOCH = SLOTS_PER_EPOCH * SECONDS_PER_SLOT; - bytes8 internal constant UINT64_MASK = 0xffffffffffffffff; - /// @notice This struct contains the merkle proofs and leaves needed to verify a partial/full withdrawal struct WithdrawalProof { bytes withdrawalProof; diff --git a/src/storage/ClientChainGatewayStorage.sol b/src/storage/ClientChainGatewayStorage.sol index 8058d4df..dea39f85 100644 --- a/src/storage/ClientChainGatewayStorage.sol +++ b/src/storage/ClientChainGatewayStorage.sol @@ -23,9 +23,13 @@ contract ClientChainGatewayStorage is BootstrapStorage { IBeacon public immutable EXO_CAPSULE_BEACON; // constant state variables + uint256 internal constant TOKEN_ADDRESS_BYTES_LENGTH = 32; uint256 internal constant GWEI_TO_WEI = 1e9; address internal constant VIRTUAL_STAKED_ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; IETHPOSDeposit internal constant ETH_POS = IETHPOSDeposit(0x00000000219ab540356cBB839Cbe05303d7705Fa); + // constants used for layerzero messaging + uint128 internal constant DESTINATION_GAS_LIMIT = 500_000; + uint128 internal constant DESTINATION_MSG_VALUE = 0; uint256[40] private __gap; diff --git a/src/storage/ExocoreGatewayStorage.sol b/src/storage/ExocoreGatewayStorage.sol index 88884e37..4fcb74e6 100644 --- a/src/storage/ExocoreGatewayStorage.sol +++ b/src/storage/ExocoreGatewayStorage.sol @@ -16,8 +16,10 @@ contract ExocoreGatewayStorage is GatewayStorage { uint256 internal constant CLAIM_REWARD_REQUEST_LENGTH = 96; // bytes32 token + bytes32 delegator + bytes(42) operator + uint256 amount uint256 internal constant DEPOSIT_THEN_DELEGATE_REQUEST_LENGTH = DELEGATE_REQUEST_LENGTH; - uint256 internal constant UINT8_BYTES_LENGTH = 1; - uint256 internal constant UINT256_BYTES_LENGTH = 32; + + // constants used for layerzero messaging + uint128 internal constant DESTINATION_GAS_LIMIT = 500_000; + uint128 internal constant DESTINATION_MSG_VALUE = 0; mapping(uint32 clienChainId => bool) public chainToBootstrapped; mapping(uint32 clienChainId => bool registered) public isRegisteredClientChain; diff --git a/src/storage/GatewayStorage.sol b/src/storage/GatewayStorage.sol index 96bd9569..b1b5d621 100644 --- a/src/storage/GatewayStorage.sol +++ b/src/storage/GatewayStorage.sol @@ -14,11 +14,6 @@ contract GatewayStorage { RESPOND } - /* ----------------- constants used for layerzero messaging ----------------- */ - uint256 internal constant TOKEN_ADDRESS_BYTES_LENGTH = 32; - uint128 internal constant DESTINATION_GAS_LIMIT = 500_000; - uint128 internal constant DESTINATION_MSG_VALUE = 0; - mapping(Action => bytes4) internal _whiteListFunctionSelectors; address payable public exocoreValidatorSetAddress;