From 957a3e8fdcad44441f1441208e84c2a6a6a21fba Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 25 Oct 2016 02:17:47 +0100 Subject: [PATCH 1/2] Warn if using tx.origin --- Changelog.md | 1 + libsolidity/analysis/TypeChecker.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 81d753d9c2de..ad807e45ce5c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ Features: * Inline assembly: issue warning if stack is not balanced after block. * Include ``keccak256()`` as an alias to ``sha3()``. * Support shifting constant numbers. + * Type Checker: warn if using ``tx.origin``. Bugfixes: * Commandline interface: Disallow unknown options in ``solc``. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 10d24e5a81d8..3af4354decb1 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1373,7 +1373,16 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) exprType->toString() + " (expected " + funType->selfType()->toString() + ")" ); - if (exprType->category() == Type::Category::Struct) + if (exprType->category() == Type::Category::Magic) + { + auto const& magicType(dynamic_cast(*exprType)); + if ((magicType.kind() == MagicType::Kind::Transaction) && (memberName == "origin")) + warning( + _memberAccess.location(), + "Using tx.origin is not recommended." + ); + } + else if (exprType->category() == Type::Category::Struct) annotation.isLValue = true; else if (exprType->category() == Type::Category::Array) { From fd7943cde57e1340e7ee6b41b9e42f02edfc21c3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 25 Oct 2016 02:28:32 +0100 Subject: [PATCH 2/2] Export MagicType.kind --- libsolidity/ast/Types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 3f94d11a6101..3d46ed14d0c0 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -1093,6 +1093,7 @@ class MagicType: public Type return TypePointer(); } + virtual Kind kind() const { return m_kind; } virtual bool operator==(Type const& _other) const override; virtual bool canBeStored() const override { return false; } virtual bool canLiveOutsideStorage() const override { return true; }