Skip to content

Commit

Permalink
fix: make sure fund specified from args match msg.value (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
chefburger authored Oct 28, 2024
1 parent e7f6e7f commit 959233c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Create3Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract Create3Factory is ICreate3Factory, Ownable2Step, ReentrancyGuard {
uint256 afterDeploymentExecutionFund
) external payable onlyWhitelisted nonReentrant returns (address deployed) {
if (creationCodeHash != keccak256(creationCode)) revert CreationCodeHashMismatch();
if (creationFund + afterDeploymentExecutionFund != msg.value) revert FundsAmountMismatch();

deployed = Create3.create3(
salt, creationCode, creationFund, afterDeploymentExecutionPayload, afterDeploymentExecutionFund
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/ICreate3Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
interface ICreate3Factory {
error NotWhitelisted();
error CreationCodeHashMismatch();
error FundsAmountMismatch();

/**
* @notice create3 deploy a contract
Expand Down
19 changes: 19 additions & 0 deletions test/Create3Factory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ contract Create3FactoryTest is Test, GasSnapshot {
);
}

function test_Deploy_MockOwnerWithConstructorArgs_RevertWithFundsAmountMismatch() public {
// 1. prepare salt and creation code
bytes32 salt = bytes32(uint256(0x1234));
bytes memory creationCode = abi.encodePacked(type(MockOwnerWithConstructorArgs).creationCode, abi.encode(42));

// 2. prepare owner transfer payload
bytes memory afterDeploymentExecutionPayload =
abi.encodeWithSelector(Ownable.transferOwnership.selector, expectedOwner);

// 3. make sure this contract has enough balance
vm.deal(address(this), 1 ether);

// 4. deploy
vm.expectRevert(abi.encodeWithSelector(ICreate3Factory.FundsAmountMismatch.selector));
create3Factory.deploy{value: 1 ether}(
salt, creationCode, keccak256(creationCode), 1 ether, afterDeploymentExecutionPayload, 0.2 ether
);
}

function test_Deploy_MockOwnerWithConstructorArgs_BubbleUpRevert() public {
// 1. prepare salt and creation code
bytes32 salt = bytes32(uint256(0x1234));
Expand Down

0 comments on commit 959233c

Please sign in to comment.