Skip to content

Commit

Permalink
feat: ability for safe deployment of AGW from any address even if it …
Browse files Browse the repository at this point in the history
…is not deployer or initial k1 owner (#4)

* add ability for safe deployment from any address that is not deployer or initial k1 owner

* tests
  • Loading branch information
coffeexcoin authored Dec 23, 2024
1 parent 52742cf commit 6a5642f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
14 changes: 11 additions & 3 deletions contracts/AGWAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ contract AGWAccount is

uint256 public constant VERSION = 1;

address public immutable KNOWN_TRUSTED_EOA_VALIDATOR;

/**
* @notice Constructor for the account implementation
*/
constructor() {
constructor(address knownTrustedEoaValidator) {
KNOWN_TRUSTED_EOA_VALIDATOR = knownTrustedEoaValidator;
_disableInitializers();
}

Expand All @@ -76,14 +79,19 @@ contract AGWAccount is
if (address(this) != expectedAddress) {
revert Errors.INVALID_SALT();
}

// add the initial k1 owner as an owner
_k1AddOwner(initialK1Owner);

address thisDeployer = factory.accountToDeployer(address(this));
if (thisDeployer != factory.deployer()) {
if (initialK1Owner != thisDeployer) {
revert Errors.NOT_FROM_DEPLOYER();
// disregard any modules and initial call as the deployer is untrusted
_k1AddValidator(KNOWN_TRUSTED_EOA_VALIDATOR);
return;
}
}

_k1AddOwner(initialK1Owner);
_k1AddValidator(initialK1Validator);

for (uint256 i = 0; i < modules.length; ) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default async function (): Promise<void> {
implementation = await deployContract(
hre,
'ClaveImplementation',
[await batchCaller.getAddress()],
[await eoaValidator.getAddress()],
{
wallet: fundingWallet,
silent: false,
Expand Down
8 changes: 4 additions & 4 deletions test/utils/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export class ClaveDeployer {
);
}

public async implementation(): Promise<Contract> {
public async implementation(eoaValidator: string): Promise<Contract> {
return await deployContract(
this.hre,
CONTRACT_NAMES.IMPLEMENTATION,
[],
[eoaValidator],
{
wallet: this.deployerWallet,
silent: true,
Expand Down Expand Up @@ -95,13 +95,13 @@ export class ClaveDeployer {
return factory;
}

public async setupFactory(): Promise<{
public async setupFactory(eoaValidator: string): Promise<{
registry: Contract;
implementation: Contract;
factory: Contract;
}> {
const registry = await this.registry();
const implementation = await this.implementation();
const implementation = await this.implementation(eoaValidator);
const factory = await this.factory(implementation, registry);

return { registry, implementation, factory };
Expand Down
4 changes: 2 additions & 2 deletions test/utils/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export const fixture = async (
const wallet = HDNodeWallet.createRandom();

const registry = await deployer.registry();
const implementation = await deployer.implementation();
const factory = await deployer.factory(implementation, registry);
const eoaValidator = await deployer.validator(VALIDATORS.EOA);
const implementation = await deployer.implementation(await eoaValidator.getAddress());
const factory = await deployer.factory(implementation, registry);
const teeValidator = await deployer.validator(VALIDATORS.TEE);
const mockValidator = await deployer.validator(VALIDATORS.MOCK);
const passkeyValidator = await deployer.validator(VALIDATORS.PASSKEY);
Expand Down

0 comments on commit 6a5642f

Please sign in to comment.