Skip to content

Commit

Permalink
factory update (#7)
Browse files Browse the repository at this point in the history
* factory update

* fix test
  • Loading branch information
coffeexcoin authored Jan 2, 2025
1 parent 6a5642f commit 1aeeaac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
29 changes: 5 additions & 24 deletions contracts/AccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.17;
import {DEPLOYER_SYSTEM_CONTRACT, IContractDeployer} from '@matterlabs/zksync-contracts/l2/system-contracts/Constants.sol';
import {SystemContractsCaller} from '@matterlabs/zksync-contracts/l2/system-contracts/libraries/SystemContractsCaller.sol';
import {Ownable, Ownable2Step} from '@openzeppelin/contracts/access/Ownable2Step.sol';

import {EfficientCall} from '@matterlabs/zksync-contracts/l2/system-contracts/libraries/EfficientCall.sol';
import {Errors} from './libraries/Errors.sol';
import {IAGWRegistry} from './interfaces/IAGWRegistry.sol';

Expand Down Expand Up @@ -91,18 +91,15 @@ contract AccountFactory is Ownable2Step {
*/
function deployAccount(
bytes32 salt,
bytes memory initializer
bytes calldata initializer
) external payable returns (address accountAddress) {
// Check that the initializer is not empty
if (initializer.length < 4) {
revert Errors.INVALID_INITIALIZER();
}
// Check that the initializer selector is correct
{
bytes4 selector;
assembly ('memory-safe') {
selector := mload(add(initializer, 0x20))
}
bytes4 selector = bytes4(initializer[0:4]);
if (selector != initializerSelector) {
revert Errors.INVALID_INITIALIZER();
}
Expand Down Expand Up @@ -132,24 +129,8 @@ contract AccountFactory is Ownable2Step {
// Store the deployer of the account
accountToDeployer[accountAddress] = msg.sender;

// Initialize the account
bool initializeSuccess;

assembly ('memory-safe') {
initializeSuccess := call(
gas(),
accountAddress,
callvalue(),
add(initializer, 0x20),
mload(initializer),
0,
0
)
}

if (!initializeSuccess) {
revert Errors.INITIALIZATION_FAILED();
}
// This propagates the revert if the initialization fails
EfficientCall.call(gasleft(), accountAddress, msg.value, initializer, false);

IAGWRegistry(registry).register(accountAddress);

Expand Down
2 changes: 1 addition & 1 deletion test/deployments/deployer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('AGW Contracts - Deployer class tests', () => {
it('should not deploy an account with an invalid salt', async () => {
const salt = randomBytes(32);
await expect(deployer.account(wallet, factory, eoaValidator, { salt: hexlify(salt) }))
.to.be.revertedWithCustomError(factory, "INITIALIZATION_FAILED");
.to.be.revertedWithCustomError(account, "INVALID_SALT");
});

it('should not deploy an account with an empty initializer', async () => {
Expand Down

0 comments on commit 1aeeaac

Please sign in to comment.