project screenshot 1
project screenshot 2
project screenshot 3

TEX

TEX is an MEV-resistant DEX designed to provide a fair and efficient trading environment for traders. Swap tokens without "hidden" slippages.

TEX

Created At

HackMoney 2022

Winner of

trophy

🥇 Uniswap Grants Program — Uniswap Tooling

trophy

🏆 HackMoney Finalist

Project Description

This project combines time-lock puzzles and zero-knowledge proofs to build verifiable delay encryption for MEV-resistant transactions on DEX.

Traders' Exchange (TEX in short) is an MEV-resistant DEX for swapping tokens without “hidden slippages". Traders are paying more than they should due to MEV and the manipulation of their transactions. As transaction data is public, MEV searchers can capture profits through arbitrage steals or sandwich attacks, and miners also have the power to order transactions to make profits out of traders’ transactions. This leads to the traders’ financial losses, which we call these "hidden slippages".

To eliminate MEV, TEX encrypts the transactions with a symmetric key generated from time-lock puzzles, so that miners confirm the order of transactions without seeing the transaction contents. Then, miners can decrypt the transactions with the key from the solving time-lock puzzle and make state transitions. But, if miners can't see the contents, malicious traders are able to attack miners by sending invalid transactions. This leads to the miners wasting computational resources to solve the time-lock puzzles and block space.

This is why validity proof of transactions is needed to prove that time-lock puzzles and encryptions are done correctly. Generating the validity proof with general zk-SNARKs would be impractical for the trader. Therefore, we combined zk-SNARKs and Sigma protocol to make this process practical, which only takes 5 seconds for the traders.

How it's Made

= Trader =

Generating Validity Proof is composed of two main parts running inside zkp: 1) time-lock puzzle and 2) encryption of transactions

  1. Time-lock puzzle: We applied an RSA group to build a time-lock puzzle. To implement this process within zk-SNARKs, we used groth16 scheme from Bellman and Big-Nat libraries. And to make it practical, some of the processes were replaced by Sigma protocol. We call this PVDE (Practical Verifiable Delay Encryption)

  2. Encryption: We applied zk-SNARKs friendly Poseidon hash for encryption. We modified a library from Dusk-network to encrypt transactions more suitable for our implementation.

= Front-End =

  • We forked the front-end of Uniswap and made modifications to it. It’s quite difficult to integrate with our prototype as we needed to implement our own service to provide information about TEX.

  • We integrated MetaMask to sign transactions.

= TEX =

  • Chain: We deployed smart contracts on Polygon Mumbai Testnet. It was fast with cheap gas prices. Quite easy to integrate with MetaMask.

  • DEX protocol: We forked Uniswap v2 and made modifications on the Router smart contract to force the order of transactions.

background image mobile

Join the mailing list

Get the latest news and updates