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 looks at honeypots.
A honeypot is generally used to lure hackers and other attackers. The previous articles in this bug bounty series covered ways to defend against vulnerabilities. This time, we will approach the subject from a different perspective.
Honeypots are important to understand if you want to improve your Solidity skills or participate in bug bounty programs.
If you are unfamiliar with bug bounties, start with the following article.
[Solidity Bug Bounty] An Introduction to Bug Bounties
What Is a Honeypot?

First, let's establish what the term means.
Definition of a Honeypot
The Japanese Wikipedia article describes a honeypot as follows (translated from Japanese).
In computer security, a honeypot is a technique or system that exposes a deliberately attack-prone device on a network as a decoy, attracting cyberattacks so that attackers can be identified and their methods analyzed [1].
Purposes include obtaining samples of viruses and worms, attracting intruders away from important systems, and studying unauthorized access techniques and trends using recorded operation and communication logs.
https://ja.wikipedia.org/wiki/%E3%83%8F%E3%83%8B%E3%83%BC%E3%83%9D%E3%83%83%E3%83%88
In short, the purpose of a honeypot is to design a system that attracts attackers so you can observe how they behave and what they target.
Honeypots in Smart Contracts
Now that we have a definition, consider what a honeypot looks like in a smart contract.
A smart contract honeypot is a contract deliberately made to appear vulnerable so that an attacker attempts to exploit it.
An attacker may identify what looks like a vulnerability and attempt to exploit it, only to find that their own funds have been trapped or taken instead.
The purpose described here is not primarily to obtain the attacker's funds but to identify the attacker's address and, for example, add it to a blocklist.
Creating a new wallet is easy, however, so an address blocklist alone has limited effectiveness. Blocklisting can be more useful at a centralized exchange (CEX) that requires users to submit identifying information.
Honeypot Implementation

The following historical Solidity examples illustrate how an apparent vulnerability can be misleading. They are presented for security analysis in an isolated test environment, not as contracts to deploy with real users' funds.
Balance Disorder
The following contract appears to allow deposits and withdrawals.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract Honeypot {
// 確認用の変数
uint public balance;
uint public value;
/// @notice 資金を預けることができる関数。
function deposit() public payable {
balance += msg.value;
value = msg.value;
}
/// @notice 資金を引き出すことができる関数。
function withdraw() public payable {
balance += address(this).balance;
value = msg.value;
// コントラクトが保持している資金より多くの資金を渡して呼び出すと、
// コントラクト内の資金を全て取得できる脆弱性...?
if (msg.value >= address(this).balance) {
payable(msg.sender).transfer(address(this).balance+msg.value);
}
}
}deposit
The function allows funds to be deposited.
widthdraw
This function (named withdraw in this first code example) appears to contain a vulnerability that would allow someone to withdraw all the funds by calling it with more ETH than the contract holds.
The following demonstration shows its actual behavior.

Although the funds appear to be withdrawable, the withdrawal does not occur.
The amount held by the contract is greater than the amount sent with the call, so the following if block is not executed.
if (msg.value >= address(this).balance) {
payable(msg.sender).transfer(address(this).balance+msg.value);
}As in the demonstration, suppose the contract already holds 2 ether and a caller sends 3 ether. The contract then holds 5 ether, so address(this).balance is greater than the incoming amount.
As a result, the caller cannot withdraw their funds and has fallen into the honeypot.
This is an example of code that looks exploitable at first glance but does not behave as the apparent vulnerability suggests. In a payable call, the contract balance already includes the value sent with that call.
Honeypots That Conceal Code
Solidity contracts can conceal malicious behavior behind other code.
The following article explains this subject in more detail.
[Solidity Bug Bounty] Understanding Hidden Malicious Code
CallContract
contract CallContract {
// withdraw関数を呼び出すコントラクトのアドレスを格納。
address public widthdrawContract;
// コントラクトをデプロイしたEOAアドレスを格納。
address public owner;
// アドレスごとに預けた資金を管理。
mapping(address => uint) balances;
constructor(address _widthdrawContract) {
widthdrawContract = _widthdrawContract;
owner = msg.sender;
}
/// @notice 資金を預ける。
function dposit() public payable {
balances[msg.sender] += msg.value;
}
/// @notice WidthdrawContractのwidthdraw関数を呼び出して、
/// 指定した資金を引き出す。
function widthdraw(uint _amount) public payable {
(bool sent, ) = widthdrawContract.delegatecall(abi.encodeWithSignature("widthdraw(uint256)", _amount));
require(sent, "Could not remit.");
}
}The address of another contract is supplied when this contract is deployed.
deposit
This is the deposit function, spelled dposit in the original code.
widthdraw
This function calls widthdraw at the address supplied during deployment. It appears to let the caller withdraw the specified amount to their own address.
For an explanation of delegatecall, see the following article.
[Solidity Bug Bounty] Understanding Delegatecall Vulnerabilities
WithdrawContract
contract WithdrawContract {
address contractAddress;
address owner;
mapping(address => uint) balances;
/// @notice 指定した資金を引き出す関数。
function widthdraw(uint _amount) public payable {
require(balances[msg.sender] >= 1 ether);
balances[msg.sender] -= _amount;
(bool sent, ) = msg.sender.call{value: _amount}("");
require(sent, "Could not remit.");
}
}This is a decoy contract that is not actually used.
With delegatecall, the calling and target contracts must have compatible storage layouts. Their variables are therefore declared in corresponding positions in this example.
widthdraw
The function checks whether the user attempting to withdraw has deposited at least 1 ether and then attempts to send the requested amount.
At first glance, the function appears to allow the caller to specify an _amount larger than their deposit.
There is an important historical-code caveat: in Solidity 0.8, the subtraction reverts on underflow, so the code as shown does not permit an overdraw merely because there is no explicit upper-bound check.
HoneyPot
contract HoneyPot {
address contractAddress;
address public owner;
mapping(address => uint) balances;
constructor() {
owner = msg.sender;
}
/// @notice 預けた以上の資金を引き出そうとするユーザーの資金を逆に抜き取る関数。
function widthdraw(uint _amount) public payable {
require(balances[msg.sender] >= 1 ether);
if (_amount > balances[msg.sender]) {
balances[msg.sender] = 0;
(bool sent, ) = payable(owner).call{value: balances[msg.sender]}("");
require(sent, "Could not remit.");
} else {
balances[msg.sender] -= _amount;
(bool sent, ) = msg.sender.call{value: _amount}("");
require(sent, "Could not remit.");
}
}
}The original example supplies the address of this contract when deploying CallContract.
Because the call uses delegatecall, the variables are declared with the same storage layout as CallContract.
widthdraw
The function checks whether the user has deposited at least 1 ether and whether the requested withdrawal exceeds their deposit, which the example treats as evidence of a malicious user.
For an ordinary withdrawal, the requested amount is sent to the user. For an attempted overdraw, the example is intended to confiscate the user's recorded deposit and send it to the deployer of CallContract.
Note that the standalone snippet above sets the recorded balance to zero before reading it as the amount to send. Consequently, it attempts to transfer zero in that branch, unlike the complete listing below. The original code is preserved for comparison.
The following recording illustrates the example.

The sequence involves three contracts and several users.
Execution sequence
- User A deploys the three contracts. The
widthdrawContractvariable in CallContract holds the address of HoneyPot. - User B deposits
3 etherand user C deposits2 ether, leaving5 etherin the contract. - User C expects that calling
widthdrawwill execute the function in WithdrawContract. Believing they have found a vulnerability, user C attempts to withdraw5 ether. - The function that actually executes is
widthdrawin HoneyPot. The attempted withdrawal exceeds user C's deposit, so the conditional branch is reached. In the complete listing below, user C's2 etheris sent to user A's address. - The demonstration specifies
5000000000000000000as the argument towidthdrawfor a reason. - Passing the integer 1 would specify
1 wei, not1 ether. Since1 ether = 10^18 wei, the example specifies5 ether = 5000000000000000000 wei.
Understanding this example requires familiarity with both hidden malicious contract behavior and delegatecall. Study each concept separately. Apparent intent cannot be established solely from a withdrawal amount.
Complete Code
The original complete listing follows.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.13;
contract CallContract {
// withdraw関数を呼び出すコントラクトのアドレスを格納。
address public widthdrawContract;
// コントラクトをデプロイしたEOAアドレスを格納。
address public owner;
// アドレスごとに預けた資金を管理。
mapping(address => uint) balances;
constructor(address _widthdrawContract) {
widthdrawContract = _widthdrawContract;
owner = msg.sender;
}
/// @notice 資金を預ける。
function dposit() public payable {
balances[msg.sender] += msg.value;
}
/// @notice WidthdrawContractのwidthdraw関数を呼び出して、
/// 指定した資金を引き出す。
function widthdraw(uint _amount) public payable {
(bool sent, ) = widthdrawContract.delegatecall(abi.encodeWithSignature("widthdraw(uint256)", _amount));
require(sent, "Could not remit.");
}
}
contract WithdrawContract {
address contractAddress;
address owner;
mapping(address => uint) balances;
/// @notice 指定した資金を引き出す関数。
function widthdraw(uint _amount) public payable {
require(balances[msg.sender] >= 1 ether);
balances[msg.sender] -= _amount;
(bool sent, ) = msg.sender.call{value: _amount}("");
require(sent, "Could not remit.");
}
}
contract HoneyPot {
address contractAddress;
address public owner;
mapping(address => uint) balances;
constructor() {
owner = msg.sender;
}
/// @notice 預けた以上の資金を引き出そうとするユーザーの資金を逆に抜き取る関数。
function widthdraw(uint _amount) public payable {
require(balances[msg.sender] >= 1 ether);
if (_amount > balances[msg.sender]) {
uint baalnce = balances[msg.sender];
balances[msg.sender] = 0;
(bool sent, ) = payable(owner).call{value: baalnce}("");
require(sent, "Could not remit.");
} else {
balances[msg.sender] -= _amount;
(bool sent, ) = msg.sender.call{value: _amount}("");
require(sent, "Could not remit.");
}
}
}Conclusion

This article covered honeypots.
Key points
- Understand what a honeypot is.
- Recognize how the example implementations are constructed.
- Understand the mechanisms that make an apparent vulnerability misleading.
These concepts are useful when reviewing Solidity contracts. The author also shares information about Solidity, blockchain, and Web3, including interesting articles on Twitter.

