Skip to content

Commit

Permalink
feat: prediction script computes dependencies on the fly, using compu…
Browse files Browse the repository at this point in the history
…ted values
  • Loading branch information
Zer0dot committed Dec 12, 2024
1 parent 48c4a95 commit 42a60b3
Showing 1 changed file with 87 additions and 39 deletions.
126 changes: 87 additions & 39 deletions script/PredictAddresses.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ contract PredictAddressScript is ScriptBase, Artifacts {
// Load the env vars for the account implementations and the factory.
entryPoint = _getEntryPoint();
executionInstallDelegate = ExecutionInstallDelegate(_getExecutionInstallDelegate());

modularAccountImpl = _getModularAccountImpl();
semiModularAccountBytecodeImpl = _getSemiModularAccountBytecodeImpl();
singleSignerValidationModule = _getSingleSignerValidationModule();
Expand All @@ -68,7 +69,7 @@ contract PredictAddressScript is ScriptBase, Artifacts {
}

function run() public view onlyProfile("optimized-build") {
console.log("******** Logging Expected Addresses With Env Salts *********");
console.log("#******** Logging Expected Addresses With Env Salts *********");

console.log(
"ALLOWLIST_MODULE=",
Expand All @@ -93,14 +94,13 @@ contract PredictAddressScript is ScriptBase, Artifacts {
)
);

console.log(
"SINGLE_SIGNER_VALIDATION_MODULE=",
Create2.computeAddress(
bytes32(singleSignerValidationModuleSalt),
keccak256(_getSingleSignerValidationModuleInitcode()),
CREATE2_FACTORY
)
// Needed for factory.
address computedSingleSignerValidationModule = Create2.computeAddress(
bytes32(singleSignerValidationModuleSalt),
keccak256(_getSingleSignerValidationModuleInitcode()),
CREATE2_FACTORY
);
console.log("SINGLE_SIGNER_VALIDATION_MODULE=", computedSingleSignerValidationModule);

console.log(
"TIME_RANGE_MODULE=",
Expand All @@ -109,67 +109,115 @@ contract PredictAddressScript is ScriptBase, Artifacts {
)
);

console.log(
"WEBAUTHN_VALIDATION_MODULE=",
Create2.computeAddress(
bytes32(webAuthnValidationModuleSalt),
keccak256(_getWebAuthnValidationModuleInitcode()),
CREATE2_FACTORY
)
address computedWebauthValidationModule = Create2.computeAddress(
bytes32(webAuthnValidationModuleSalt),
keccak256(_getWebAuthnValidationModuleInitcode()),
CREATE2_FACTORY
);
console.log("WEBAUTHN_VALIDATION_MODULE=", computedWebauthValidationModule);

console.log("");
console.log("******** Logging Expected Account Impl Addresses With Env Salt And Env Addresses *********");
console.log("#******** Logging Expected Account Impl Addresses With Env Salt And Env Addresses *********");

console.log(
"EXECUTION_INSTALL_DELEGATE=",
// Needed for accounts.
ExecutionInstallDelegate computedExecutionInstallDelegate = ExecutionInstallDelegate(
Create2.computeAddress(
bytes32(executionInstallDelegateSalt),
keccak256(_getExecutionInstallDelegateInitcode()),
CREATE2_FACTORY
)
);

console.log(
"MODULAR_ACCOUNT_IMPL=",
Create2.computeAddress(
bytes32(modularAccountImplSalt),
keccak256(_getModularAccountInitcode(entryPoint, executionInstallDelegate)),
CREATE2_FACTORY
)
console.log("EXECUTION_INSTALL_DELEGATE=", address(computedExecutionInstallDelegate));

if (computedExecutionInstallDelegate != executionInstallDelegate) {
console.log(
"# Create2 computed ExecutionInstallDelegate: %s differs from env: %s, proceeding with"
"computed value for account computations.",
address(computedExecutionInstallDelegate),
address(executionInstallDelegate)
);
}

// Needed for factory.
address computedModularAccountImpl = Create2.computeAddress(
bytes32(modularAccountImplSalt),
keccak256(_getModularAccountInitcode(entryPoint, computedExecutionInstallDelegate)),
CREATE2_FACTORY
);
console.log("MODULAR_ACCOUNT_IMPL=", computedModularAccountImpl);

console.log(
"SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL=",
Create2.computeAddress(
bytes32(semiModularAccountBytecodeImplSalt),
keccak256(_getSemiModularAccountBytecodeInitcode(entryPoint, executionInstallDelegate)),
CREATE2_FACTORY
)
// Needed for factory.
address computedSemiModularAccountBytecodeImpl = Create2.computeAddress(
bytes32(semiModularAccountBytecodeImplSalt),
keccak256(_getSemiModularAccountBytecodeInitcode(entryPoint, computedExecutionInstallDelegate)),
CREATE2_FACTORY
);
console.log("SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL=", computedSemiModularAccountBytecodeImpl);

console.log(
"SEMI_MODULAR_ACCOUNT_STORAGE_ONLY_IMPL=",
Create2.computeAddress(
bytes32(semiModularAccountStorageOnlyImplSalt),
keccak256(_getSemiModularAccountStorageOnlyInitcode(entryPoint, executionInstallDelegate)),
keccak256(_getSemiModularAccountStorageOnlyInitcode(entryPoint, computedExecutionInstallDelegate)),
CREATE2_FACTORY
)
);

// Now, we check all factory dependencies and log if they differ from the environment variables.
console.log("");
console.log("******** Logging Expected Factory Address With Env Salt And Env Addresses *********");

if (computedModularAccountImpl != modularAccountImpl) {
console.log(
"# Create2 computed ModularAccountImpl: %s differs from env: %s,"
" proceeding with computed value for Factory computation.",
computedModularAccountImpl,
modularAccountImpl
);
}

if (computedSemiModularAccountBytecodeImpl != semiModularAccountBytecodeImpl) {
console.log(
"# Create2 computed SemiModularAccountBytecodeImpl: %s differs from env: %s,"
" proceeding with computed value for Factory computation.",
computedSemiModularAccountBytecodeImpl,
semiModularAccountBytecodeImpl
);
}

if (computedSingleSignerValidationModule != singleSignerValidationModule) {
console.log(
"# Create2 computed SingleSignerValidationModule: %s differs from env: %s,"
" proceeding with computed value for Factory computation.",
computedSingleSignerValidationModule,
singleSignerValidationModule
);
}

if (computedWebauthValidationModule != webAuthnValidationModule) {
console.log(
"# Create2 computed WebAuthnValidationModule: %s differs from env: %s,"
" proceeding with computed value for Factory computation.",
computedWebauthValidationModule,
webAuthnValidationModule
);
}

if (factoryOwner == address(0)) {
console.log("# WARNING: ACCOUNT_FACTORY_OWNER is set to zero, this factory will have no owner!");
}

console.log("#******** Logging Expected Factory Address With Env Salt And Env Addresses *********");
console.log(
"ACCOUNT_FACTORY=",
Create2.computeAddress(
bytes32(factorySalt),
keccak256(
_getAccountFactoryInitcode(
entryPoint,
ModularAccount(payable(modularAccountImpl)),
SemiModularAccountBytecode(payable(semiModularAccountBytecodeImpl)),
singleSignerValidationModule,
webAuthnValidationModule,
ModularAccount(payable(computedModularAccountImpl)),
SemiModularAccountBytecode(payable(computedSemiModularAccountBytecodeImpl)),
computedSingleSignerValidationModule,
computedWebauthValidationModule,
factoryOwner
)
),
Expand Down

0 comments on commit 42a60b3

Please sign in to comment.