Finding Missing Auth bugs in EOSIO Smart Contracts
Tags: staticcodeanalysis, eosio, eos, smartcontracts
Published: 2021-03-27 08:05:20

---
title: Finding Missing Auth bugs in EOSIO Smart Contracts
published: true
date: 2021-03-25 05:31:24 UTC
tags: staticcodeanalysis,eosio,eos,smartcontracts
canonical_url: https://medium.com/coinmonks/finding-missing-auth-bugs-in-eosio-smart-contracts-242400e10cdc
---

![](https://cdn-images-1.medium.com/max/1024/0*nG0HqhICo9OXaBwM.png)

This is a series of blog posts in which I’ll cover some common EOSIO smart contract vulnerabilities and then explain how we can use our EOSIO vulnerability scanner, [Inspect](https://klevoya.com/inspect/), to perform static analysis to uncover these vulnerabilities.

This week, I look at Missing Authorisations.

### The vulnerability

In EOSIO, a developer can use two functions to control authorisation of smart contract actions by checking whether the declared authorisation of the action equals the account that should be able to run the action. These are:

- require\_auth(account [, permission])
- has\_auth(account)

Due to missing authorisation controls, a vulnerable smart contract grants authorisation to untrusted accounts such as malicious parties, to:

- access/modify privileged smart contract resources e.g. smart contract tables,
- Call functions of other contracts on behalf of the vulnerable contract, or
- Perform mission-critical contract actions e.g. token withdrawals.

Let’s look at an example of where a smart contract is setup such that it is paying for EOSIO RAM (which is what EOSIO calls the on chain database) storage costs, in such a scenario every write to the database should be checked to ensure that the entity calling the action that contains the database write has the proper authorisation to do so. Otherwise incorrect data may be written, or a RAM filling attack (see severity below) may occur.

In the action code below, despite there being a require\_auth() call prior to the emplace call (which writes data to the \_users table), the user is not the RAM payer, allowing any user to write to the database using the contract account’s own RAM making the contract vulnerable to a RAM filling attack.

{% gist https://gist.github.com/klevoya/d88003be837c646521d8778896723400 %}

Modifying the action so that the user pays for RAM, makes the action immune to a RAM filling attack (as the user is no longer using the contract’s resources for RAM):

{% gist https://gist.github.com/klevoya/8ab6c19d5fe74d488265fbf2756a3a43 %}

### Severity

The impact of this type of vulnerability is that a hacker could:

- Write/modify/delete any data stored in RAM that is not adequately guarded by an appropriate authorisation check,
- Call functionality that should ostensibly be reserved only for the smart contract’s administrators/privileged users,
- In EOSIO RAM is not free so a hacker can fill up a smart contract’s RAM with spurious data and exhaust the dAPP’s resources leading to a denial of service for legitimate users.

### Finding the vulnerability with Inspect

Inspect employs a technique called Static analysis. Static analysis is performed by reasoning about a computer program’s source-code, or some intermediate representation, without actually executing it.

With Inspect we perform static analysis on the WASM binary code, this is decompiled and then lifted into a proprietary intermediate representation (IR). Inspect then takes the IR, represents it in a database which we can mine for patterns of known vulnerabilities.

Running Inspect on a smart contract containing the above smart contract actions gives the following result:

```
Auth Violation: ✘ Action: emplaceself1 Insn: ($fel) = db_store_i64($feb, $fec, $fef, $feh, $fej, $fek)
```

The first action is correctly flagged as violating the Authorisation check. As Inspect operates on the WASM byte code, it reports the violation occurring at the EOSIO intrinsic, db\_store\_i64(), that corresponds to the emplace() call.

The second action is not reported as it is safe.

In a real analysis scenario, the next step would be to correlate this result with the source code and confirm that this is truly a vulnerability.

What else? What vulnerabilities would you like me to cover next?

_Originally published at_ [_https://klevoya.com_](https://klevoya.com/blog/finding-missing-auth-bugs-in-eosio-smart-contracts/) _on March 8, 2021._

> Join Coinmonks [Telegram group](https://t.me/joinchat/EPmjKpNYwRMsBI4p) and learn about crypto trading and investing

#### Also, Read

- [What is Margin Trading](https://blog.coincodecap.com/margin-trading)
- The Best [Crypto Trading Bot](https://medium.com/coinmonks/crypto-trading-bot-c2ffce8acb2a) | [Grid Trading](https://blog.coincodecap.com/grid-trading)
- [3Commas Review](https://medium.com/coinmonks/3commas-review-an-excellent-crypto-trading-bot-2020-1313a58bec92) | [Pionex Review](https://medium.com/coinmonks/pionex-review-exchange-with-crypto-trading-bot-1e459d0191ea) | [Coinrule review](https://medium.com/coinmonks/coinrule-review-2021-a-beginner-friendly-crypto-trading-bot-daf0504848ba)
- [AAX Exchange Review](https://medium.com/coinmonks/aax-exchange-review-2021-67c5ea09330c) | [Deribit Review](https://medium.com/coinmonks/deribit-review-options-fees-apis-and-testnet-2ca16c4bbdb2) |[FTX Exchange Review](https://medium.com/coinmonks/ftx-crypto-exchange-review-53664ac1198f)
- [NGRAVE ZERO review](https://medium.com/coinmonks/ngrave-zero-review-c465cf8307fc) | [Phemex Review](https://medium.com/coinmonks/phemex-review-4cfba0b49e28) | [PrimeXBT Review](https://medium.com/coinmonks/primexbt-review-88e0815be858)
- [Bybit Exchange Review](https://medium.com/coinmonks/bybit-exchange-review-dbd570019b71) | [Bityard Review](https://medium.com/coinmonks/bityard-review-7d104239be35) | [CoinSpot Review](https://blog.coincodecap.com/coinspot-review)
- [3Commas vs Cryptohopper](https://medium.com/coinmonks/3commas-vs-pionex-vs-cryptohopper-best-crypto-bot-6a98d2baa203) | [Earn crypto interest](https://medium.com/coinmonks/earn-crypto-interest-b10b810fdda3)
- The Best Bitcoin [Hardware wallet](https://medium.com/coinmonks/the-best-cryptocurrency-hardware-wallets-of-2020-e28b1c124069?source=friends_link&sk=324dd9ff8556ab578d71e7ad7658ad7c) | [BitBox02 Review](https://medium.com/coinmonks/bitbox02-review-your-swiss-bitcoin-hardware-wallet-c36c88fff29)
- [Ledger vs Ngrave](https://medium.com/coinmonks/ledger-vs-ngrave-zero-7e40f0c1d694) | [Ledger nano s vs x](https://medium.com/coinmonks/ledger-nano-s-vs-x-battery-hardware-price-storage-59a6663fe3b0)
- [Crypto Copy Trading Platforms](https://medium.com/coinmonks/top-10-crypto-copy-trading-platforms-for-beginners-d0c37c7d698c)
- [CoinLoan Review](https://medium.com/coinmonks/coinloan-review-18128b9badc4) | [YouHodler Review](https://medium.com/coinmonks/youhodler-4-easy-ways-to-make-money-98969b9689f2) | [BlockFi Review](https://medium.com/coinmonks/blockfi-review-53096053c097)
- The Best [Crypto Tax Software](https://medium.com/coinmonks/best-crypto-tax-tool-for-my-money-72d4b430816b) | [CoinTracking Review](https://medium.com/coinmonks/cointracking-review-a-reliable-cryptocurrency-tax-software-5114e3eb5737)
- Best [Crypto Lending Platforms](https://medium.com/coinmonks/top-5-crypto-lending-platforms-in-2020-that-you-need-to-know-a1b675cec3fa) | [Leveraged Token](https://medium.com/coinmonks/leveraged-token-3f5257808b22)
- [BlockFi vs Celsius](https://medium.com/coinmonks/blockfi-vs-celsius-vs-hodlnaut-8a1cc8c26630) | [Hodlnaut Review](https://medium.com/coinmonks/hodlnaut-review-best-way-to-hodl-is-to-earn-interest-on-your-bitcoin-6658a8c19edf)
- [Bitsgap review](https://medium.com/coinmonks/bitsgap-review-a-crypto-trading-bot-that-makes-easy-money-a5d88a336df2) | [Quadency Review](https://medium.com/coinmonks/quadency-review-a-crypto-trading-automation-platform-3068eaa374e1) | [Bitbns Review](https://medium.com/coinmonks/bitbns-review-38256a07e161)
- [Ellipal Titan Review](https://medium.com/coinmonks/ellipal-titan-review-85e9071dd029) | [SecuX Stone Review](https://medium.com/coinmonks/secux-stone-hardware-wallet-review-15-discount-coupon-2020-7577032faa6e)
- [LocalBitcoins Review](https://medium.com/coinmonks/localbitcoins-review-6cc001c6ed56) | [Cryptocurrency Savings Accounts](https://blog.coincodecap.com/cryptocurrency-savings-accounts)
- Best [Blockchain Analysis](https://bitquery.io/blog/best-blockchain-analysis-tools-and-software) Tools | [Earn Bitcoin](https://medium.com/coinmonks/earn-bitcoin-6e8bd3c592d9)
- [Crypto arbitrage](https://medium.com/coinmonks/crypto-arbitrage-guide-how-to-make-money-as-a-beginner-62bfe5c868f6) Guide | [How to Short Bitcoin](https://medium.com/coinmonks/how-to-short-bitcoin-568a2d0b4ae5)
- Best [Crypto Charting Tool](https://medium.com/coinmonks/what-are-the-best-charting-platforms-for-cryptocurrency-trading-85aade584d80) | [Best Crypto Exchange](https://medium.com/coinmonks/crypto-exchange-dd2f9d6f3769)
- [How to buy Bitcoin in India?](https://medium.com/coinmonks/buy-bitcoin-in-india-feb50ddfef94) | [WazirX Review](https://medium.com/coinmonks/wazirx-review-5c811b074f5b)
- [Bitcoin exchange in India](https://medium.com/coinmonks/bitcoin-exchange-in-india-7f1fe79715c9) | [Bitcoin Savings Account](https://medium.com/coinmonks/bitcoin-savings-account-e65b13f92451)
- [CoinDCX Review](https://medium.com/coinmonks/coindcx-review-8444db3621a2) | [Crypto Margin Trading Exchanges](https://blog.coincodecap.com/crypto-margin-trading-exchanges)

> [Get Best Software Deals Directly In Your Inbox](https://medium.com/coinmonks/newsletters/coinmonks)

[![](https://cdn-images-1.medium.com/max/584/1*BoDnKUyK8p4hitHAJZ5Pdw.png)](https://medium.com/coinmonks/newsletters/coinmonks)

* * *