Unverified Commit 19417c7c by Anton Bukov Committed by GitHub

Rename CREATE2 argument from bytecodeHash to bytecode and add new method for…

Rename CREATE2 argument from bytecodeHash to bytecode and add new method for precomputed bytecode hash (#2087)

* Rename CREATE2 argument from bytecodeHash to bytecode and add new method for precomputed bytecode hash

* Remove only from test

* Fix linter error
parent 5dfe7215
...@@ -20,4 +20,8 @@ contract Create2Impl { ...@@ -20,4 +20,8 @@ contract Create2Impl {
function computeAddress(bytes32 salt, bytes memory code, address deployer) public pure returns (address) { function computeAddress(bytes32 salt, bytes memory code, address deployer) public pure returns (address) {
return Create2.computeAddress(salt, code, deployer); return Create2.computeAddress(salt, code, deployer);
} }
function computeAddress(bytes32 salt, bytes32 codeHash, address deployer) public pure returns (address) {
return Create2.computeAddress(salt, codeHash, deployer);
}
} }
...@@ -39,10 +39,17 @@ library Create2 { ...@@ -39,10 +39,17 @@ library Create2 {
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at * @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}. * `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/ */
function computeAddress(bytes32 salt, bytes memory bytecodeHash, address deployer) internal pure returns (address) { function computeAddress(bytes32 salt, bytes memory bytecode, address deployer) internal pure returns (address) {
bytes32 bytecodeHashHash = keccak256(bytecodeHash); return computeAddress(salt, keccak256(bytecode), deployer);
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address) {
bytes32 _data = keccak256( bytes32 _data = keccak256(
abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHashHash) abi.encodePacked(bytes1(0xff), deployer, salt, bytecodeHash)
); );
return address(bytes20(_data << 96)); return address(bytes20(_data << 96));
} }
......
...@@ -30,7 +30,17 @@ describe('Create2', function () { ...@@ -30,7 +30,17 @@ describe('Create2', function () {
it('should compute the correct contract address with deployer', async function () { it('should compute the correct contract address with deployer', async function () {
const onChainComputed = await this.factory const onChainComputed = await this.factory
.computeAddress(saltHex, constructorByteCode, deployerAccount); .methods['computeAddress(bytes32,bytes,address)'](saltHex, constructorByteCode, deployerAccount);
const offChainComputed =
computeCreate2Address(saltHex, constructorByteCode, deployerAccount);
expect(onChainComputed).to.equal(offChainComputed);
});
it('should compute the correct contract address with deployer and bytecode hash', async function () {
const onChainComputed = await this.factory
.methods['computeAddress(bytes32,bytes32,address)'](
saltHex, web3.utils.keccak256(constructorByteCode), deployerAccount
);
const offChainComputed = const offChainComputed =
computeCreate2Address(saltHex, constructorByteCode, deployerAccount); computeCreate2Address(saltHex, constructorByteCode, deployerAccount);
expect(onChainComputed).to.equal(offChainComputed); expect(onChainComputed).to.equal(offChainComputed);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment