From dac0029d16ffe31fba2e6241f99893ea9a26926e Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 15 May 2018 13:04:49 +0200 Subject: ABI encoding functions are pure and should be usable in constants. --- libsolidity/analysis/TypeChecker.cpp | 3 +++ libsolidity/ast/Types.cpp | 6 +++++- libsolidity/ast/Types.h | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index a222bdf0..e8694e88 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -2093,6 +2093,9 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) if (auto tt = dynamic_cast(exprType.get())) if (tt->actualType()->category() == Type::Category::Enum) annotation.isPure = true; + if (auto magicType = dynamic_cast(exprType.get())) + if (magicType->kind() == MagicType::Kind::ABI) + annotation.isPure = true; return false; } diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index dc548538..60e3183c 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2865,7 +2865,11 @@ bool FunctionType::isPure() const m_kind == Kind::RIPEMD160 || m_kind == Kind::AddMod || m_kind == Kind::MulMod || - m_kind == Kind::ObjectCreation; + m_kind == Kind::ObjectCreation || + m_kind == Kind::ABIEncode || + m_kind == Kind::ABIEncodePacked || + m_kind == Kind::ABIEncodeWithSelector || + m_kind == Kind::ABIEncodeWithSignature; } TypePointers FunctionType::parseElementaryTypeVector(strings const& _types) diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 6defacfc..4884696d 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -1046,8 +1046,8 @@ public: return *m_declaration; } bool hasDeclaration() const { return !!m_declaration; } - /// @returns true if the result of this function only depends on its arguments - /// and it does not modify the state. + /// @returns true if the result of this function only depends on its arguments, + /// does not modify the state and is a compile-time constant. /// Currently, this will only return true for internal functions like keccak and ecrecover. bool isPure() const; bool isPayable() const { return m_stateMutability == StateMutability::Payable; } -- cgit