diff --git a/src/utils/LibClone.sol b/src/utils/LibClone.sol index d9f1d0c15..13f4f84bf 100644 --- a/src/utils/LibClone.sol +++ b/src/utils/LibClone.sol @@ -670,7 +670,8 @@ library LibClone { assembly { args := mload(0x40) let n := and(0xffffffffff, sub(extcodesize(instance), 0x2d)) - extcodecopy(instance, add(args, 0x20), add(start, 0x2d), add(n, 0x20)) + let l := sub(n, and(0xffffff, mul(lt(start, n), start))) + extcodecopy(instance, add(args, 0x20), add(start, 0x2d), add(l, 0x20)) mstore(args, mul(sub(n, start), lt(start, n))) // Store the length. mstore(0x40, add(args, add(0x40, mload(args)))) // Allocate memory. } @@ -1144,7 +1145,8 @@ library LibClone { assembly { args := mload(0x40) let n := and(0xffffffffff, sub(extcodesize(instance), 0x3d)) - extcodecopy(instance, add(args, 0x20), add(start, 0x3d), add(n, 0x20)) + let l := sub(n, and(0xffffff, mul(lt(start, n), start))) + extcodecopy(instance, add(args, 0x20), add(start, 0x3d), add(l, 0x20)) mstore(args, mul(sub(n, start), lt(start, n))) // Store the length. mstore(0x40, add(args, add(0x40, mload(args)))) // Allocate memory. } @@ -1644,7 +1646,8 @@ library LibClone { assembly { args := mload(0x40) let n := and(0xffffffffff, sub(extcodesize(instance), 0x52)) - extcodecopy(instance, add(args, 0x20), add(start, 0x52), add(n, 0x20)) + let l := sub(n, and(0xffffff, mul(lt(start, n), start))) + extcodecopy(instance, add(args, 0x20), add(start, 0x52), add(l, 0x20)) mstore(args, mul(sub(n, start), lt(start, n))) // Store the length. mstore(0x40, add(mload(args), add(args, 0x40))) // Allocate memory. } @@ -2239,7 +2242,8 @@ library LibClone { assembly { args := mload(0x40) let n := and(0xffffffffff, sub(extcodesize(instance), 0x52)) - extcodecopy(instance, add(args, 0x20), add(start, 0x52), add(n, 0x20)) + let l := sub(n, and(0xffffff, mul(lt(start, n), start))) + extcodecopy(instance, add(args, 0x20), add(start, 0x52), add(l, 0x20)) mstore(args, mul(sub(n, start), lt(start, n))) // Store the length. mstore(0x40, add(args, add(0x40, mload(args)))) // Allocate memory. } @@ -2741,7 +2745,8 @@ library LibClone { assembly { args := mload(0x40) let n := and(0xffffffffff, sub(extcodesize(instance), 0x57)) - extcodecopy(instance, add(args, 0x20), add(start, 0x57), add(n, 0x20)) + let l := sub(n, and(0xffffff, mul(lt(start, n), start))) + extcodecopy(instance, add(args, 0x20), add(start, 0x57), add(l, 0x20)) mstore(args, mul(sub(n, start), lt(start, n))) // Store the length. mstore(0x40, add(args, add(0x40, mload(args)))) // Allocate memory. } diff --git a/src/utils/SSTORE2.sol b/src/utils/SSTORE2.sol index 2a428922a..1e760b7a2 100644 --- a/src/utils/SSTORE2.sol +++ b/src/utils/SSTORE2.sol @@ -223,7 +223,8 @@ library SSTORE2 { assembly { data := mload(0x40) let n := and(0xffffffffff, sub(extcodesize(pointer), 0x01)) - extcodecopy(pointer, add(data, 0x1f), start, add(n, 0x21)) + let l := sub(n, and(0xffffff, mul(lt(start, n), start))) + extcodecopy(pointer, add(data, 0x1f), start, add(l, 0x21)) mstore(data, mul(sub(n, start), lt(start, n))) // Store the length. mstore(0x40, add(data, add(0x40, mload(data)))) // Allocate memory. } diff --git a/test/DeploylessPredeployQueryer.t.sol b/test/DeploylessPredeployQueryer.t.sol index ce8d7e836..1e6b9affe 100644 --- a/test/DeploylessPredeployQueryer.t.sol +++ b/test/DeploylessPredeployQueryer.t.sol @@ -124,11 +124,13 @@ contract DeploylessPredeployQueryerTest is SoladyTest { } function testTargetGenerate() public { + vm.pauseGasMetering(); Target target = new Target(); for (uint256 i; i < 16; ++i) { bytes memory seed = _randomBytes(); assertEq(target.generate(seed), RandomBytesGeneratorLib.generate(seed)); } + vm.resumeGasMetering(); } function testPredeployQueryer(bytes32 salt) public {