Merge pull request #10777 from blishko/smt-fix-checked

[SMTChecker] Fix BMC crash related to `unchecked` blocks
This commit is contained in:
Leonardo
2021-01-15 16:46:32 +01:00
committed by GitHub
4 changed files with 51 additions and 0 deletions
@@ -0,0 +1,17 @@
pragma experimental SMTChecker;
contract C {
function f(uint x) internal pure {
unchecked {
uint y = x - 1;
assert(y < x); // should fail, underflow can happen, we are inside unchecked block
}
}
function g(uint x) public pure {
unchecked { f(x); }
}
}
// ====
// SMTEngine: bmc
// ----
// Warning 4661: (117-130): BMC: Assertion violation happens here.
// Warning 4661: (117-130): BMC: Assertion violation happens here.
@@ -0,0 +1,18 @@
pragma experimental SMTChecker;
contract C {
modifier m() {
unchecked{}
_;
}
function t() m internal pure {}
function f() public pure {
unchecked { t(); }
}
}
// ----
@@ -0,0 +1,14 @@
pragma experimental SMTChecker;
contract C {
function f(uint x) internal pure {
unchecked {
uint y = x - 1;
assert(y < x); // should fail, underflow can happen, we are inside unchecked block
}
}
function g(uint x) public pure {
unchecked { f(x); }
}
}
// ----
// Warning 6328: (117-130): CHC: Assertion violation happens here.\nCounterexample:\n\nx = 0\n\nTransaction trace:\nC.constructor()\nC.g(0)\n C.f(0) -- internal call