Skip to content

Commit

Permalink
fix: better way to deploy with factory explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Burtsevych committed Jan 3, 2025
1 parent 6eb57a7 commit 9353ebe
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions zksync/src/contracts/utils/ScriptUtilsZkSync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,22 @@ import {ICreate2Factory} from './interfaces/ICreate2Factory.sol';
* use the Create2Factory contract from the era-contracts repository. When using the Create2Factory to deploy a smart contract with
* a deterministic address, you need to provide not the contract creation code, but the hash of the contract bytecode.
* Then zkSync tries to match the provided bytecode hash with contracts that already exist on the network. If it finds one,
* the contract will be deployed. These utils use the Create2Factory contract, so before trying to deploy a contract with a
* deterministic address, you first need to deploy it at a random address to let zkSync remember its bytecode.
* the contract will be deployed.
* So if you deploy the contract that already exists in zksync network, you simply need to call the
* deploy function with a valid bytecode hash(check below). Otherwise, consider using the factory method. You'll need to write
* a factory contract like this:
*
* contract Factory {
* address public immutable IMPL;
*
* constructor(bytes32 salt, bytes memory arguments) {
* IMPL = Create2UtilsZkSync.create2Deploy(type(Contract).creationCode, arguments);
* }
* }
*
* This approach will force foundry-zksync to create EIP-712 transaction and pass your contract's full bytecode
* in `factory_deps` field of the transaction. It can be handled by zksync network and you'll be able to
* deploy contract in deterministic address even if it wasn't deployed before.
* @dev This library uses the contract's creation code to compute the bytecode hash.
* You can get the creation code using `type(Contract).creationCode`.
* IMPORTANT: There might be a bug while compiling and executing tests or scripts with the --zksync flag.
Expand Down

0 comments on commit 9353ebe

Please sign in to comment.