From 60575a97bb1c9aebcec20fe98b8e230cc52b6863 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 11 Jul 2017 01:44:55 +0100 Subject: [PATCH] Fix simplification rules for shifts --- libevmasm/SimplificationRules.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libevmasm/SimplificationRules.cpp b/libevmasm/SimplificationRules.cpp index f79aeb72ba0d..d4242053bd82 100644 --- a/libevmasm/SimplificationRules.cpp +++ b/libevmasm/SimplificationRules.cpp @@ -123,8 +123,16 @@ Rules::Rules() u256 mask = (u256(1) << testBit) - 1; return u256(boost::multiprecision::bit_test(B.d(), testBit) ? B.d() | ~mask : B.d() & mask); }}, - {{Instruction::SHL, {A, B}}, [=]{ return u256(bigint(A.d()) << bigint(B.d())); }}, - {{Instruction::SHR, {A, B}}, [=]{ return A.d() >> B.d(); }}, + {{Instruction::SHL, {A, B}}, [=]{ + if (B.d() > 255) + return u256(0); + return u256(bigint(A.d()) << unsigned(B.d())); + }}, + {{Instruction::SHR, {A, B}}, [=]{ + if (B.d() > 255) + return u256(0); + return A.d() >> unsigned(B.d()); + }}, // invariants involving known constants (commutative instructions will be checked with swapped operants too) {{Instruction::ADD, {X, 0}}, [=]{ return X; }},