Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Minimal Proxy Contract to library #28

Merged
merged 2 commits into from Mar 9, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -2,6 +2,8 @@ pragma solidity ^0.5.0;

import "./Marmo.sol";
import "./commons/Bytes.sol";
import "./commons/MinimalProxy.sol";


// MarmoStork creates all Marmo wallets
// every address has a designated marmo wallet
@@ -10,22 +12,6 @@ import "./commons/Bytes.sol";
// All wallets are proxies pointing to a single
// source contract, to make deployment costs viable
contract MarmoStork {
using Bytes for address;
using Bytes for bytes1;
using Bytes for bytes;

// Minimal proxy contract
// by Agusx1211
bytes constant CODE1 = hex"60"; // + <size> // Copy code to memory
bytes constant CODE2 = hex"80600b6000396000f3"; // Return and deploy contract
bytes constant CODE3 = hex"3660008037600080366000"; // + <pushx> + <source> // Proxy, copy calldata and start delegatecall
bytes constant CODE4 = hex"5af43d6000803e60003d9160"; // + <return jump> // Do delegatecall and return jump
bytes constant CODE5 = hex"57fd5bf3"; // Return proxy

bytes1 constant BASE_SIZE = 0x1d;
bytes1 constant PUSH_1 = 0x60;
bytes1 constant BASE_RETURN_JUMP = 0x1b;

// Bytecode to deploy marmo wallets
bytes public bytecode;

@@ -43,20 +29,13 @@ contract MarmoStork {
// the difference will be filled with 0s at the beginning of the address
constructor(bytes memory _source) public {
// Generate and save wallet creator bytecode using the provided '_source'
bytecode = Bytes.concat(
CODE1,
BASE_SIZE.plus(_source.length).toBytes(),
CODE2,
CODE3.concat(PUSH_1.plus(_source.length - 1)).concat(_source),
CODE4.concat(BASE_RETURN_JUMP.plus(_source.length)),
CODE5
);
bytecode = MinimalProxy.build(_source);

// Precalculate init_code hash
hash = keccak256(bytecode);

// Destroy the '_source' provided, if is not destroyed
Marmo marmoc = Marmo(_source.toAddress());
Marmo marmoc = Marmo(Bytes.toAddress(_source));
if (marmoc.signer() == address(0)) {
marmoc.init(address(65536));
}
@@ -0,0 +1,33 @@
pragma solidity ^0.5.0;

import "./Bytes.sol";


library MinimalProxy {
using Bytes for address;
using Bytes for bytes1;
using Bytes for bytes;

// Minimal proxy contract
// by Agusx1211
bytes constant CODE1 = hex"60"; // + <size> // Copy code to memory
bytes constant CODE2 = hex"80600b6000396000f3"; // Return and deploy contract
bytes constant CODE3 = hex"3660008037600080366000"; // + <pushx> + <source> // Proxy, copy calldata and start delegatecall
bytes constant CODE4 = hex"5af43d6000803e60003d9160"; // + <return jump> // Do delegatecall and return jump
bytes constant CODE5 = hex"57fd5bf3"; // Return proxy

bytes1 constant BASE_SIZE = 0x1d;
bytes1 constant PUSH_1 = 0x60;
bytes1 constant BASE_RETURN_JUMP = 0x1b;

function build(bytes memory _address) internal pure returns (bytes memory initCode) {
initCode = Bytes.concat(
CODE1,
BASE_SIZE.plus(_address.length).toBytes(),
CODE2,
CODE3.concat(PUSH_1.plus(_address.length - 1)).concat(_address),
CODE4.concat(BASE_RETURN_JUMP.plus(_address.length)),
CODE5
);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.