Skip to content

Commit

Permalink
chore: update config, validate init code hash
Browse files Browse the repository at this point in the history
  • Loading branch information
howydev committed Oct 3, 2023
1 parent 00fa7ce commit 526f4b1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Foundry build and cache directories
out/
cache/
.env
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ out = 'out'
test = 'test'
libs = ['lib']
optimizer = true
optimizer_runs = 10_000
optimizer_runs = 10_000_000

[fuzz]
runs = 5000
Expand Down
59 changes: 59 additions & 0 deletions script/Deploy_LightAccountFactory.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import "forge-std/Script.sol";

import {IEntryPoint} from "account-abstraction/interfaces/IEntryPoint.sol";

import {LightAccountFactory} from "../src/LightAccountFactory.sol";

// @notice Deploys LightAccountFactory to the address `0x006A000bb900dC0781A5290e210F000000e92200`
// @dev Note: EntryPoint must be at 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789
// @dev To run: `forge script script/Deploy_LightAccountFactory.s.sol:Deploy_LightAccountFactory --broadcast --rpc-url ${RPC_URL} --verify -vvvv`
contract Deploy_LightAccountFactory is Script {
error InitCodeHashMismatch(bytes32 initCodeHash);
error DeployedAddressMismatch(address deployed);

function run() public {
uint256 deployerPrivateKey = uint256(vm.envBytes32("DEPLOYER_PRIVATE_KEY"));

vm.startBroadcast(deployerPrivateKey);

// Using entryPoint: 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789
// Correct as of Oct 3 2023, from https://docs.alchemy.com/reference/eth-supportedentrypoints
IEntryPoint entryPoint = IEntryPoint(payable(0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789));

// Init code hash check
bytes32 initCodeHash = keccak256(
abi.encodePacked(type(LightAccountFactory).creationCode, bytes32(uint256(uint160(address(entryPoint)))))
);

if (initCodeHash != 0x3043a72812fec9b9987853a9b869c1a469dc6e04b0f80da3af2ecb8cf8eed209) {
revert InitCodeHashMismatch(initCodeHash);
}

console.log("********************************");
console.log("******** Deploy Inputs *********");
console.log("********************************");
console.log("Entrypoint Address is:");
console.logAddress(address(entryPoint));
console.log("********************************");
console.log("******** Deploy ...... *********");
console.log("********************************");

LightAccountFactory factory =
new LightAccountFactory{salt: 0x00000000000000000000000000000000000000007845d3459c316000001d6f83}(entryPoint);

// Deployed address check
if (address(factory) != 0x000000893A26168158fbeaDD9335Be5bC96592E2) {
revert DeployedAddressMismatch(address(factory));
}

console.log("LightAccountFactory address:");
console.logAddress(address(factory));

console.log("Implementation address:");
console.logAddress(address(factory.accountImplementation()));
vm.stopBroadcast();
}
}
12 changes: 12 additions & 0 deletions test/LightAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ contract LightAccountTest is Test {
assertEq(initialized, 1);
}

function testValidateInitCodeHash() external {
assertEq(
keccak256(
abi.encodePacked(
type(LightAccountFactory).creationCode,
bytes32(uint256(uint160(0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789)))
)
),
0x3043a72812fec9b9987853a9b869c1a469dc6e04b0f80da3af2ecb8cf8eed209
);
}

function _useContractOwner() internal {
vm.prank(eoaAddress);
account.transferOwnership(address(contractOwner));
Expand Down

0 comments on commit 526f4b1

Please sign in to comment.