Coverage Report

Created: 2025-06-24 07:59

/src/solidity/libsolidity/formal/Z3SMTLib2Interface.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
19
#include <libsolidity/formal/Z3SMTLib2Interface.h>
20
21
#include <libsolidity/interface/UniversalCallback.h>
22
23
#ifdef EMSCRIPTEN_BUILD
24
#include <z3++.h>
25
#endif
26
27
using namespace solidity::frontend::smt;
28
29
Z3SMTLib2Interface::Z3SMTLib2Interface(
30
  frontend::ReadCallback::Callback _smtCallback,
31
  std::optional<unsigned int> _queryTimeout
32
): SMTLib2Interface({}, std::move(_smtCallback), _queryTimeout)
33
605
{
34
#ifdef EMSCRIPTEN_BUILD
35
  constexpr int resourceLimit = 2000000;
36
  if (m_queryTimeout)
37
    z3::set_param("timeout", int(*m_queryTimeout));
38
  else
39
    z3::set_param("rlimit", resourceLimit);
40
  z3::set_param("rewriter.pull_cheap_ite", true);
41
  z3::set_param("fp.spacer.q3.use_qgen", true);
42
  z3::set_param("fp.spacer.mbqi", false);
43
  z3::set_param("fp.spacer.ground_pobs", false);
44
#endif
45
605
}
46
47
0
void Z3SMTLib2Interface::setupSmtCallback() {
48
0
  if (auto* universalCallback = m_smtCallback.target<frontend::UniversalCallback>())
49
0
    universalCallback->smtCommand().setZ3(m_queryTimeout, true, false);
50
0
}
51
52
std::string Z3SMTLib2Interface::querySolver(std::string const& _query)
53
0
{
54
#ifdef EMSCRIPTEN_BUILD
55
  z3::context context;
56
  return Z3_eval_smtlib2_string(context, _query.c_str());
57
#else
58
0
  return SMTLib2Interface::querySolver(_query);
59
0
#endif
60
0
}