Detect only assembly blocks

pull/2315/head
Simone 8 months ago
parent fda9935c52
commit f57c2ca0b3
  1. 11
      shift_parameter_mixup.sol
  2. 11
      slither/detectors/assembly/shift_parameter_mixup.py
  3. 2
      tests/e2e/detectors/snapshots/detectors__detector_ShiftParameterMixup_0_6_11_shift_parameter_mixup_sol__0.txt
  4. 2
      tests/e2e/detectors/snapshots/detectors__detector_ShiftParameterMixup_0_7_6_shift_parameter_mixup_sol__0.txt
  5. 5
      tests/e2e/detectors/test_data/incorrect-shift/0.4.25/shift_parameter_mixup.sol
  6. BIN
      tests/e2e/detectors/test_data/incorrect-shift/0.4.25/shift_parameter_mixup.sol-0.4.25.zip
  7. 5
      tests/e2e/detectors/test_data/incorrect-shift/0.5.16/shift_parameter_mixup.sol
  8. BIN
      tests/e2e/detectors/test_data/incorrect-shift/0.5.16/shift_parameter_mixup.sol-0.5.16.zip
  9. 5
      tests/e2e/detectors/test_data/incorrect-shift/0.6.11/shift_parameter_mixup.sol
  10. BIN
      tests/e2e/detectors/test_data/incorrect-shift/0.6.11/shift_parameter_mixup.sol-0.6.11.zip
  11. 2
      tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol
  12. BIN
      tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol-0.7.6.zip

@ -0,0 +1,11 @@
contract C {
function f() internal returns (uint a, uint b) {
assembly {
a := shr(a, 8)
b := shl(248, 0xff)
}
uint y = 1;
uint g = 0xff << y;
}
}

@ -8,6 +8,7 @@ from slither.slithir.operations import Binary, BinaryType
from slither.slithir.variables import Constant
from slither.core.declarations.function_contract import FunctionContract
from slither.utils.output import Output
from slither.core.cfg.node import NodeType
class ShiftParameterMixup(AbstractDetector):
@ -45,8 +46,18 @@ The shift statement will right-shift the constant 8 by `a` bits"""
def _check_function(self, f: FunctionContract) -> List[Output]:
results = []
in_assembly = False
for node in f.nodes:
if node.type == NodeType.ASSEMBLY:
in_assembly = True
continue
if node.type == NodeType.ENDASSEMBLY:
in_assembly = False
continue
if not in_assembly:
continue
for ir in node.irs:
if isinstance(ir, Binary) and ir.type in [
BinaryType.LEFT_SHIFT,

@ -1,2 +1,2 @@
C.f() (tests/e2e/detectors/test_data/incorrect-shift/0.6.11/shift_parameter_mixup.sol#3-7) contains an incorrect shift operation: a = 8 >> a (tests/e2e/detectors/test_data/incorrect-shift/0.6.11/shift_parameter_mixup.sol#5)
C.f() (tests/e2e/detectors/test_data/incorrect-shift/0.6.11/shift_parameter_mixup.sol#3-10) contains an incorrect shift operation: a = 8 >> a (tests/e2e/detectors/test_data/incorrect-shift/0.6.11/shift_parameter_mixup.sol#5)

@ -1,2 +1,2 @@
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)
C.f() (tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol#3-10) contains an incorrect shift operation: a = 8 >> a (tests/e2e/detectors/test_data/incorrect-shift/0.7.6/shift_parameter_mixup.sol#5)

@ -1,8 +1,11 @@
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)
}
uint y = 1;
uint g = 0xff << y;
}
}

@ -1,8 +1,11 @@
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)
}
uint y = 1;
uint g = 0xff << y;
}
}

@ -1,8 +1,11 @@
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)
}
uint y = 1;
uint g = 0xff << y;
}
}

@ -5,5 +5,7 @@ contract C {
a := shr(a, 8)
b := shl(248, 0xff)
}
uint y = 1;
uint g = 0xff << y;
}
}
Loading…
Cancel
Save