Skip to content

Commit

Permalink
revert if account is already created for salt (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeexcoin authored Jan 8, 2025
1 parent 418429b commit 82f48c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions contracts/AccountFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ contract AccountFactory is Ownable2Step {
bytes32 salt,
bytes calldata initializer
) external payable returns (address accountAddress) {
if (saltToAccount[salt] != address(0)) {
revert Errors.ALREADY_CREATED();
}
// Check that the initializer is not empty
if (initializer.length < 4) {
revert Errors.INVALID_INITIALIZER();
Expand Down
5 changes: 3 additions & 2 deletions contracts/libraries/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ library Errors {

error DEPLOYMENT_FAILED(); // 0x0f02d218
error INITIALIZATION_FAILED(); // 0x5b101091
error INVALID_INITIALIZER();
error INVALID_SALT();
error INVALID_INITIALIZER(); // 0x350366d7
error INVALID_SALT(); // 0x8b3152e6
error ALREADY_CREATED(); // 0x26ebf2e8

/*//////////////////////////////////////////////////////////////
PAYMASTER
Expand Down
16 changes: 13 additions & 3 deletions test/deployments/deployer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { expect } from 'chai';
import type { ec } from 'elliptic';
import type { BytesLike, HDNodeWallet } from 'ethers';
import { getAddress, hexlify, parseEther, randomBytes } from 'ethers';
import { getAddress, hexlify, keccak256, parseEther, randomBytes } from 'ethers';
import * as hre from 'hardhat';
import type { Contract, Wallet } from 'zksync-ethers';
import { Provider } from 'zksync-ethers';
Expand Down Expand Up @@ -109,12 +109,22 @@ describe('AGW Contracts - Deployer class tests', () => {
});

it('should not deploy an account with an empty initializer', async () => {
await expect(deployer.account(wallet, factory, eoaValidator, { initializer: '0x' }))
const pk = randomBytes(32);
const wallet = getWallet(hre, hexlify(pk));
await expect(deployer.account(wallet, factory, eoaValidator, {
salt: keccak256(wallet.address),
initializer: '0x'
}))
.to.be.revertedWithCustomError(factory, "INVALID_INITIALIZER");
});

it('should not deploy an account with an invalid initializer selector', async () => {
await expect(deployer.account(wallet, factory, eoaValidator, { initializer: '0xabababab' }))
const pk = randomBytes(32);
const wallet = getWallet(hre, hexlify(pk));
await expect(deployer.account(wallet, factory, eoaValidator, {
salt: keccak256(wallet.address),
initializer: '0xabababab'
}))
.to.be.revertedWithCustomError(factory, "INVALID_INITIALIZER");
});

Expand Down

0 comments on commit 82f48c7

Please sign in to comment.