GithubHelp home page GithubHelp logo

troublor / erebus-redgiant Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 1.0 2.75 MB

Smart contract front-running vulnerability benchmark

Home Page: https://arxiv.org/abs/2212.12110

License: Creative Commons Zero v1.0 Universal

Solidity 0.40% Yul 0.08% Go 99.52%
benchmark blockchain ethereum front-running smart-contracts vulnerability

erebus-redgiant's Introduction

Hi there 👋

I'm William Aaron Cheung. You can call me William or Aaron, whichever you find easy to read. My formal name is Wuqi Zhang but it is a bit difficult to pronounce so I prefer to use the previous English name in most informal cases.

I recognize myself as two roles: a Full-Stack Software Developer and a Software Engineering Researcher. Please see explanations bellow.

As a Researcher 🧑‍🔬

I am a PhD candidate in the Hong Kong University of Science and Technology (HKUST). I do research in Software Engineering (SE) in CASTLE research group under the supervision of Prof. Shing-Chi Cheung.

My research currently focuses on program analysis and software testing with the application to blockchain applications such as smart contracts and DApps. I am also interested in Deep Learning (DL) application testing, Internet of Things (IoT) software testing, website fingerprinting attack and defense, etc. You can find my research experience and publications in my personal website: https://troublor.xyz

As a Developer 🧑‍💻

I believe a good SE researcher should be an excellent software engineer in the first place. Therefore, I am also a full stack software developer capable of:

  • Web Development with Typescript and React.js
  • Server-side Development with Golang, and Node.js
  • Command Line Tool development with Golang, Typescript, Rust, and Haskell
  • Scripting with Python (yes, Python is just a script language. 🧐 I don't accept arguments), Bash, and Zsh
  • and so many more...

I am passionate in functional programming and strongly typed programming languages, and recently program a lot in Typescript and Haskell.

erebus-redgiant's People

Contributors

otto-aa avatar troublor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jiawen2000411

erebus-redgiant's Issues

Questions regarding the profit properties for a specific displacement attack

I've started to look through the displacement attacks by Frontrunner Jones and got confused why the following attack got reported also by this tool.

The transactions:

The victim transaction is contained in the attacker transaction, which explains why it is included as a displacement attack in the Frontrunner Jones paper. However, from my current understanding, I don't see how these transactions fulfill the Attacker Gain and Victim Loss properties.

Property definitions from the paper Property 1 (Attacker Gain): The attacker obtains financial gain in the attack scenario compared with the attack-free scenario.

Property 2 (Victim Loss): The victim suffers from financial loss in the attack scenario compared with the attack-free scenario.

Understanding the transactions

I'm relatively new to analyzing ethereum transactions, so I may have missed something. Feel free to double check :)

The victim transaction directly calls multihopBatchSwapExactIn(...) from this ExchangeProxy contract. The attacker transactions makes a call with exactly the same data (as we can see here at "Action [11]"), but also performs some pre- and postprocessing.

The call essentially converts between different currencies/tokens:

  • 6 ether to 6000000000000000000 WETH
  • all WETH tokens to 100495097474324020199 BAL
  • all BAL tokens to 2013713552 USDC

The USDC are the final outcome without any additional WETH left. For the attacker this means that they converted 6 ether to 2013713552 USDC. In the preprocessing, the attacker withdrew these 6 ether from 6000000000000000000 WETH, so all in all they changed WETH to USDC.

For the victim, the transaction failed and they only paid a small transaction fee, while the 6 ether value were returned.

My profit calculations

The victim case is easier, so I will start with this one:

In the attack scenario (where the transaction failed) the victims balance is:

  • 6 ether (the ether it didn't spent)
  • 0 USDC tokens

In the attack-free scenario the victims balance would likely be (I could not verify this with an EVM simulation, because I couldn't setup my test environment that well yet):

  • 0 ether
  • 2013713552 USDC

While the amount of USDC tokens increased, the ether balance would decrease. Looking at profit_test.go this seems like an "ErrNotComparable" case to me, where we can't compare the profits and thus should disregarded this possible attack.

For the attacker it is likely the same case but mirrored. However, this also depends on the pre- and postprocessing of the executing contract (in particular how it catches errors and how it handles them). So while this also looks strange to me, I'm less sure about this one.

Questions

Did I miss something in general? Or used the definitions wrong? For the attacker profits, I was also confused for which account the profits are calculated (for tx.origin who initiated everything, or the contract that orchestrates everything, or the sub-contract that actually executes the swap transaction, or even a mixture of them?).


And in case you are curious, I'm asking these questions in the process of defining my master thesis topic. Currently I'm trying to understand better the different types of frontrunning attacks, before diving into how they could be detected by a code analysis tool. With my current setup, even a full node is not possible for me, so I couldn't run the erebus-redgiant analysis myself on these transactions and also couldn't find the results in the repository.

CGO compilation error

github.com/torquem-ch/mdbx-go/mdbx

mdbx.c:19127:5: error: conflicting types for ‘mdbx_cursor_put’ due to enum/integer mismatch; have ‘int(MDBX_cursor *, const MDBX_val *, MDBX_val *, unsigned int)’ {aka ‘int(MDBX_cursor *, const struct iovec *, struct iovec *, unsigned int)’} [-Werror=enum-int-mismatch]
19127 | int mdbx_cursor_put(MDBX_cursor *mc, const MDBX_val *key, MDBX_val *data,
| ^~~~~~~~~~~~~~~
In file included from mdbx.c:132:
mdbx.h:4624:17: note: previous declaration of ‘mdbx_cursor_put’ with type ‘int(MDBX_cursor *, const MDBX_val *, MDBX_val *, MDBX_put_flags_t)’ {aka ‘int(MDBX_cursor *, const struct iovec *, struct iovec *, MDBX_put_flags_t)’}
4624 | LIBMDBX_API int mdbx_cursor_put(MDBX_cursor *cursor, const MDBX_val *key,
| ^~~~~~~~~~~~~~~
mdbx.c:23042:5: error: conflicting types for ‘mdbx_put’ due to enum/integer mismatch; have ‘int(MDBX_txn *, MDBX_dbi, const MDBX_val *, MDBX_val *, unsigned int)’ {aka ‘int(MDBX_txn *, unsigned int, const struct iovec *, struct iovec *, unsigned int)’} [-Werror=enum-int-mismatch]
23042 | int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data,
| ^~~~~~~~
mdbx.h:4223:17: note: previous declaration of ‘mdbx_put’ with type ‘int(MDBX_txn *, MDBX_dbi, const MDBX_val *, MDBX_val *, MDBX_put_flags_t)’ {aka ‘int(MDBX_txn *, unsigned int, const struct iovec *, struct iovec *, MDBX_put_flags_t)’}
4223 | LIBMDBX_API int mdbx_put(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key,
| ^~~~~~~~
mdbx.c:23727:12: error: conflicting types for ‘mdbx_env_copy2fd’ due to enum/integer mismatch; have ‘int(MDBX_env *, mdbx_filehandle_t, unsigned int)’ {aka ‘int(MDBX_env *, int, unsigned int)’} [-Werror=enum-int-mismatch]
23727 | __cold int mdbx_env_copy2fd(MDBX_env *env, mdbx_filehandle_t fd,
| ^~~~~~~~~~~~~~~~
mdbx.h:2378:17: note: previous declaration of ‘mdbx_env_copy2fd’ with type ‘int(MDBX_env *, mdbx_filehandle_t, MDBX_copy_flags_t)’ {aka ‘int(MDBX_env *, int, MDBX_copy_flags_t)’}
2378 | LIBMDBX_API int mdbx_env_copy2fd(MDBX_env env, mdbx_filehandle_t fd,
| ^~~~~~~~~~~~~~~~
mdbx.c:25117:12: error: conflicting types for ‘mdbx_setup_debug’ due to enum/integer mismatch; have ‘int(int, int, void (
)(MDBX_log_level_t, const char *, int, const char *, __va_list_tag *))’ [-Werror=enum-int-mismatch]
25117 | __cold int mdbx_setup_debug(int loglevel, int flags, MDBX_debug_func logger) {
| ^~~~~~~~~~~~~~~~
mdbx.h:973:17: note: previous declaration of ‘mdbx_setup_debug’ with type ‘int(MDBX_log_level_t, MDBX_debug_flags_t, void (
)(MDBX_log_level_t, const char *, int, const char *, __va_list_tag ))’
973 | LIBMDBX_API int mdbx_setup_debug(MDBX_log_level_t log_level,
| ^~~~~~~~~~~~~~~~
mdbx.c:26605:23: error: conflicting types for ‘mdbx_get_keycmp’ due to enum/integer mismatch; have ‘int (
(unsigned int))(const MDBX_val *, const MDBX_val )’ {aka ‘int ((unsigned int))(const struct iovec *, const struct iovec *)’} [-Werror=enum-int-mismatch]
26605 | __cold MDBX_cmp_func mdbx_get_keycmp(unsigned flags) {
| ^~~~~~~~~~~~~~~
mdbx.h:4907:1: note: previous declaration of ‘mdbx_get_keycmp’ with type ‘int (
(MDBX_db_flags_t))(const MDBX_val *, const MDBX_val )’ {aka ‘int ((MDBX_db_flags_t))(const struct iovec *, const struct iovec )’}
4907 | mdbx_get_keycmp(MDBX_db_flags_t flags);
| ^~~~~~~~~~~~~~~
mdbx.c:26609:23: error: conflicting types for ‘mdbx_get_datacmp’ due to enum/integer mismatch; have ‘int (
(unsigned int))(const MDBX_val *, const MDBX_val )’ {aka ‘int ((unsigned int))(const struct iovec *, const struct iovec *)’} [-Werror=enum-int-mismatch]
26609 | __cold MDBX_cmp_func mdbx_get_datacmp(unsigned flags) {
| ^~~~~~~~~~~~~~~~
mdbx.h:4932:1: note: previous declaration of ‘mdbx_get_datacmp’ with type ‘int (
(MDBX_db_flags_t))(const MDBX_val *, const MDBX_val )’ {aka ‘int ((MDBX_db_flags_t))(const struct iovec *, const struct iovec *)’}
4932 | mdbx_get_datacmp(MDBX_db_flags_t flags);
| ^~~~~~~~~~~~~~~~

Is "**Under construction: source code not published**" still the case?

Hi, regarding this section of tool.md:

erebus-redgiant/tool.md

Lines 3 to 20 in 8747772

**Under construction: source code not published**
This repository offers `erebus`, which is the implementation of the search algorithm for historical front-running attacks in Ethereum history and vulnerability localization technique from each attack by extracting influence traces.
`erebus` searches for front-running attacks in the specified block range and save attacks to MongoDB database.
For each found attack, `erebus` will analyze the exploited vulnerability, by extracting influence traces from the attack.
Details can be found in our paper.
## Only Executable before Acceptance
The executable binary of `erebus` can be downloaded from the [Release](https://github.com/erebus-redgiant/tool/releases) page.
We only provide our tool as executable binary files before our paper is accepted.
There are several reasons.
First, the source code of our implementation has some dependencies that will reveal the authors' identities.
Second, we would like to avoid unauthorized use of our code before publication.
We will open source our erebus after the paper is accepted.

Is there still code missing, oder is this just an artifact from the past?

Notify calls private telegram endpoint

The notify option calls a seemingly private API endpoint. You may want to remove this from the source code and change the endpoint (or add some kind of authentication). I didn't test if it still works though.

if notify {
log.Info().Msg("I will tell you via Telegram when I exit either with or without error")
defer func() {
err := recover()
var msg string
if err != nil {
msg = fmt.Sprintf("Started At: %s\nStopped At: %s\nProgram panic: %s", startTime, time.Now(), err)
} else {
msg = fmt.Sprintf("Started At: %s\nStopped At: %s\nProgram exit without error", startTime, time.Now())
}
if !interrupted {
_, _ = http.Post(
fmt.Sprintf("https://troublor.xyz/telegram/notify/%s", "troublor"),
"text/plain",
strings.NewReader(msg),
)
}
if err != nil {
panic(err)
}
}()
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.