mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[SMTChecker] Support check/unchecked
This commit is contained in:
@@ -283,6 +283,25 @@ void SMTEncoder::endVisit(FunctionDefinition const&)
|
||||
m_context.popSolver();
|
||||
}
|
||||
|
||||
bool SMTEncoder::visit(Block const& _block)
|
||||
{
|
||||
if (_block.unchecked())
|
||||
{
|
||||
solAssert(m_checked, "");
|
||||
m_checked = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SMTEncoder::endVisit(Block const& _block)
|
||||
{
|
||||
if (_block.unchecked())
|
||||
{
|
||||
solAssert(!m_checked, "");
|
||||
m_checked = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool SMTEncoder::visit(InlineAssembly const& _inlineAsm)
|
||||
{
|
||||
m_errorReporter.warning(
|
||||
@@ -745,6 +764,7 @@ void SMTEncoder::initContract(ContractDefinition const& _contract)
|
||||
createStateVariables(_contract);
|
||||
clearIndices(m_currentContract, nullptr);
|
||||
m_variableUsage.setCurrentContract(_contract);
|
||||
m_checked = true;
|
||||
}
|
||||
|
||||
void SMTEncoder::initFunction(FunctionDefinition const& _function)
|
||||
@@ -759,6 +779,7 @@ void SMTEncoder::initFunction(FunctionDefinition const& _function)
|
||||
createLocalVariables(_function);
|
||||
m_arrayAssignmentHappened = false;
|
||||
clearIndices(m_currentContract, &_function);
|
||||
m_checked = true;
|
||||
}
|
||||
|
||||
void SMTEncoder::visitAssert(FunctionCall const& _funCall)
|
||||
@@ -1762,6 +1783,9 @@ pair<smtutil::Expression, smtutil::Expression> SMTEncoder::arithmeticOperation(
|
||||
}
|
||||
}();
|
||||
|
||||
if (m_checked)
|
||||
return {valueUnbounded, valueUnbounded};
|
||||
|
||||
if (_op == Token::Div || _op == Token::Mod)
|
||||
{
|
||||
// mod and unsigned division never underflow/overflow
|
||||
@@ -2385,6 +2409,16 @@ void SMTEncoder::defineExpr(Expression const& _e, smtutil::Expression _value)
|
||||
createExpr(_e);
|
||||
solAssert(_value.sort->kind != smtutil::Kind::Function, "Equality operator applied to type that is not fully supported");
|
||||
m_context.addAssertion(expr(_e) == _value);
|
||||
|
||||
if (
|
||||
auto type = _e.annotation().type;
|
||||
m_checked && smt::isNumber(*type)
|
||||
)
|
||||
m_context.addAssertion(smtutil::Expression::implies(
|
||||
currentPathConditions(),
|
||||
smt::symbolicUnknownConstraints(expr(_e), type)
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
void SMTEncoder::popPathCondition()
|
||||
|
||||
Reference in New Issue
Block a user