Skip to content

Commit

Permalink
apply updates from upstream PR wighawag#14 (h/t saw-mon & natalie)
Browse files Browse the repository at this point in the history
  • Loading branch information
wminshew committed Aug 12, 2022
1 parent e966c51 commit b58847d
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 144 deletions.
25 changes: 13 additions & 12 deletions src/Clone.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
pragma solidity ^0.8.4;

/// @title Clone
/// @author zefram.eth
/// @author zefram.eth, Saw-mon & Natalie
/// @notice Provides helper functions for reading immutable args from calldata
contract Clone {
uint256 private constant ONE_WORD = 0x20;

/// @notice Reads an immutable arg with type address
/// @param argOffset The offset of the arg in the packed data
/// @return arg The arg value
Expand Down Expand Up @@ -44,17 +46,18 @@ contract Clone {
pure
returns (uint256[] memory arr)
{
uint256 offset = _getImmutableArgsOffset();
uint256 el;
uint256 offset = _getImmutableArgsOffset() + argOffset;
arr = new uint256[](arrLen);
for (uint64 i = 0; i < arrLen; i++) {
// solhint-disable-next-line no-inline-assembly
assembly {
el := calldataload(add(add(offset, argOffset), mul(i, 32)))
// solhint-disable-next-line no-inline-assembly
assembly {
let i
arrLen := mul(arrLen, ONE_WORD)
for {} lt(i, arrLen) {} {
let j := add(i, ONE_WORD)
mstore(add(arr, j), calldataload(add(offset, i)))
i := j
}
arr[i] = el;
}
return arr;
}

/// @notice Reads an immutable arg with type uint64
Expand Down Expand Up @@ -92,9 +95,7 @@ contract Clone {
// solhint-disable-next-line no-inline-assembly
assembly {
offset :=
sub(
calldatasize(), add(shr(240, calldataload(sub(calldatasize(), 2))), 2)
)
sub(calldatasize(), shr(240, calldataload(sub(calldatasize(), 2))))
}
}
}
Loading

0 comments on commit b58847d

Please sign in to comment.