From 30a68cb1750b66a82db65419f7ca35b43ea15d2a Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Wed, 20 Nov 2024 17:20:46 +0900 Subject: [PATCH] S8: fix to remove unused code Signed-off-by: Jun Kimura --- contracts/Asn1Decode.sol | 2 ++ contracts/ILCPClientErrors.sol | 1 - contracts/LCPClientBase.sol | 8 -------- contracts/LCPCommitment.sol | 32 -------------------------------- contracts/LCPOperator.sol | 2 ++ slither.config.json | 2 +- test/TestHelper.t.sol | 24 ++++++++++++++++++++---- 7 files changed, 25 insertions(+), 46 deletions(-) diff --git a/contracts/Asn1Decode.sol b/contracts/Asn1Decode.sol index 97ca1ed..18f8fc1 100644 --- a/contracts/Asn1Decode.sol +++ b/contracts/Asn1Decode.sol @@ -55,6 +55,7 @@ library NodePtr { } } +// slither-disable-start dead-code library Asn1Decode { using NodePtr for uint256; using BytesUtils for bytes; @@ -226,3 +227,4 @@ library Asn1Decode { return NodePtr.getPtr(ix, ixFirstContentByte, ixLastContentByte); } } +// slither-disable-end dead-code diff --git a/contracts/ILCPClientErrors.sol b/contracts/ILCPClientErrors.sol index ab98229..aa41eaf 100644 --- a/contracts/ILCPClientErrors.sol +++ b/contracts/ILCPClientErrors.sol @@ -8,7 +8,6 @@ interface ILCPClientErrors { error LCPClientClientStateInvalidKeyExpiration(); error LCPClientClientStateInvalidMrenclaveLength(); error LCPClientClientStateUnexpectedMrenclave(); - error LCPClientClientStateEmptyOperators(); error LCPClientClientStateInvalidOperatorAddress(); error LCPClientClientStateInvalidOperatorAddressLength(); error LCPClientClientStateInvalidOperatorsNonce(); diff --git a/contracts/LCPClientBase.sol b/contracts/LCPClientBase.sol index 614d702..e6e215c 100644 --- a/contracts/LCPClientBase.sol +++ b/contracts/LCPClientBase.sol @@ -650,14 +650,6 @@ abstract contract LCPClientBase is ILightClient, ILCPClientErrors { } } - function verifyECDSASignature(bytes32 commitment, bytes memory signature, address signer) - internal - pure - returns (bool) - { - return verifyECDSASignature(commitment, signature) == signer; - } - function verifyECDSASignature(bytes32 commitment, bytes memory signature) internal pure returns (address) { if (uint8(signature[64]) < 27) { signature[64] = bytes1(uint8(signature[64]) + 27); diff --git a/contracts/LCPCommitment.sol b/contracts/LCPCommitment.sol index ad18f95..8a6b0ae 100644 --- a/contracts/LCPCommitment.sol +++ b/contracts/LCPCommitment.sol @@ -44,22 +44,6 @@ library LCPCommitment { bytes state; } - function parseUpdateStateProxyMessage(bytes calldata messageBytes) - internal - pure - returns (UpdateStateProxyMessage memory) - { - HeaderedProxyMessage memory hm = abi.decode(messageBytes, (HeaderedProxyMessage)); - // MSB first - // 0-1: version - // 2-3: message type - // 4-31: reserved - if (hm.header != LCP_MESSAGE_HEADER_UPDATE_STATE) { - revert LCPCommitmentUnexpectedProxyMessageHeader(); - } - return abi.decode(hm.message, (UpdateStateProxyMessage)); - } - struct MisbehaviourProxyMessage { PrevState[] prevStates; bytes context; @@ -71,22 +55,6 @@ library LCPCommitment { bytes32 stateId; } - function parseMisbehaviourProxyMessage(bytes calldata messageBytes) - internal - pure - returns (MisbehaviourProxyMessage memory) - { - HeaderedProxyMessage memory hm = abi.decode(messageBytes, (HeaderedProxyMessage)); - // MSB first - // 0-1: version - // 2-3: message type - // 4-31: reserved - if (hm.header != LCP_MESSAGE_HEADER_MISBEHAVIOUR) { - revert LCPCommitmentUnexpectedProxyMessageHeader(); - } - return abi.decode(hm.message, (MisbehaviourProxyMessage)); - } - struct ValidationContext { bytes32 header; bytes context; diff --git a/contracts/LCPOperator.sol b/contracts/LCPOperator.sol index fd48f04..adca35a 100644 --- a/contracts/LCPOperator.sol +++ b/contracts/LCPOperator.sol @@ -21,10 +21,12 @@ library LCPOperator { // chainTypeSalt(CHAIN_TYPE_EVM, hex"") bytes32 internal constant CHAIN_TYPE_EVM_SALT = keccak256(abi.encodePacked(CHAIN_TYPE_EVM, hex"")); + // slither-disable-next-line dead-code function chainTypeSalt(ChainType chainType, bytes memory args) internal pure returns (bytes32) { return keccak256(abi.encodePacked(chainType, args)); } + // slither-disable-next-line dead-code function domainSeparatorUniversal() internal pure returns (bytes32) { return keccak256( abi.encode( diff --git a/slither.config.json b/slither.config.json index bbcdead..80ba075 100644 --- a/slither.config.json +++ b/slither.config.json @@ -1,4 +1,4 @@ { - "detectors_to_run": "arbitrary-send-erc20,array-by-reference,incorrect-shift,name-reused,rtlo,suicidal,uninitialized-storage,arbitrary-send-erc20-permit,controlled-array-length,controlled-delegatecall,delegatecall-loop,msg-value-loop,reentrancy-eth,unchecked-transfer,weak-prng,domain-separator-collision,erc20-interface,erc721-interface,locked-ether,mapping-deletion,shadowing-abstract,tautology,write-after-write,boolean-cst,reentrancy-no-eth,reused-constructor,tx-origin,unchecked-lowlevel,unchecked-send,variable-scope,void-cst,events-access,events-maths,incorrect-unary,boolean-equal,deprecated-standards,erc20-indexed,function-init-state,pragma,reentrancy-unlimited-gas,immutable-states,var-read-using-this", + "detectors_to_run": "arbitrary-send-erc20,array-by-reference,incorrect-shift,name-reused,rtlo,suicidal,uninitialized-storage,arbitrary-send-erc20-permit,controlled-array-length,controlled-delegatecall,delegatecall-loop,msg-value-loop,reentrancy-eth,unchecked-transfer,weak-prng,domain-separator-collision,erc20-interface,erc721-interface,locked-ether,mapping-deletion,shadowing-abstract,tautology,write-after-write,boolean-cst,reentrancy-no-eth,reused-constructor,tx-origin,unchecked-lowlevel,unchecked-send,variable-scope,void-cst,events-access,events-maths,incorrect-unary,boolean-equal,deprecated-standards,erc20-indexed,function-init-state,pragma,reentrancy-unlimited-gas,immutable-states,var-read-using-this,dead-code", "filter_paths": "(test/|node_modules/|contracts/proto/)" } \ No newline at end of file diff --git a/test/TestHelper.t.sol b/test/TestHelper.t.sol index 068f424..2faa9e2 100644 --- a/test/TestHelper.t.sol +++ b/test/TestHelper.t.sol @@ -108,12 +108,20 @@ library LCPCommitmentTestHelper { LCPCommitment.trustingPeriodContextEval(context, currentTimestampNanos); } - function parseUpdateStateProxyMessage(bytes calldata commitmentBytes) + function parseUpdateStateProxyMessage(bytes calldata messageBytes) public pure - returns (LCPCommitment.UpdateStateProxyMessage memory commitment) + returns (LCPCommitment.UpdateStateProxyMessage memory) { - return LCPCommitment.parseUpdateStateProxyMessage(commitmentBytes); + LCPCommitment.HeaderedProxyMessage memory hm = abi.decode(messageBytes, (LCPCommitment.HeaderedProxyMessage)); + // MSB first + // 0-1: version + // 2-3: message type + // 4-31: reserved + if (hm.header != LCPCommitment.LCP_MESSAGE_HEADER_UPDATE_STATE) { + revert LCPCommitment.LCPCommitmentUnexpectedProxyMessageHeader(); + } + return abi.decode(hm.message, (LCPCommitment.UpdateStateProxyMessage)); } function parseVerifyMembershipCommitmentProofs(bytes calldata proofBytes) @@ -129,7 +137,15 @@ library LCPCommitmentTestHelper { pure returns (LCPCommitment.MisbehaviourProxyMessage memory) { - return LCPCommitment.parseMisbehaviourProxyMessage(messageBytes); + LCPCommitment.HeaderedProxyMessage memory hm = abi.decode(messageBytes, (LCPCommitment.HeaderedProxyMessage)); + // MSB first + // 0-1: version + // 2-3: message type + // 4-31: reserved + if (hm.header != LCPCommitment.LCP_MESSAGE_HEADER_MISBEHAVIOUR) { + revert LCPCommitment.LCPCommitmentUnexpectedProxyMessageHeader(); + } + return abi.decode(hm.message, (LCPCommitment.MisbehaviourProxyMessage)); } }