Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue a warning when using tx.origin #1278

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
11 changes: 10 additions & 1 deletion libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MagicType const&>(*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)
{
Expand Down
1 change: 1 addition & 0 deletions libsolidity/ast/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down