Atomic Batched Transactions — Solving ERC-20 problems through MetaTX

George Spasov
Nov 9, 2018 · 3 min read

Executing multiple arbitrary blockchain transactions at once

Co-authored by me and Ivo Georgiev

Preface: Meta Transactions

Changing the Meta Proxy to support batches

While the community has been focusing on making a better relayer network or standardizing the Meta Proxy, we had the idea to try and batch multiple transactions together. This new-found atomicity of multiple transactions together seems to come quite handy in multiple scenarios. Some of them are:

  • ERC-20 approve+transferFrom based interactions
  • Decentralized exchanges

The batched transactions are achieved through simply changing the to, data and signature params to arrays. Now, all we do, is loop through them, validating and executing them. If a single transaction fails — the whole batch is going to be reverted. Look for the code below.

Use case: Solving ERC-20 non-atomicity through batched meta transactions

The main idea is that we build the two transactions with their signatures and send them to the MetaTx proxy. The two transactions have different ato, but will be performed in batch.

Image for post
Image for post

One of the main problems of the ERC20 token interactions is that they require 2 different transactions — one for approve and one for doingSomethingWithTheToken towards arbitrary contract (that internally calls transferFrom). This introduces all the problems of non-atomic transactions. The simplest problem is that even if your doSomethingForTokens transaction fails, your approve does not and your allowance still stands.

In the example above I’ve created a dummy token and a dummy service contract — Billboard. The Billboard contract has a buy function that allows you to buy the Billboard space for at least the amount the previous person has given.

Now on the positive scenario — we’ve built approve transaction data plus transaction signature, and buy transaction data plus transaction signature. Executing them together goes through successfully and we’ve been able to buy the Billboard space.

In the negative scenario, we reuse the same approve and buy artifacts. The difference is that the Billboard smart contract is now supposed to revert, as we are not sending a bigger amount of tokens than the previous time, thus we should not be able to buy the Billboard space. The test reverts successfully and in addition to the reverted buy transaction, the approve reverts as well— no attack vector is left to steal from your approval.

Conclusion


About the authors

George Spasov is Blockchain Architect and Co-founder of LimeChain. Twitter handle: @GSpasov

LimeChain

Blockchain & DLT Services and Solutions for Enterprises and…

Thanks to Daniel Ivanov

George Spasov

Written by

Blockchain Architect and Co-founder of http://limechain.tech

LimeChain

LimeChain

Blockchain & DLT Services and Solutions for Enterprises and Entrepreneurs. More on limechain.tech or directly at hi@limechain.tech

George Spasov

Written by

Blockchain Architect and Co-founder of http://limechain.tech

LimeChain

LimeChain

Blockchain & DLT Services and Solutions for Enterprises and Entrepreneurs. More on limechain.tech or directly at hi@limechain.tech

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store