Skip to content

Commit

Permalink
Merge pull request sphinx-labs#921 from sphinx-labs/sg/docs-create3
Browse files Browse the repository at this point in the history
docs(ct): update docs for create3 contract interface
  • Loading branch information
sam-goldman authored Aug 8, 2023
2 parents c1280e9 + 2cde104 commit 54be0a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion packages/contracts/contracts/DefaultCreate3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { ICreate3 } from "./interfaces/ICreate3.sol";
/**
* @title DefaultCreate3
* @notice Default implementation of the ICreate3 interface. The default Create3 formula is used on
Ethereum and networks that are EVM-equivalent, or close to it.
* Ethereum and networks that are EVM-equivalent, or close enough to it.
*
* See the `ICreate3` interface for more information.
*/
contract DefaultCreate3 is ICreate3 {
using Bytes32AddressLib for bytes32;
Expand Down
6 changes: 4 additions & 2 deletions packages/contracts/contracts/SphinxManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,10 @@ contract SphinxManager is
);
registry.announce("ContractDeploymentSkipped");
} else {
// We delegatecall the Create3 contract so that the SphinxManager address is used in
// the address calculation of the deployed contract.
// We delegatecall the Create3 contract so that the SphinxManager address is used in the
// address calculation of the deployed contract. If we call the Create3 contract instead
// of delegatecalling it, it'd be possible for an attacker to snipe a user's contract by
// calling the `deploy` function on the Create3 contract directly.
(bool deploySuccess, bytes memory actualAddressBytes) = create3.delegatecall(
abi.encodeCall(ICreate3.deploy, (salt, creationCodeWithConstructorArgs, 0))
);
Expand Down
19 changes: 14 additions & 5 deletions packages/contracts/contracts/interfaces/ICreate3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ pragma solidity ^0.8.15;

/**
* @title ICreate3
* @notice Interface for a Create3 contract. Normally, this functionality would in a library.
Instead, we put it in a contract so that other contracts can use non-standard Create3 formulas in
a modular way. If we opted for a library to implement this functionality, we would need separate
copies of each contract that uses the library, where each contract would use a different
implementation of the Create3 formula.
* @notice Interface for a Create3 contract. Normally, this functionality would exist as internal
* functions in a library, which can be inherited by other contracts. Instead, we put this
* functionality in a contract so that other contracts can use non-standard Create3 formulas
* in a modular way. These non-standard Create3 formulas exist on some EVM-compatible
* chains. Each Create3 contract that inherits from this interface will implement its own
* Create3 formula.
*
* The contracts that inherit from this interface are meant to be delegatecalled by the
* `SphinxManager` in order to deploy contracts. It's important to note that a Create3
* contract must be delegatecalled by the `SphinxManager` and not called directly. This
* ensures that the address of the deployed contract is determined by the address of the
* `SphinxManager` contract and not the Create3 contract. Otherwise, it'd be possible for an
* attacker to snipe a user's contract by calling the `deploy` function on the Create3
* contract.
*/
interface ICreate3 {
// The creation code isn't used in the address calculation.
Expand Down

0 comments on commit 54be0a0

Please sign in to comment.