Add paris constraints to SMTChecker

Co-authored-by: Daniel <daniel@ekpyron.org>
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
Co-authored-by: Leo <leo@ethereum.org>
This commit is contained in:
Rodrigo Q. Saramago
2023-01-31 11:03:04 +01:00
co-authored by Daniel Kamil Śliwak Leo
parent d9d9ab30a2
commit feba4de509
26 changed files with 183 additions and 102 deletions
+8 -2
View File
@@ -255,8 +255,14 @@ string Predicate::formatSummaryCall(
if (auto const* identifier = dynamic_cast<Identifier const*>(memberExpr))
{
ASTString const& name = identifier->name();
auto memberName = _memberAccess.memberName();
// TODO remove this for 0.9.0
if (name == "block" && memberName == "difficulty")
memberName = "prevrandao";
if (name == "block" || name == "msg" || name == "tx")
txVars.insert(name + "." + _memberAccess.memberName());
txVars.insert(name + "." + memberName);
}
return true;
@@ -642,7 +648,7 @@ map<string, optional<string>> Predicate::readTxVars(smtutil::Expression const& _
{"block.basefee", TypeProvider::uint256()},
{"block.chainid", TypeProvider::uint256()},
{"block.coinbase", TypeProvider::address()},
{"block.difficulty", TypeProvider::uint256()},
{"block.prevrandao", TypeProvider::uint256()},
{"block.gaslimit", TypeProvider::uint256()},
{"block.number", TypeProvider::uint256()},
{"block.timestamp", TypeProvider::uint256()},
+7 -1
View File
@@ -1337,7 +1337,13 @@ bool SMTEncoder::visit(MemberAccess const& _memberAccess)
{
auto const& name = identifier->name();
solAssert(name == "block" || name == "msg" || name == "tx", "");
defineExpr(_memberAccess, state().txMember(name + "." + _memberAccess.memberName()));
auto memberName = _memberAccess.memberName();
// TODO remove this for 0.9.0
if (name == "block" && memberName == "difficulty")
memberName = "prevrandao";
defineExpr(_memberAccess, state().txMember(name + "." + memberName));
}
else if (auto magicType = dynamic_cast<MagicType const*>(exprType))
{
+8 -1
View File
@@ -142,13 +142,20 @@ smtutil::Expression SymbolicState::txMember(string const& _member) const
return m_tx.member(_member);
}
smtutil::Expression SymbolicState::evmParisConstraints() const
{
// Ensure prevrandao range as defined by EIP-4399.
return txMember("block.prevrandao") > (u256(1) << 64);
}
smtutil::Expression SymbolicState::txTypeConstraints() const
{
return
evmParisConstraints() &&
smt::symbolicUnknownConstraints(m_tx.member("block.basefee"), TypeProvider::uint256()) &&
smt::symbolicUnknownConstraints(m_tx.member("block.chainid"), TypeProvider::uint256()) &&
smt::symbolicUnknownConstraints(m_tx.member("block.coinbase"), TypeProvider::address()) &&
smt::symbolicUnknownConstraints(m_tx.member("block.difficulty"), TypeProvider::uint256()) &&
smt::symbolicUnknownConstraints(m_tx.member("block.prevrandao"), TypeProvider::uint256()) &&
smt::symbolicUnknownConstraints(m_tx.member("block.gaslimit"), TypeProvider::uint256()) &&
smt::symbolicUnknownConstraints(m_tx.member("block.number"), TypeProvider::uint256()) &&
smt::symbolicUnknownConstraints(m_tx.member("block.timestamp"), TypeProvider::uint256()) &&
+3 -2
View File
@@ -68,9 +68,9 @@ private:
* - block basefee
* - block chainid
* - block coinbase
* - block difficulty
* - block gaslimit
* - block number
* - block prevrandao
* - block timestamp
* - TODO gasleft
* - msg data
@@ -136,6 +136,7 @@ public:
smtutil::Expression txTypeConstraints() const;
smtutil::Expression txNonPayableConstraint() const;
smtutil::Expression blockhash(smtutil::Expression _blockNumber) const;
smtutil::Expression evmParisConstraints() const;
//@}
/// Crypto functions.
@@ -197,7 +198,7 @@ private:
{"block.basefee", smtutil::SortProvider::uintSort},
{"block.chainid", smtutil::SortProvider::uintSort},
{"block.coinbase", smt::smtSort(*TypeProvider::address())},
{"block.difficulty", smtutil::SortProvider::uintSort},
{"block.prevrandao", smtutil::SortProvider::uintSort},
{"block.gaslimit", smtutil::SortProvider::uintSort},
{"block.number", smtutil::SortProvider::uintSort},
{"block.timestamp", smtutil::SortProvider::uintSort},