Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert if account is already created for salt #12

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading