Skip to content

Instantly share code, notes, and snippets.

benchmark gas @ 150 gwei, 1 ETH = $350
Account transactions
Deploy proxy account: $7.69, 0.02196825 ETH, 146455 gas
✓ Deploy proxy account (directly) (202ms)
Deploy proxy account (via ContractDeployer): $7.83, 0.022359 ETH, 149060 gas
✓ Deploy proxy account (via ContractDeployer) (252ms)
1st Tx: Transfer ETH (via executeCall): $3.22, 0.0092013 ETH, 61342 gas
2nd Tx: Transfer ETH (via executeCall): $2.43, 0.0069543 ETH, 46362 gas
3rd Tx: Transfer ETH (via executeCall): $2.43, 0.0069513 ETH, 46342 gas

Keybase proof

I hereby claim:

  • I am mikec on github.
  • I am mfcalvanese (https://keybase.io/mfcalvanese) on keybase.
  • I have a public key ASC2U7FJ9viEUuSWGob0tqkGSyhZ0d9oT-lANaSPxaDklAo

To claim this, I am signing this object:

@mikec
mikec / proxy-code-with-comments.sol
Created September 5, 2018 17:46
solidity-proxy-assembly-code
function () public payable {
address _impl = implementation();
require(_impl != address(0));
bytes memory data = msg.data;
assembly {
/*
delegatecall params explained:
gas: the amount of gas to provide for the call. `gas` is an Opcode that gives
us the amount of gas still available to execution
0xDf08F82De32B8d460adbE8D72043E3a7e25A3B39
pragma solidity ^0.4.19;
/**
* @title Proxy
* @dev Gives the possibility to delegate any call to a foreign implementation.
*/
contract Proxy {
/**
* @dev Tells the address of the implementation where every call will be delegated.
contract MintableTokenDelegate is TokenDelegate {
modifier onlyOwner {
require(msg.sender == _storage.getAddress("owner"));
_;
}
modifier canMint() {
require(!_storage.getBool("mintingFinished"));
_;
contract TokenDelegate is StorageStateful {
using SafeMath for uint256;
function transfer(address to, uint256 value) public returns (bool) {
require(to != address(0));
require(value <= getBalance(msg.sender));
subBalance(msg.sender, value);
addBalance(to, value);
return true;
contract KeyValueStorage {
mapping(address => mapping(bytes32 => uint256)) _uintStorage;
mapping(address => mapping(bytes32 => address)) _addressStorage;
mapping(address => mapping(bytes32 => bool)) _boolStorage;
/**** Get Methods ***********/
function getAddress(bytes32 key) public view returns (address) {
return _addressStorage[msg.sender][key];
pragma solidity ^0.4.18;
import "./StorageStateful.sol";
contract TokenDelegate is StorageStateful {
function totalSupply() public view returns (uint256) {
return _storage.getUint("totalSupply");
}
contract Thing is Proxy {
uint256 num;
string name = "Thing";
}
contract ThingDelegate {
uint256 n;
function incrementNum() public {
n = n + 1;