Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article explains phishing attacks involving tx.origin.
If you have not encountered tx.origin before, it is a Solidity global variable worth understanding as you learn smart contract development.
Understanding the vulnerability associated with tx.origin helps you build safer contracts. It is also useful for Solidity developers who want to improve their skills and for researchers interested in bug bounties.
If you are unfamiliar with bug bounties, start here.
[Solidity-Bug Bounty] A Beginner's Guide to Bug Bounties
What is phishing?

First, consider what phishing means.
The Japanese Wikipedia article describes phishing as fraud intended to obtain valuable information from Internet users, such as usernames, passwords, and credit card details. A typical example involves impersonating a trusted party in an email and directing the recipient to a fraudulent website.
In short, phishing is a deceptive attempt to obtain sensitive information.
Several common forms are described below.
Email phishing
Email phishing uses fraudulent messages and websites to steal account information.
A fraudulent website may closely resemble the legitimate one, making visual identification difficult. Check the destination URL and sender address rather than relying on appearance alone.
Spear phishing
Spear phishing targets a particular individual, often within a company or group.
An attacker may exploit information about the target and impersonate a trusted person, such as a manager or family member, to persuade the recipient to act.
Smishing
Smishing is phishing delivered through SMS.
A message may contain a suspicious URL leading to a page that collects personal information. Fraudulent delivery notifications impersonating services such as Amazon or Yamato Transport are familiar examples.
Vishing
The term combines "voice" and "phishing."
A fraudulent browser warning may claim that a device is infected and direct the user to a supposed support telephone number. The caller may then be pressured into purchasing a support contract or installing malicious software.
The original article also discusses suspicious communication during such calls. An accent or nationality is not a reliable indicator of fraud; verify the support channel independently.
Social media phishing
Phishing links can appear on platforms such as Facebook, Twitter, Instagram, and LinkedIn.
Messages from compromised accounts may appear more trustworthy to friends or relatives than unsolicited posts. Password reuse increases the risk that credentials leaked from one service will also be used to compromise another.
What is tx.origin?

Both tx.origin and msg.sender provide an address in Solidity.
The difference is that tx.origin identifies the account that originated the transaction, whereas msg.sender identifies the immediate caller in the ordinary external-call example below.
Suppose a user (an externally owned account, or EOA) calls ContractA, which then calls ContractB.

Inside ContractB, msg.sender is ContractA's address and tx.origin is the user's address.
The following demonstration illustrates that difference.

The observed addresses match the explanation above.
The Solidity documentation explicitly warns against using tx.origin for authorization.
Never use tx.origin for authorization. Let’s say you have a wallet contract like this:
https://docs.soliditylang.org/en/v0.8.17/security-considerations.html
The following sections explain why this matters.
An attack involving tx.origin

Consider the following historical Solidity examples in an isolated test environment.
Bank
contract Bank {
address public owner;
constructor() payable {
owner = msg.sender;
}
/// @notice 資金を預ける関数。
function deposit() public payable { }
/// @notice 資金を引き出す関数。ownerしか実行できない。
function withdraw(address payable _to, uint _amount) public {
require(tx.origin == owner);
(bool sent, ) = _to.call{value: _amount}("");
require(sent, "Failed to send Ether");
}
function getBalance() public view returns(uint) {
return address(this).balance;
}
}This contract accepts and releases funds.
owner
Stores the address that deployed the Bank contract.
deposit
Accepts funds sent to the contract.
withdraw
Checks whether the transaction origin is the Bank contract's owner before releasing funds. This is intended to restrict withdrawals to the owner, but the check does not authenticate the immediate caller.
getBalance
Returns the balance held by the Bank contract.
Attack
contract Attack {
address payable public owner;
Bank bank;
constructor(address _bank) public payable {
bank = Bank(_bank);
owner = payable(msg.sender);
}
/// @notice 資金を送られた際に呼び出される無名関数。
fallback() external payable {
bank.withdraw(owner, address(bank).balance);
}
}This contract demonstrates why the authorization check is unsafe.
owner
Stores the address that deployed the Attack contract.
bank
References the Bank contract.
fallback
An unnamed function invoked when the contract receives a call with no matching function. In this example, it calls Bank's withdraw function.
Demonstration

The demonstration shows that when the Bank owner sends funds to the Attack contract using the vulnerable withdrawal function, the remaining Bank balance can also be transferred away.
Code walkthrough
The authorization failure can be understood from the call chain.
Explanation
- User A deploys Bank and deposits a total of
5 etherusingdeposit. - User B deploys Attack.
- User A invokes
withdrawto send1 etherto the recipient address, which is the Attack contract. - A direct withdrawal by User B fails because User B is not the owner.
- When Attack receives the funds, its
fallbackfunction runs. - The fallback function calls
withdrawagain. - The transaction still originated from User A. Because the vulnerable check uses
tx.origin, the nested withdrawal passes authorization and transfers the remaining Bank balance to User B, the owner of Attack.
The essential problem is that the identity of the immediate caller changes while the transaction origin remains the same.
Complete code
The original complete example is reproduced below.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract Bank {
address public owner;
constructor() payable {
owner = msg.sender;
}
/// @notice 資金を預ける関数。
function deposit() public payable { }
/// @notice 資金を引き出す関数。ownerしか実行できない。
function withdraw(address payable _to, uint _amount) public {
require(tx.origin == owner);
(bool sent, ) = _to.call{value: _amount}("");
require(sent, "Failed to send Ether");
}
function getBalance() public view returns(uint) {
return address(this).balance;
}
}
contract Attack {
address payable public owner;
Bank bank;
constructor(address _bank) public payable {
bank = Bank(_bank);
owner = payable(msg.sender);
}
/// @notice 資金を送られた際に呼び出される無名関数。
fallback() external payable {
bank.withdraw(owner, address(bank).balance);
}
}Mitigation

For this direct-owner authorization model, use msg.sender instead.
The contract then checks the immediate caller on each call. When Attack's fallback function calls Bank, the caller is Attack, not the EOA that originally started the transaction. The unauthorized call therefore fails the owner check.
/// @notice 資金を引き出す関数。ownerしか実行できない。
function withdraw(address payable _to, uint _amount) public {
require(msg.sender == owner);
(bool sent, ) = _to.call{value: _amount}("");
require(sent, "Failed to send Ether");
}
function getBalance() public view returns(uint) {
return address(this).balance;
}Conclusion

This article explained phishing-related vulnerabilities involving tx.origin.
Key points
- Understand the difference between
tx.originandmsg.sender. - Recognize the risk of using
tx.originfor authorization. - Know how to address this issue in a direct-owner access control model.
These distinctions are important when designing smart contract access control.
I regularly write about Solidity, blockchain, and Web3, and share interesting articles on Twitter.
References
https://medium.com/coinmonks/solidity-tx-origin-attacks-58211ad95514




