mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9782 from ethereum/smt-revert
[SMTChecker] Support revert()
This commit is contained in:
commit
5355e85639
@ -5,6 +5,7 @@ Language Features:
|
||||
|
||||
Compiler Features:
|
||||
* Export compiler-generated utility sources via standard-json or combined-json.
|
||||
* SMTChecker: Support ``revert()``.
|
||||
* SMTChecker: Support shifts.
|
||||
* SMTChecker: Support structs.
|
||||
* SMTChecker: Support ``type(T).min``, ``type(T).max``, and ``type(I).interfaceId``.
|
||||
|
@ -631,6 +631,10 @@ void SMTEncoder::endVisit(FunctionCall const& _funCall)
|
||||
case FunctionType::Kind::Require:
|
||||
visitRequire(_funCall);
|
||||
break;
|
||||
case FunctionType::Kind::Revert:
|
||||
// Revert is a special case of require and equals to `require(false)`
|
||||
addPathImpliedExpression(smtutil::Expression(false));
|
||||
break;
|
||||
case FunctionType::Kind::GasLeft:
|
||||
visitGasLeft(_funCall);
|
||||
break;
|
||||
|
33
test/libsolidity/smtCheckerTests/control_flow/require.sol
Normal file
33
test/libsolidity/smtCheckerTests/control_flow/require.sol
Normal file
@ -0,0 +1,33 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() pure public {
|
||||
require(false);
|
||||
// This is not reachable.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
function g() pure public {
|
||||
require(false, "require message");
|
||||
// This is not reachable.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
function h(bool b) pure public {
|
||||
if (b)
|
||||
require(false);
|
||||
assert(!b);
|
||||
}
|
||||
|
||||
// Check that arguments are evaluated.
|
||||
bool x = false;
|
||||
function m() view internal returns (string memory) {
|
||||
assert(x != true);
|
||||
}
|
||||
function i() public {
|
||||
x = true;
|
||||
require(false, m());
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (448-465): Assertion violation happens here.
|
35
test/libsolidity/smtCheckerTests/control_flow/revert.sol
Normal file
35
test/libsolidity/smtCheckerTests/control_flow/revert.sol
Normal file
@ -0,0 +1,35 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f() pure public {
|
||||
revert();
|
||||
// This is not reachable.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
function g() pure public {
|
||||
revert("revert message");
|
||||
// This is not reachable.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
function h(bool b) pure public {
|
||||
if (b)
|
||||
revert();
|
||||
assert(!b);
|
||||
}
|
||||
|
||||
// Check that arguments are evaluated.
|
||||
bool x = false;
|
||||
function m() view internal returns (string memory) {
|
||||
assert(x != true);
|
||||
}
|
||||
function i() public {
|
||||
x = true;
|
||||
revert(m());
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 5740: (116-129): Unreachable code.
|
||||
// Warning 5740: (221-234): Unreachable code.
|
||||
// Warning 6328: (427-444): Assertion violation happens here.
|
@ -0,0 +1,18 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f(bool b, uint a) pure public {
|
||||
require(a <= 256);
|
||||
if (b)
|
||||
revert();
|
||||
uint c = a + 1;
|
||||
if (b)
|
||||
c--;
|
||||
else
|
||||
c++;
|
||||
assert(c == a);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (183-197): Assertion violation happens here.
|
||||
// Warning 6838: (155-156): Condition is always false.
|
@ -6,4 +6,3 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// Warning 6838: (94-100): Condition is always true.
|
||||
// Warning 4588: (104-112): Assertion checker does not yet implement this type of function call.
|
||||
|
@ -6,4 +6,3 @@ contract C {
|
||||
}
|
||||
// ----
|
||||
// Warning 6838: (109-115): Condition is always false.
|
||||
// Warning 4588: (119-127): Assertion checker does not yet implement this type of function call.
|
||||
|
@ -6,4 +6,3 @@ contract C {
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 4588: (136-144): Assertion checker does not yet implement this type of function call.
|
||||
|
Loading…
Reference in New Issue
Block a user