Ethereum Gatling Gun — The Fastest Wallet Out There

  1. Send 1 Ether to some other wallet
  2. Send 1 ERC223 token to some other wallet
  3. Call a contract with no function arguments
  4. Call a contract with some function arguments as well as an Ether value

Introduction

Simple Proxy Contract

pragma solidity ^0.4.25;contract Proxy {
function execute(
address target, uint256 weiValue, bytes payload
) public {
target.call.value(weiValue)(payload);
}
}

Limitations of Solidity and Experimental Encoders

pragma solidity ^0.4.25;contract ArrayProxy {
function execute(
address[] targets, uint256[] weiValues, bytes[] payloads
) public {
for(uint256 i = 0; i < targets.length; i++){
targets[i].call.value(weiValues[i])(payloads[i]);
}
}
}
Error: This type is only supported in the new experimental ABI encoder.
Use "pragma experimental ABIEncoderV2;" to enable the feature.
address[] targets, uint256[] weiValues, bytes[] payloads
^--------------^

Solidity != EVM, Leveraging Inline Assembly

Dissecting the CALL opcode

assembly{
call(
<gas_limit>,
<target>,
<wei_value>,
<data_location>,
<data_length>,
<output_location>,
<output_length>
)
}

Writing the Gatling Gun wallet

function fire(
bytes, address[] targets, uint256[] lengths, uint256[] values
)
require(targets.length == lengths.length);
require(targets.length == values.length);
uint256 payloadMemoryLocation;
assembly {
payloadMemoryLocation := mload(0x40)let payloadLengthLocation := add(4, calldataload(4))
let payloadLength := calldataload(payloadLengthLocation)
let payloadLocation := add(32, payloadLengthLocation)
calldatacopy(payloadMemoryLocation, payloadLocation, payloadLength)
mstore(0x40, add(payloadMemoryLocation, payloadLength))
}
uint256 offset = 0;
bool success;
for(uint256 i = 0; i < targets.length; i++){
address target = targets[i];
uint256 limit = lengths[i];
uint256 value = values[i];

# ASSEMBLY MAGIC HERE
require(success);
offset += limit;
}
assembly {
success := call(
gas,
target,
value,
add(payloadMemoryLocation, offset),
limit,
0,
0
)
}

Usage Demonstration

  1. Send 1 Ether to some other wallet
  2. Send 1 ERC223 token to some other wallet
  3. Call a contract with no function arguments
  4. Call a contract with some function arguments as well as an Ether value
0x785b8612b225b06764499f61e098725864ecd26b - 
1000000000000000000 -
0x
0x14c926f2290044b647e1bf2072e67b495eff1905 - 
0 -
0xa9059cbb000000000000000000000000abcd412dd0e1b3a3bf1131e927450f71f2e9085a0000000000000000000000000000000000000000000000000de0b6b3a7640000
0xeeb66b5624ddfa13bee72d9e9dc418a34a74b5c5 - 
0 -
0xd09de08a
0x06741096ef84fd751b0805a96583123b5cb11540 - 
1000000000000000000 -
0x8b3c99e3000000000000000000000000000000000000000000000000000000000000007b
0x785b8612b225b06764499f61e098725864ecd26b - 1000000000000000000 - 0x ; 0x14c926f2290044b647e1bf2072e67b495eff1905 - 0 - 0xa9059cbb000000000000000000000000abcd412dd0e1b3a3bf1131e927450f71f2e9085a0000000000000000000000000000000000000000000000000de0b6b3a7640000 ; 0xeeb66b5624ddfa13bee72d9e9dc418a34a74b5c5 - 0 - 0xd09de08a ; 0x06741096ef84fd751b0805a96583123b5cb11540 - 1000000000000000000 - 0x8b3c99e3000000000000000000000000000000000000000000000000000000000000007b

Evaluation

Conclusion

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

#CPDinSpace #coinspaid

DRIP Price Arbitrage?

Funding the Future: a look into the new Polis Reward Distribution

Monthly Update of Astar Network

What is KubeSwap?

Dcoin will list SKL/USDT on April 14

AMA Recap with Decentralized Club

Mining of Cryptocurrencies With Your Smartphone- Android Devices

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
Simon Rovder

Simon Rovder

More from Medium

Guide To Convert ERC-20 Tokens To The Binance Smart Chain With The Binance Bridge

2021’s biggest trends in your own language [Part II].

The most complete blockchain financial investment information query and airdrop tutorial Fomoin.fina

Fast’s Crypto Newsletter #1 — Using Metamask, introduction to AAVE