/src/solidity/libsmtutil/CHCSolverInterface.h
Line | Count | Source |
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 | | /** |
20 | | * Interface for constrained Horn solvers. |
21 | | */ |
22 | | |
23 | | #pragma once |
24 | | |
25 | | #include <libsmtutil/SolverInterface.h> |
26 | | |
27 | | #include <map> |
28 | | #include <unordered_map> |
29 | | #include <vector> |
30 | | |
31 | | namespace solidity::smtutil |
32 | | { |
33 | | |
34 | | class CHCSolverInterface : public SolverInterface |
35 | | { |
36 | | public: |
37 | 15.1k | CHCSolverInterface(std::optional<unsigned> _queryTimeout = {}): m_queryTimeout(_queryTimeout) {} |
38 | | |
39 | | /// Takes a function declaration as a relation. |
40 | | virtual void registerRelation(Expression const& _expr) = 0; |
41 | | |
42 | | /// Takes an implication and adds as rule. |
43 | | /// Needs to bound all vars as universally quantified. |
44 | | virtual void addRule(Expression const& _expr, std::string const& _name) = 0; |
45 | | |
46 | | using CexNode = Expression; |
47 | | struct CexGraph |
48 | | { |
49 | | std::map<unsigned, CexNode> nodes; |
50 | | std::map<unsigned, std::vector<unsigned>> edges; |
51 | | }; |
52 | | |
53 | | struct InvariantInfo |
54 | | { |
55 | | /// Predicate definition as SMT expression |
56 | | Expression expression; |
57 | | /// Names of the formal arguments of the predicate definition |
58 | | std::vector<std::string> variableNames; |
59 | | }; |
60 | | /// Maps predicate to its definition as given by the solver and the formal arguments of the predicate |
61 | | using Invariants = std::unordered_map<std::string, InvariantInfo>; |
62 | | struct QueryResult |
63 | | { |
64 | | CheckResult answer; |
65 | | Invariants invariants; |
66 | | CexGraph cex; |
67 | | }; |
68 | | /// Takes a function application _expr and checks for reachability. |
69 | | /// @returns solving result, an invariant, and counterexample graph, if possible. |
70 | | virtual QueryResult query(Expression const& _expr) = 0; |
71 | | |
72 | | protected: |
73 | | std::optional<unsigned> m_queryTimeout; |
74 | | }; |
75 | | |
76 | | } |