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

Fix dirty bits in upper bits in implementation address in Clones.sol #5069

Merged
merged 7 commits into from
Jun 14, 2024
Merged
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions test/proxy/Clones.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ contract ClonesTest is Test {
assertEq(spillage, bytes32(0));
}

function testCloneDirty() external {
function testCloneDirty(address caller) external {
vm.startPrank(caller);
ernestognw marked this conversation as resolved.
Show resolved Hide resolved
address cloneClean = Clones.clone(address(this));
address cloneDirty = Clones.clone(_dirty(address(this)));
vm.stopPrank();

// both clones have the same code
assertEq(keccak256(cloneClean.code), keccak256(cloneDirty.code));
Expand All @@ -32,9 +34,9 @@ contract ClonesTest is Test {
assertEq(ClonesTest(cloneDirty).getNumber(), this.getNumber());
}

function testCloneDeterministicDirty() external {
address cloneClean = Clones.cloneDeterministic(address(this), bytes32(block.prevrandao));
address cloneDirty = Clones.cloneDeterministic(_dirty(address(this)), bytes32(~block.prevrandao));
function testCloneDeterministicDirty(bytes32 salt) external {
address cloneClean = Clones.cloneDeterministic(address(this), salt);
address cloneDirty = Clones.cloneDeterministic(_dirty(address(this)), ~salt);

// both clones have the same code
assertEq(keccak256(cloneClean.code), keccak256(cloneDirty.code));
Expand All @@ -53,7 +55,7 @@ contract ClonesTest is Test {
}

function _dirty(address input) private pure returns (address output) {
assembly {
assembly ("memory-safe") {
output := or(input, shl(160, not(0)))
}
}
Expand Down