From 36142aa3fbb7f9db3c8f603831ae1795faa5f76a Mon Sep 17 00:00:00 2001 From: alpharush <0xalpharush@protonmail.com> Date: Thu, 4 May 2023 22:01:08 -0500 Subject: [PATCH 1/2] do not detect incorrect-shift when rhs is constant --- .../assembly/shift_parameter_mixup.py | 2 +- ...xup_0_7_6_shift_parameter_mixup_sol__0.txt | 2 +- .../0.7.6/shift_parameter_mixup.sol | 3 ++- .../0.7.6/shift_parameter_mixup.sol-0.7.6.zip | Bin 1468 -> 1557 bytes 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/slither/detectors/assembly/shift_parameter_mixup.py b/slither/detectors/assembly/shift_parameter_mixup.py index a4169499a7..5bfefb4c9c 100644 --- a/slither/detectors/assembly/shift_parameter_mixup.py +++ b/slither/detectors/assembly/shift_parameter_mixup.py @@ -52,7 +52,7 @@ def _check_function(self, f: FunctionContract) -> List[Output]: BinaryType.LEFT_SHIFT, BinaryType.RIGHT_SHIFT, ]: - if isinstance(ir.variable_left, Constant): + if isinstance(ir.variable_left, Constant) and not isinstance(ir.variable_right, Constant): info: DETECTOR_INFO = [ f, " contains an incorrect shift operation: ", diff --git a/tests/e2e/detectors/snapshots/detectors__detector_ShiftParameterMixup_0_7_6_shift_parameter_mixup_sol__0.txt b/tests/e2e/detectors/snapshots/detectors__detector_ShiftParameterMixup_0_7_6_shift_parameter_mixup_sol__0.txt index 08fdbe1c68..1c4206ea0f 100644 --- a/tests/e2e/detectors/snapshots/detectors__detector_ShiftParameterMixup_0_7_6_shift_parameter_mixup_sol__0.txt +++ b/tests/e2e/detectors/snapshots/detectors__detector_ShiftParameterMixup_0_7_6_shift_parameter_mixup_sol__0.txt @@ -1,2 +1,2 @@ -C.f() (tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol#3-7) contains an incorrect shift operation: a = 8 >> a (tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol#5) +C.f() (tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol#3-8) contains an incorrect shift operation: a = 8 >> a (tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol#5) diff --git a/tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol b/tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol index 89a9210ad8..11a2af9ae3 100644 --- a/tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol +++ b/tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol @@ -1,8 +1,9 @@ contract C { - function f() internal returns (uint a) { + function f() internal returns (uint a, uint b) { assembly { a := shr(a, 8) + b := shl(248, 0xff) } } } \ No newline at end of file diff --git a/tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol-0.7.6.zip b/tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol-0.7.6.zip index 7f833af857b0e8cac358ec9a83882debe1d333dc..e1cce4a17341c1df74817f1d973dffc2c27c7e16 100644 GIT binary patch delta 1239 zcmV;|1StEw3zZBQP)h>@KL7#%4ghDbq*hW?iU3&!006`mu^0sbf7K!=V7QoD1pOUb z;#`h#`LjS|K8Ti2v6Xb+^&SF-rsAN-J}fdQ<4ehp*pt$_!8Rl7wfsJ>uMaKn4`>@Z z)x=k#di^mxeF%4dss_}8dX%CJ8fW)2?60M*%dpX?JCOpS#1mq1pXZAt$#xU?bjN6% zAR82oz?L$Hx}uMhe`aU5Jf8p~Ra^id__c>#XlB6jgtgQn_ZLs>$w)xHB`&YX;xeaq zr@#3D9U8dI-(gY94QRE;M{$1dfBtqZWzgH0yy5ljr)D~;qS_kRy;Pg}|0}bM@B=jzLUaeC^CG4*V9IH~eV-T( zV(5#(w~F56f~035Oh@)=o3YG(yUuYK=!IC%+_<#_#KID(2(M2k`ll-x7ZpgYZar+^ zG~*wM#THJCk3HG1c;YF~^FmQ&D*z2%|1l!oe^@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|KI8kE!7vLO7YjU=ngSMtweh5+iVH~Mgg5xu zi#8>Ay0=#JDn5Tv(Fw^jsJ?*rRC!kP9qNt%7`wIDSH|kQ?F;{~g0|1jCByL}QzMly zy|bV^qom6gCrWplhj$ZcD8mUCa-OxWwsYH&T`4ijv5fvqO~aX?q@sM?Hv0HSyzyT+wA zfS|EO>y*;c*HbAwoyD)i0cqT-vb^0IHIrhxd^y*&68*Mo@&W$gF_X+>SH z2?2&LN>YDgje|=r-vhXsT;mTh4eek21Yg~HiwKp0=;)di#MRvrRAY@Xqc>Ak@g-TV zFC>3E$vxbns(rRsW{q$vaX-+cX+u$ Date: Thu, 4 May 2023 22:10:19 -0500 Subject: [PATCH 2/2] lint --- slither/detectors/assembly/shift_parameter_mixup.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slither/detectors/assembly/shift_parameter_mixup.py b/slither/detectors/assembly/shift_parameter_mixup.py index 5bfefb4c9c..1f6a878e2f 100644 --- a/slither/detectors/assembly/shift_parameter_mixup.py +++ b/slither/detectors/assembly/shift_parameter_mixup.py @@ -52,7 +52,9 @@ def _check_function(self, f: FunctionContract) -> List[Output]: BinaryType.LEFT_SHIFT, BinaryType.RIGHT_SHIFT, ]: - if isinstance(ir.variable_left, Constant) and not isinstance(ir.variable_right, Constant): + if isinstance(ir.variable_left, Constant) and not isinstance( + ir.variable_right, Constant + ): info: DETECTOR_INFO = [ f, " contains an incorrect shift operation: ",