Skip to content

Commit

Permalink
refactor: code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Burtsevych committed Dec 23, 2024
1 parent 331e8e2 commit 85754f7
Showing 1 changed file with 2 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity >=0.8.24;

import {TransparentProxyFactoryBase} from '../../../../src/contracts/transparent-proxy/TransparentProxyFactoryBase.sol';
import {ITransparentProxyFactoryZkSync} from './interfaces/ITransparentProxyFactoryZkSync.sol';
import {Create2UtilsZkSync} from '../utils/ScriptUtilsZkSync.sol';

/**
* @title TransparentProxyFactoryZkSync
Expand Down Expand Up @@ -30,31 +31,11 @@ contract TransparentProxyFactoryZkSync is
ZKSYNC_CREATE2_PREFIX,
bytes32(uint256(uint160(sender))),
salt,
bytes32(_sliceBytes(creationCode, 36, 32)),
Create2UtilsZkSync.getBytecodeHashFromBytecode(creationCode),
keccak256(constructorInput)
)
);

return address(uint160(uint256(addressHash)));
}

function _sliceBytes(
bytes memory data,
uint256 start,
uint256 length
) internal pure returns (bytes memory) {
require(start + length <= data.length, 'Slice out of bounds');

bytes memory result = new bytes(length);
assembly {
let dataPtr := add(data, 32)
let resultPtr := add(result, 32)

// Use mcopy to efficiently copy the slice
mcopy(resultPtr, add(dataPtr, start), length)

mstore(result, length)
}
return result;
}
}

0 comments on commit 85754f7

Please sign in to comment.