Skip to content

Commit

Permalink
feat: update initcode hash script to only give hashes for correct con…
Browse files Browse the repository at this point in the history
…tracts
  • Loading branch information
adamegyed committed Dec 14, 2024
1 parent fa10db5 commit 899c959
Showing 1 changed file with 73 additions and 36 deletions.
109 changes: 73 additions & 36 deletions script/GetInitcodeHash.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,90 @@ import {ScriptBase} from "./ScriptBase.sol";
// - AccountFactory

contract GetInitcodeHashScript is ScriptBase, Artifacts {
function run() public view onlyProfile("optimized-build") {
console.log("******** Calculating Initcode Hashes *********");
function run() public view {
string memory actualProfile = vm.envOr(string("FOUNDRY_PROFILE"), string(""));

console.log("Artifact initcode hashes with no dependencies:");
console.log("- AllowlistModule: %x", uint256(keccak256(_getAllowlistModuleInitcode())));
console.log("- ExecutionInstallDelegate: %x", uint256(keccak256(_getExecutionInstallDelegateInitcode())));
console.log("- NativeTokenLimitModule: %x", uint256(keccak256(_getNativeTokenLimitModuleInitcode())));
console.log("- PaymasterGuardModule: %x", uint256(keccak256(_getPaymasterGuardModuleInitcode())));
console.log(
"- SingleSignerValidationModule: %x", uint256(keccak256(_getSingleSignerValidationModuleInitcode()))
);
console.log("- TimeRangeModule: %x", uint256(keccak256(_getTimeRangeModuleInitcode())));
console.log("- WebAuthnValidationModule: %x", uint256(keccak256(_getWebAuthnValidationModuleInitcode())));

console.log("Artifact initcode hashes with dependencies on EntryPoint and ExecutionInstallDelegate:");
IEntryPoint entryPoint = _getEntryPoint();

ExecutionInstallDelegate executionInstallDelegate =
ExecutionInstallDelegate(_getExecutionInstallDelegate());
console.log("******** Calculating Initcode Hashes *********");

if (address(executionInstallDelegate) == address(0)) {
console.log(
"Env Variable 'EXECUTION_INSTALL_DELEGATE' not found or invalid, skipping reporting "
"initcode hashes for ModularAccount, SemiModularAccount7702, SemiModularAccountBytecode, "
"and SemiModularAccountStorageOnly"
);
} else {
console.log("Using user-defined ExecutionInstallDelegate at: %x", address(executionInstallDelegate));
if (keccak256(bytes(actualProfile)) == keccak256(bytes("optimized-build-standalone"))) {
console.log("Running script with the `optimized-build-standalone` profile.");

console.log("Artifact initcode hashes with no dependencies:");
console.log("- AllowlistModule: %x", uint256(keccak256(_getAllowlistModuleInitcode())));
console.log(
"- ModularAccount: %x",
uint256(keccak256(_getModularAccountInitcode(entryPoint, executionInstallDelegate)))
);
console.log(
"- SemiModularAccount7702: %x",
uint256(keccak256(_getSemiModularAccount7702Initcode(entryPoint, executionInstallDelegate)))
"- ExecutionInstallDelegate: %x", uint256(keccak256(_getExecutionInstallDelegateInitcode()))
);
console.log("- NativeTokenLimitModule: %x", uint256(keccak256(_getNativeTokenLimitModuleInitcode())));
console.log("- PaymasterGuardModule: %x", uint256(keccak256(_getPaymasterGuardModuleInitcode())));
console.log(
"- SemiModularAccountBytecode: %x",
uint256(keccak256(_getSemiModularAccountBytecodeInitcode(entryPoint, executionInstallDelegate)))
"- SingleSignerValidationModule: %x",
uint256(keccak256(_getSingleSignerValidationModuleInitcode()))
);
console.log("- TimeRangeModule: %x", uint256(keccak256(_getTimeRangeModuleInitcode())));
console.log(
"- SemiModularAccountStorageOnly: %x",
uint256(keccak256(_getSemiModularAccountStorageOnlyInitcode(entryPoint, executionInstallDelegate)))
"- WebAuthnValidationModule: %x", uint256(keccak256(_getWebAuthnValidationModuleInitcode()))
);

_logFactoryInitcodeHash();
}

if (
keccak256(bytes(actualProfile)) == keccak256(bytes("optimized-build"))
|| keccak256(bytes(actualProfile)) == keccak256(bytes("optimized-build-sma-storage"))
) {
console.log("Artifact initcode hashes with dependencies on EntryPoint and ExecutionInstallDelegate:");
IEntryPoint entryPoint = _getEntryPoint();

ExecutionInstallDelegate executionInstallDelegate =
ExecutionInstallDelegate(_getExecutionInstallDelegate());

if (address(executionInstallDelegate) == address(0)) {
console.log(
"Env Variable 'EXECUTION_INSTALL_DELEGATE' not found or invalid, skipping reporting "
"initcode hashes for ModularAccount, SemiModularAccount7702, SemiModularAccountBytecode, "
"and SemiModularAccountStorageOnly"
);
} else {
console.log(
"Using user-defined ExecutionInstallDelegate at: %x", address(executionInstallDelegate)
);

if (keccak256(bytes(actualProfile)) == keccak256(bytes("optimized-build-sma-storage"))) {
console.log(
"- SemiModularAccountStorageOnly: %x",
uint256(
keccak256(
_getSemiModularAccountStorageOnlyInitcode(entryPoint, executionInstallDelegate)
)
)
);
}

if (keccak256(bytes(actualProfile)) == keccak256(bytes("optimized-build"))) {
console.log(
"- ModularAccount: %x",
uint256(keccak256(_getModularAccountInitcode(entryPoint, executionInstallDelegate)))
);
console.log(
"- SemiModularAccount7702: %x",
uint256(
keccak256(_getSemiModularAccount7702Initcode(entryPoint, executionInstallDelegate))
)
);
console.log(
"- SemiModularAccountBytecode: %x",
uint256(
keccak256(_getSemiModularAccountBytecodeInitcode(entryPoint, executionInstallDelegate))
)
);
}
}
}
}

function _logFactoryInitcodeHash() internal view {
IEntryPoint entryPoint = _getEntryPoint();

console.log(
"Artifact initcode hashes with dependency on EntryPoint, ModularAccount impl, "
"SemiModularAccountBytecode impl, SingleSignerValidationModule, "
Expand Down

0 comments on commit 899c959

Please sign in to comment.