Skip to content

Commit

Permalink
Remove unused test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohann committed Sep 26, 2024
1 parent d0706e8 commit 2fd1838
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 133 deletions.
78 changes: 60 additions & 18 deletions src/FactoryUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,66 @@ pragma solidity ^0.8.27;

import {IUniversalFactory} from "./UniversalFactory.sol";

/**
* @title A library with helper methods for compute `CREATE2` and `CREATE3` addresses.
* @author Lohann Paterno Coutinho Ferreira <[email protected]>
*/
library FactoryUtils {
// Create3Proxy creation code
// 0x763318602e57363d3d37363d34f080915215602e57f35bfd6017526460203d3d7360a01b33173d5260306007f3:
// 0x00 0x67 0x763318602e.. PUSH23 0x3318.. 0x3318602e57363d3d37363d34f080915215602e57f35bfd
// 0x01 0x3d 0x3d PUSH1 0x58 23 0x3318602e57363d3d37363d34f080915215602e57f35bfd
// 0x01 0x3d 0x3d MSTORE
// 0x03 0x52 0x5260203d3d.. PUSH5 0x60203.. 0x60203d3d73
// 0x04 0xf3 0x6008 PUSH1 0xa0 160 0x60203d3d73
// 0x05 0x60 0x6018 SHL 0x60203d3d730000000000000000000000000000000000000000
// 0x06 0x3d 0x3d CALLER addr 0x60203d3d730000000000000000000000000000000000000000
// 0x08 0xf3 0xf3 OR 0x60203d3d73XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// 0x09 0x60 0x6018 RETURNDATASIZE 0 0x60203d3d73XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// 0x04 0xf3 0x6008 PUSH1 0x30 48
// 0x04 0xf3 0x6008 PUSH1 0x07 7 48
// 0x14 0x3d 0x3d RETURN
/**
* @notice The `Create3Proxy` is a contract that proxies the creation of another contract
* @dev If this code is deployed using CREATE2 it can be used to decouple `creationCode` from the child contract address.
*
* Create3Proxy creation code
* 0x763318602e57363d3d37363d34f080915215602e57f35bfd602b52336014526460203d3d733d526030601bf3:
* 0x00 0x763318602e.. PUSH23 0x3318.. 0x3318602e57363d3d37363d34f080915215602e57f35bfd
* 0x18 0x602b PUSH1 0x2b 43 0x3318602e57363d3d37363d34f080915215602e57f35bfd
* 0x1a 0x52 MSTORE
* 0x1b 0x33 CALLER addr
* 0x1c 0x6014 PUSH1 20 20 addr
* 0x1f 0x52 MSTORE
* 0x25 0x6460203d3d73 PUSH5 0x6020.. 0x60203d3d73
* 0x26 0x3d RETURNDATASIZE 0 0x60203d3d73
* 0x27 0x52 MSTORE
* 0x29 0x6030 PUSH1 48 48
* 0x2a 0x601b PUSH1 27 27 48
* 0x2b 0xf3 RETURN
*
* Create3Proxy runtime code, where `XXXX..` is the Universal Factory contract address.
* 0x60203d3d73XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX3318602e57363d3d37363d34f080915215602e57f35bfd
* 0x00 0x6020 PUSH1 32 32
* 0x02 0x3d RETURNDATASIZE 0 32
* 0x03 0x3d RETURNDATASIZE 0 0 32
* 0x04 0x74XXXXXX.. PUSH20 XXXXXXX factory 0 0 32
* 0x19 0x33 CALLER caller factory 0 0 32
* 0x1a 0x18 XOR invalid 0 0 32
* 0x1b 0x602e PUSH1 0x2e 46 invalid 0 0 32
* ,=< 0x1d 0x57 JUMPI 0 0 32
* | 0x1e 0x36 CALLDATASIZE cls 0 0 32
* | 0x1f 0x3d RETURNDATASIZE 0 cls 0 0 32
* | 0x20 0x3d RETURNDATASIZE 0 0 cls 0 0 32
* | 0x21 0x37 CALLDATACOPY 0 0 32
* | 0x22 0x36 CALLDATASIZE cls 0 0 32
* | 0x23 0x3d RETURNDATASIZE 0 cls 0 0 32
* | 0x24 0x34 CALLVALUE val 0 cls 0 0 32
* | 0x25 0xf0 CREATE addr 0 0 32
* | 0x26 0x80 DUP1 addr addr 0 0 32
* | 0x27 0x91 SWAP2 0 addr addr 0 32
* | 0x28 0x52 MSTORE addr 0 32
* | 0x29 0x16 ISZERO fail 0 32
* | 0x2a 0x602e PUSH1 0x2e 46 fail 0 32
* |=< 0x2c 0x57 JUMPI 0 32
* | 0x2d 0xf3 RETURN
* `=> 0x2e 0x5b JUMPDEST
* 0x2f 0xfd REVERT
*/
bytes internal constant PROXY_INITCODE =
hex"763318602e57363d3d37363d34f080915215602e57f35bfd6017526460203d3d7360a01b33173d5260306007f3";
bytes32 internal constant PROXY_INITCODE_HASH = keccak256(PROXY_INITCODE);
hex"763318602e57363d3d37363d34f080915215602e57f35bfd602b52336014526460203d3d733d526030601bf3";

/**
* @dev Create3Proxy creation code hash
* PROXY_INITCODE_HASH == keccak256(PROXY_INITCODE)
*/
bytes32 internal constant PROXY_INITCODE_HASH = 0xcb98364b80db304e3c59b36036695fcfcaf2d56d8bdfeb39be950fe627a2f752;

/**
* @dev Compute the create2 address of an contract created by `UniversalFactory`.
Expand Down Expand Up @@ -81,7 +123,7 @@ library FactoryUtils {
}

/**
* @dev Compute the create3 salt.
* @dev Compute the create3 salt, this is used to guarantee the uniqueness of the create3 address per deployer.
*/
function computeCreate3Salt(address deployer, uint256 salt) internal pure returns (bytes32 create3salt) {
// The code below is equivalent to the Solidity code:
Expand Down Expand Up @@ -122,7 +164,7 @@ library FactoryUtils {
mstore(0x00, factory)
mstore8(11, 0xff)
mstore(0x20, salt)
mstore(0x40, 0xda812570be8257354a14ed469885e4d206be920835861010301b25f5c180427a)
mstore(0x40, PROXY_INITCODE_HASH)
mstore(0x14, keccak256(11, 85))
mstore(0x00, 0xd694)
mstore8(0x34, 0x01)
Expand Down
Loading

0 comments on commit 2fd1838

Please sign in to comment.