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

Clean up clone3 return value #23

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ClonesWithImmutableArgs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ library ClonesWithImmutableArgs {
// Nonce of the proxy contract (1).
mstore8(0x34, 0x01)

deployed := keccak256(0x1e, 0x17)
deployed := and(keccak256(0x1e, 0x17), 0xffffffffffffffffffffffffffffffffffffffff)

// If the `call` fails or the code size of `deployed` is zero, revert.
// The second argument of the or() call is evaluated first, which is important
Expand Down Expand Up @@ -480,7 +480,7 @@ library ClonesWithImmutableArgs {
// Nonce of the proxy contract (1).
mstore8(0x34, 0x01)

deployed := keccak256(0x1e, 0x17)
deployed := and(keccak256(0x1e, 0x17), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
}
42 changes: 42 additions & 0 deletions src/test/ClonesWithImmutableArgs.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: BSD
pragma solidity ^0.8.4;

import {DSTest} from "ds-test/test.sol";

import {ClonesWithImmutableArgs} from "../ClonesWithImmutableArgs.sol";
import {ExampleClone} from "../ExampleClone.sol";

contract ClonesWithImmutableArgsTest is DSTest {
/// -----------------------------------------------------------------------
/// Correctness tests
/// -----------------------------------------------------------------------
function testCorrectness_addressOfClone3CleanAddress(bytes32 salt) public {
uint256 remainderMask = ~(uint256(type(uint160).max));
address predicted = ClonesWithImmutableArgs.addressOfClone3(salt);

uint256 remainder;
assembly ("memory-safe") {
remainder := and(predicted, remainderMask)
}
assertEq(remainder, 0);
}

function testCorrectness_clone3CleanAddress(
address param1,
uint256 param2,
uint64 param3,
uint8 param4,
bytes32 salt
) public {
address implementation = address(new ExampleClone());
uint256 remainderMask = ~(uint256(type(uint160).max));
bytes memory data = abi.encodePacked(param1, param2, param3, param4);
address clone = ClonesWithImmutableArgs.clone3(implementation, data, salt, 0);

uint256 remainder;
assembly ("memory-safe") {
remainder := and(clone, remainderMask)
}
assertEq(remainder, 0);
}
}
Loading