Paper title: SGXonerated: Finding (and Partially Fixing) Privacy Flaws in TEE-based Smart Contract Platforms Without Breaking the TEE
Artifacts HotCRP Id: 87
Requested Badge: Reproducible
There are three main artifacts, briefly described below.
Contains the source code and docker-based environment to simulate a sandwich attack on a private swap as described in section 6.2 of the paper.
Contains the source code, building toolchain and instructions to break the transfer amount privacy assumptions of receivers of SNIP-20 tokens as described in section 5.3 of the paper.
Contains the source code, building toolchain and instructions to break the account balance amount privacy assumptions of SNIP-20 accounts as described in section 5.5 of the paper.
None.
None.
None.
We recommend using a linux machine with a recent docker engine installed.
- Time to build the docker image: N/A we provide a prebuilt image
- Time to bootstrap the local network: < 5 minutes
- Time to run each attack for artifact 1 and 2: < 1 minute each
- Time to run attack for artifact 3: < 5 minutes
None
Ordinary linux machine with docker engine installed and manageable as a non-root user.
Please make sure your user ($USER
) is part of the docker
group.
You can do so by running the following commands:
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Test the docker command without sudo:
docker run hello-world
-
5 minutes setup
-
<1 minute for each artifacts 1 and 2
-
5 minute artifact 3
-
Github commit: Latest
-
Pulls prebuild images from initc3 docker image repo
We assume a linux operating system and we have run the experiment on Ubuntu 22.04.
Clone the repository, making sure you fetch the submodules, e.g.:
git clone --recurse-submodules https://github.com/initc3/SecretNetwork-Sandbox.git
If you are missing the submodules after having cloned, run:
git submodule update --init --recursive --remote
Go into the hacking
directory:
cd hacking/
Setup and start the local network with:
make start
What does the above command do?
Full description of start_node.sh
-
Start a validator node (node-1) and a non-validator node (node-2)
-
Store and instantiate Toy Uniswap demo contracts and set up the initial states for the MEV sandwhich attack. The pool sizes are 1000 for
token_a
and 2000 fortoken_b
. The victim and adversary account in the toy-swap contract each have a balance of 100token_a
andtoken_b
. -
Store and instantiate snip-20 contract and set up the initial states for the SNIP-20 privacy attack demos. The victim account has a balance of 12343. Two attacker accounts have balance of 10000 each.
-
Shut down node-1 to launch the attack in simulation mode without broadcasting any transactions to the network.
At the end of its execution the script should end with an output similar to:
...
*********************************************************************************
* *
* Secret Network Test Nodes are now setup, and ready for experiments. *
* *
*********************************************************************************
Node 2 status info:
{
"Address": "A80B0E25EEA4665348F071A41B8122AF079BB2AF",
"PubKey": {
"type": "tendermint/PubKeyEd25519",
"value": "Ew9FY1+mRmXWTnAklkyjcPMiJfbz23b06UtsC04xTQw="
},
"VotingPower": "0"
}
Make sure your user ($USER
) is part of the docker
group.
getent group docker | grep $USER
If not, then add your user to the docker group:
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Test the docker command without sudo:
docker run hello-world
Check docker version:
docker version
Must be >= 24.0.5.
Make sure the docker compose command is available:
docker compose
Check that only node-2 is running
docker ps | grep hacking-localsecret-2-1
We are able to determine the optimal sandwhich attack transactions for a token swap contract as described in section 6.2 of the paper.
We are able to determine the transfer amount for a SNIP-20 token transfer transaction as described in section 5.3 of the paper.
We are able to determine the balance of a SNIP-20 account as described in section 5.5 of the paper.
Launch the sandwich attack.The script creates a victim transaction swaping 10 token A for token b with slippage limit 20. (Given that the Pool balance for token a is 1000 and Pool balance for token B is 2000) It prints the optimal frontrun transaction of swaping 20 of token a for token b, and the optimal backrun transaction of swaping 40 of tokeb b for token a.
make sandwich-attack
What does the above command do?
Full description of sandwich-attack.sh
The above command simulates an adversary executing the following steps:
-
Generate a victim swap transaction to swap 10
token_a
for at least 20token_b
. -
Find a front-run transaction by bisection search that, when executed before the victim's transaction, won't fail the victim's transaction. The front-run transaction found swaps 20
token_a
with a slippage limit of 0, resulting in obtaining 40token_b
. -
After the victim's transaction, the adversary executes a back-run transaction to sell the 40
token_b
, increasing their balance oftoken_a
by 1 and maintaining their balance oftoken_b
.
Getting transfer amount. This script generates a victim transaction sending 10 of a SNIP-20 token to another account. It figures out the transfer amount prints it.
make transfer-privacy-attack
What does the above command do?
Full description of transfer-privacy-attack.sh
The above command simulates an adversary executing the following steps:
-
Generate a victim transaction to transfer 10 tokens to another account
-
Find a transfer amount by bisection search to figure out the tranfer amount:
- that sets the victim's balance to 0
- sends an amount
guess
to the victim's account resulting in the victim's account having a balance ofguess
- execute the victim's transaction to see if
guess
was enough to conver the victim's transfer transaction
-
If the
guess
was enough to cover the victim's transfer transaction thenguess
is the transfer amount
Getting the account balance. The script figures out and prints the victim's balance of 12343.
make balance-privacy-attack
What does the above command do?
Full description of balance-privacy-attack.sh
The above command simulates an adversary executing the following steps:
-
Execute balance inflation by creating transfers between the attacker's two accounts, reseting the account balance to the original value before the transfer, and repeating this until the balance has the maximum value.
-
Find a transaction by bisection search that transfers
guess
from the attacker's account to the victim's account until it causes an overflow error. -
The victim's balance is the
2**128-1-guess