-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix encoding of side-effects inside if and ternary in BMC #14216
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/libsolidity/smtCheckerTests/control_flow/side_effects_inside_if_1.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
contract C { | ||
function f() public pure { | ||
uint x; | ||
if (++x < 3) {} | ||
|
||
assert(x == 1); // should hold | ||
assert(x != 1); // should fail | ||
} | ||
} | ||
// ==== | ||
// SMTEngine: bmc | ||
// ---- | ||
// Warning 6838: (72-79): BMC: Condition is always true. | ||
// Warning 4661: (132-146): BMC: Assertion violation happens here. | ||
// Info 6002: BMC: 2 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. |
26 changes: 26 additions & 0 deletions
26
test/libsolidity/smtCheckerTests/control_flow/side_effects_inside_if_2.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
contract C { | ||
uint x; | ||
|
||
function inc() internal returns (uint) { | ||
// BMC inlines function calls and also looks at functions in isolation, | ||
// therefore it says once that this is safe, when called by `f`, | ||
// but also that it is unsafe just looking at this function (false positive). | ||
++x; | ||
return x; | ||
} | ||
|
||
function f() public { | ||
require(x < 1000); | ||
uint y = x; | ||
if (inc() < 3) {} | ||
|
||
assert(x == y + 1); // should hold | ||
assert(x != y + 1); // should fail | ||
} | ||
} | ||
// ==== | ||
// SMTEngine: bmc | ||
// ---- | ||
// Warning 2661: (318-321): BMC: Overflow (resulting value larger than 2**256 - 1) happens here. | ||
// Warning 4661: (499-517): BMC: Assertion violation happens here. | ||
// Info 6002: BMC: 4 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. |
30 changes: 30 additions & 0 deletions
30
test/libsolidity/smtCheckerTests/control_flow/side_effects_inside_if_3.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
contract C { | ||
uint x; | ||
|
||
function inc() internal returns (uint) { | ||
// BMC inlines function calls and also looks at functions in isolation, | ||
// therefore it says once that this is safe, when called by `f`, | ||
// but also that it is unsafe just looking at this function (false positive). | ||
++x; | ||
return x; | ||
} | ||
|
||
function inc2() internal returns (uint) { | ||
return inc(); | ||
} | ||
|
||
function f() public { | ||
require(x < 1000); | ||
uint y = x; | ||
if (inc2() < 3) {} | ||
|
||
assert(x == y + 1); // should hold | ||
assert(x != y + 1); // should fail | ||
} | ||
} | ||
// ==== | ||
// SMTEngine: bmc | ||
// ---- | ||
// Warning 2661: (318-321): BMC: Overflow (resulting value larger than 2**256 - 1) happens here. | ||
// Warning 4661: (575-593): BMC: Assertion violation happens here. | ||
// Info 6002: BMC: 4 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. |
15 changes: 15 additions & 0 deletions
15
test/libsolidity/smtCheckerTests/control_flow/side_effects_inside_if_4.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
contract C { | ||
function f() public pure { | ||
uint x = 2; | ||
if (--x < 3) {} | ||
|
||
assert(x == 1); // should hold | ||
assert(x != 1); // should fail | ||
} | ||
} | ||
// ==== | ||
// SMTEngine: bmc | ||
// ---- | ||
// Warning 6838: (76-83): BMC: Condition is always true. | ||
// Warning 4661: (136-150): BMC: Assertion violation happens here. | ||
// Info 6002: BMC: 2 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. |
16 changes: 16 additions & 0 deletions
16
test/libsolidity/smtCheckerTests/control_flow/side_effects_inside_ternary_1.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
contract C { | ||
function f() public pure { | ||
uint x; | ||
uint y = (++x < 3) ? ++x : --x; | ||
|
||
assert(y == x); // should hold; | ||
assert(x == 2); // should hold | ||
assert(x != 2); // should fail | ||
} | ||
} | ||
// ==== | ||
// SMTEngine: bmc | ||
// ---- | ||
// Warning 6838: (77-86): BMC: Condition is always true. | ||
// Warning 4661: (188-202): BMC: Assertion violation happens here. | ||
// Info 6002: BMC: 5 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. |
27 changes: 27 additions & 0 deletions
27
test/libsolidity/smtCheckerTests/control_flow/side_effects_inside_ternary_2.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
contract C { | ||
uint x; | ||
|
||
function inc() internal returns (uint) { | ||
// BMC inlines function calls and also looks at functions in isolation, | ||
// therefore it says once that this is safe, when called by `f`, | ||
// but also that it is unsafe just looking at this function (false positive). | ||
++x; | ||
return x; | ||
} | ||
|
||
function f() public { | ||
require(x < 1000); | ||
uint z = x; | ||
uint y = (inc() < 3) ? inc() : inc(); | ||
|
||
assert(y == x); | ||
assert(x == z + 2); // should hold | ||
assert(x != z + 2); // should fail | ||
} | ||
} | ||
// ==== | ||
// SMTEngine: bmc | ||
// ---- | ||
// Warning 2661: (318-321): BMC: Overflow (resulting value larger than 2**256 - 1) happens here. | ||
// Warning 4661: (543-561): BMC: Assertion violation happens here. | ||
// Info 6002: BMC: 5 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. |
31 changes: 31 additions & 0 deletions
31
test/libsolidity/smtCheckerTests/control_flow/side_effects_inside_ternary_3.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
contract C { | ||
uint x; | ||
|
||
function inc() internal returns (uint) { | ||
// BMC inlines function calls and also looks at functions in isolation, | ||
// therefore it says once that this is safe, when called by `f`, | ||
// but also that it is unsafe just looking at this function (false positive). | ||
++x; | ||
return x; | ||
} | ||
|
||
function inc2() internal returns (uint) { | ||
return inc(); | ||
} | ||
|
||
function f() public { | ||
require(x < 1000); | ||
uint z = x; | ||
uint y = (inc2() < 3) ? inc2() : inc2(); | ||
|
||
assert(y == x); // should hold | ||
assert(x == z + 2); // should hold | ||
assert(x != z + 2); // should fail | ||
} | ||
} | ||
// ==== | ||
// SMTEngine: bmc | ||
// ---- | ||
// Warning 2661: (318-321): BMC: Overflow (resulting value larger than 2**256 - 1) happens here. | ||
// Warning 4661: (636-654): BMC: Assertion violation happens here. | ||
// Info 6002: BMC: 5 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. |
16 changes: 16 additions & 0 deletions
16
test/libsolidity/smtCheckerTests/control_flow/side_effects_inside_ternary_4.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
contract C { | ||
function f() public pure { | ||
uint x = 2; | ||
uint y = (--x < 3) ? --x : 0; | ||
|
||
assert(y == x); // should hold | ||
assert(x == 0); // should hold | ||
assert(x != 0); // should fail | ||
} | ||
} | ||
// ==== | ||
// SMTEngine: bmc | ||
// ---- | ||
// Warning 6838: (81-90): BMC: Condition is always true. | ||
// Warning 4661: (189-203): BMC: Assertion violation happens here. | ||
// Info 6002: BMC: 4 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.