Skip to content

Commit

Permalink
Fix simplification rules for shifts
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jan 5, 2018
1 parent d9ec3e0 commit 60575a9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libevmasm/SimplificationRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }},
Expand Down

0 comments on commit 60575a9

Please sign in to comment.