solidity/libsolidity/formal/SymbolicState.h

74 lines
1.9 KiB
C
Raw Normal View History

2020-03-24 19:15:15 +00:00
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
2020-03-24 19:15:15 +00:00
#pragma once
#include <libsolidity/formal/SymbolicVariables.h>
2020-05-18 15:42:24 +00:00
#include <libsmtutil/Sorts.h>
#include <libsmtutil/SolverInterface.h>
2020-03-24 19:15:15 +00:00
namespace solidity::frontend::smt
{
class EncodingContext;
/**
* Symbolic representation of the blockchain state.
*/
class SymbolicState
{
public:
SymbolicState(EncodingContext& _context);
void reset();
/// Blockchain.
//@{
/// Value of `this` address.
2020-05-19 12:14:46 +00:00
smtutil::Expression thisAddress();
2020-03-24 19:15:15 +00:00
/// @returns the symbolic balance of address `this`.
2020-05-19 12:14:46 +00:00
smtutil::Expression balance();
2020-03-24 19:15:15 +00:00
/// @returns the symbolic balance of an address.
2020-05-19 12:14:46 +00:00
smtutil::Expression balance(smtutil::Expression _address);
2020-03-24 19:15:15 +00:00
/// Transfer _value from _from to _to.
2020-05-19 12:14:46 +00:00
void transfer(smtutil::Expression _from, smtutil::Expression _to, smtutil::Expression _value);
2020-03-24 19:15:15 +00:00
//@}
private:
/// Adds _value to _account's balance.
2020-05-19 12:14:46 +00:00
void addBalance(smtutil::Expression _account, smtutil::Expression _value);
2020-03-24 19:15:15 +00:00
EncodingContext& m_context;
/// Symbolic `this` address.
SymbolicAddressVariable m_thisAddress{
"this",
m_context
};
/// Symbolic balances.
SymbolicArrayVariable m_balances{
2020-05-13 11:08:48 +00:00
std::make_shared<smtutil::ArraySort>(smtutil::SortProvider::uintSort, smtutil::SortProvider::uintSort),
2020-03-24 19:15:15 +00:00
"balances",
m_context
};
};
}