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

feat: specialize deploy scripts per artifact #324

Merged
merged 4 commits into from
Dec 14, 2024
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
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ENTRYPOINT=

# AccountFactory's initial owner
FACTORY_OWNER=
ACCOUNT_FACTORY_OWNER=

# Expected addresses

Expand All @@ -17,7 +17,7 @@ WEBAUTHN_VALIDATION_MODULE=
MODULAR_ACCOUNT_IMPL=
SEMI_MODULAR_ACCOUNT_7702_IMPL=
SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL=
SEMI_MODULAR_ACCOUNT_STORAGEONLY_IMPL=
SEMI_MODULAR_ACCOUNT_STORAGE_ONLY_IMPL=

ACCOUNT_FACTORY=

Expand All @@ -40,7 +40,7 @@ ACCOUNT_FACTORY_SALT=

# Factory staking setup

# 1 ether required by bundlers
REQUIRED_STAKE_AMOUNT=1
# 0.1 ether required by bundlers
REQUIRED_STAKE_AMOUNT_WEI=100000000000000000
# 1 day required by bundlers
UNSTAKE_DELAY_SEC=86400
4 changes: 2 additions & 2 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: |
{
echo 'NEWSIZES<<EOF'
FOUNDRY_PROFILE=optimized-build forge b --sizes | grep '^|' | grep -v -e '| 17 |' -e 'Lib'
FOUNDRY_PROFILE=optimized-build forge b --sizes | grep '^|' | grep -v -e '| 17 |' -e 'Lib'
echo EOF
} >> "$GITHUB_OUTPUT"

Expand All @@ -60,7 +60,7 @@ jobs:
run: |
{
echo 'OLDSIZES<<EOF'
FOUNDRY_PROFILE=optimized-build forge b --sizes | grep '^|' | grep -v -e '| 17 |' -e 'Lib'
FOUNDRY_PROFILE=optimized-build forge b --sizes | grep '^|' | grep -v -e '| 17 |' -e 'Lib'
echo EOF
} >> "$GITHUB_OUTPUT"

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Foundry build and cache directories
out/
out-optimized/
out-optimized-standalone/
out-optimized-sma-storage/
cache/
cache-optimized/
cache-optimized-standalone/
cache-optimized-sma-storage/
node_modules/

# Coverage
Expand Down
20 changes: 18 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,26 @@ depth = 10
deny_warnings = true
via_ir = true
test = 'src'
optimizer_runs = 15000
optimizer_runs = 50000
out = 'out-optimized'
cache_path = 'cache-optimized'

[profile.optimized-build-standalone]
deny_warnings = true
via_ir = true
test = 'src'
optimizer_runs = 10_000_000_000
out = 'out-optimized-standalone'
cache_path = 'cache-optimized-standalone'

[profile.optimized-build-sma-storage]
deny_warnings = true
via_ir = true
test = 'src'
optimizer_runs = 15000
out = 'out-optimized-sma-storage'
cache_path = 'cache-optimized-sma-storage'

[profile.optimized-test]
deny_warnings = true
src = 'test'
Expand All @@ -58,7 +74,7 @@ depth = 32
via_ir = true
deny_warnings = true
test = 'gas'
optimizer_runs = 15000
optimizer_runs = 50000
out = 'out-optimized'
cache_path = 'cache-optimized'
snapshots = 'gas-snapshots'
Expand Down
4 changes: 2 additions & 2 deletions gas-snapshots/LightAccount.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Runtime_AccountCreation": "143836",
"Runtime_Erc20Transfer": "63183",
"Runtime_Erc20Transfer": "63180",
"Runtime_NativeTransfer": "39356",
"UserOp_Erc20Transfer": "172435",
"UserOp_Erc20Transfer": "172432",
"UserOp_NativeTransfer": "148492"
}
28 changes: 14 additions & 14 deletions gas-snapshots/ModularAccount.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"Runtime_AccountCreation": "176256",
"Runtime_BatchTransfers": "92914",
"Runtime_Erc20Transfer": "78346",
"Runtime_InstallSessionKey_Case1": "429647",
"Runtime_NativeTransfer": "54495",
"Runtime_UseSessionKey_Case1_Counter": "78523",
"Runtime_UseSessionKey_Case1_Token": "111836",
"UserOp_BatchTransfers": "197734",
"UserOp_Erc20Transfer": "184708",
"UserOp_InstallSessionKey_Case1": "537327",
"UserOp_NativeTransfer": "160953",
"UserOp_UseSessionKey_Case1_Counter": "194454",
"UserOp_UseSessionKey_Case1_Token": "225438",
"UserOp_deferredValidation": "232882"
"Runtime_AccountCreation": "176235",
"Runtime_BatchTransfers": "92896",
"Runtime_Erc20Transfer": "78331",
"Runtime_InstallSessionKey_Case1": "429572",
"Runtime_NativeTransfer": "54483",
"Runtime_UseSessionKey_Case1_Counter": "78469",
"Runtime_UseSessionKey_Case1_Token": "111779",
"UserOp_BatchTransfers": "197713",
"UserOp_Erc20Transfer": "184690",
"UserOp_InstallSessionKey_Case1": "537249",
"UserOp_NativeTransfer": "160938",
"UserOp_UseSessionKey_Case1_Counter": "194376",
"UserOp_UseSessionKey_Case1_Token": "225357",
"UserOp_deferredValidation": "232843"
}
28 changes: 14 additions & 14 deletions gas-snapshots/SemiModularAccount.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"Runtime_AccountCreation": "97767",
"Runtime_BatchTransfers": "88746",
"Runtime_Erc20Transfer": "74226",
"Runtime_InstallSessionKey_Case1": "427850",
"Runtime_NativeTransfer": "50385",
"Runtime_UseSessionKey_Case1_Counter": "78826",
"Runtime_UseSessionKey_Case1_Token": "112139",
"UserOp_BatchTransfers": "192863",
"UserOp_Erc20Transfer": "179920",
"UserOp_InstallSessionKey_Case1": "534652",
"UserOp_NativeTransfer": "156195",
"UserOp_UseSessionKey_Case1_Counter": "194706",
"UserOp_UseSessionKey_Case1_Token": "225690",
"UserOp_deferredValidation": "228856"
"Runtime_AccountCreation": "97764",
"Runtime_BatchTransfers": "88740",
"Runtime_Erc20Transfer": "74220",
"Runtime_InstallSessionKey_Case1": "427790",
"Runtime_NativeTransfer": "50382",
"Runtime_UseSessionKey_Case1_Counter": "78772",
"Runtime_UseSessionKey_Case1_Token": "112082",
"UserOp_BatchTransfers": "192854",
"UserOp_Erc20Transfer": "179911",
"UserOp_InstallSessionKey_Case1": "534589",
"UserOp_NativeTransfer": "156189",
"UserOp_UseSessionKey_Case1_Counter": "194643",
"UserOp_UseSessionKey_Case1_Token": "225624",
"UserOp_deferredValidation": "228832"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"solhint": "^3.6.2"
},
"scripts": {
"clean": "forge clean && FOUNDRY_PROFILE=optimized-build forge clean",
"clean": "forge clean && FOUNDRY_PROFILE=optimized-build forge clean && FOUNDRY_PROFILE=optimized-build-standalone forge clean",
"coverage": "forge coverage --no-match-coverage '(test)' --nmt '(testFuzz|invariant)'",
"fmt": "forge fmt && FOUNDRY_PROFILE=gas forge fmt",
"fmt:check": "forge fmt --check && FOUNDRY_PROFILE=gas forge fmt --check",
Expand All @@ -25,7 +25,7 @@
"lint:gas": "solhint --max-warnings 0 -c ./config/solhint-gas.json './gas/**/*.sol'",
"lint:script": "solhint --max-warnings 0 -c ./config/solhint-script.json './script/**/*.sol'",
"prep": "pnpm fmt && forge b --deny-warnings && pnpm lint && pnpm test && pnpm gas",
"sizes": "FOUNDRY_PROFILE=optimized-build forge b --sizes | grep '^|' | grep -v -e '| 17 |' -e 'Lib'",
"sizes": "FOUNDRY_PROFILE=optimized-build forge b --sizes | grep '^|' | grep -v -e '| 17 |' -e 'Lib'",
"test": "forge test"
}
}
76 changes: 39 additions & 37 deletions script/DeployAccounts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,39 @@ contract DeployAccountsScript is ScriptBase, Artifacts {

IEntryPoint public entryPoint;

address public expectedExecutionInstallDelegate;
uint256 public executionInstallDelegateSalt;
address public executionInstallDelegate;

address public expectedModularAccountImpl;
uint256 public modularAccountImplSalt;

address public expectedSemiModularAccountBytecodeImpl;
uint256 public semiModularAccountBytecodeImplSalt;

address public expectedSemiModularAccountStorageOnlyImpl;
uint256 public semiModularAccountStorageOnlyImplSalt;
address public expectedSemiModularAccount7702Impl;
uint256 public semiModularAccount7702ImplSalt;

function setUp() public {
// Load the required addresses for the deployment from env vars.
entryPoint = _getEntryPoint();

expectedExecutionInstallDelegate = _getExecutionInstallDelegate();
executionInstallDelegateSalt = _getSaltOrZero("EXECUTION_INSTALL_DELEGATE");
executionInstallDelegate = _getExecutionInstallDelegate();

expectedModularAccountImpl = _getModularAccountImpl();
modularAccountImplSalt = _getSaltOrZero("MODULAR_ACCOUNT_IMPL");

expectedSemiModularAccountBytecodeImpl = _getSemiModularAccountBytecodeImpl();
semiModularAccountBytecodeImplSalt = _getSaltOrZero("SEMI_MODULAR_ACCOUNT_BYTECODE_IMPL");

expectedSemiModularAccountStorageOnlyImpl = address(_getSemiModularAccountStorageOnlyImpl());
semiModularAccountStorageOnlyImplSalt = _getSaltOrZero("SEMI_MODULAR_ACCOUNT_STORAGE_ONLY_IMPL");
expectedSemiModularAccount7702Impl = _getSemiModularAccount7702Impl();
semiModularAccount7702ImplSalt = _getSaltOrZero("SEMI_MODULAR_ACCOUNT_7702_IMPL");
}

function run() public onlyProfile("optimized-build") {
console.log("******** Deploying Account Implementations and Execution Install Delegate *********");
console.log("******** Deploying Account Implementations *********");

vm.startBroadcast();
_ensureNonzeroArgs();

_safeDeploy(
"Execution Install Delegate",
expectedExecutionInstallDelegate,
executionInstallDelegateSalt,
_getExecutionInstallDelegateInitcode(),
_deployExecutionInstallDelegate
);
vm.startBroadcast();

// At this point, the delegate and entrypoint are valid, so we can safely proceed with
// using them as parameters and accessing them in wrapped functions.
Expand All @@ -65,51 +57,61 @@ contract DeployAccountsScript is ScriptBase, Artifacts {
"Modular Account Impl",
expectedModularAccountImpl,
modularAccountImplSalt,
_getModularAccountInitcode(entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate)),
_getModularAccountInitcode(entryPoint, ExecutionInstallDelegate(executionInstallDelegate)),
_wrappedDeployModularAccount
);

_safeDeploy(
"Semi Modular Account Bytecode Impl",
expectedSemiModularAccountBytecodeImpl,
semiModularAccountBytecodeImplSalt,
_getSemiModularAccountBytecodeInitcode(
entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate)
),
_getSemiModularAccountBytecodeInitcode(entryPoint, ExecutionInstallDelegate(executionInstallDelegate)),
_wrappedDeploySemiModularAccountBytecode
);

_safeDeploy(
"Semi Modular Account Storage Only Impl",
expectedSemiModularAccountStorageOnlyImpl,
semiModularAccountStorageOnlyImplSalt,
_getSemiModularAccountStorageOnlyInitcode(
entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate)
),
_wrappedDeploySemiModularAccountStorageOnly
"Semi Modular Account 7702 Impl",
expectedSemiModularAccount7702Impl,
semiModularAccount7702ImplSalt,
_getSemiModularAccount7702Initcode(entryPoint, ExecutionInstallDelegate(executionInstallDelegate)),
_wrappedDeploySemiModularAccount7702
);

vm.stopBroadcast();

console.log("******** Account Implementations and Execution Install Delegate Deployed *********");
console.log("******** Account Implementations Deployed *********");
}

// These functions wrap the internal deployment functions to provide access to the needed state variables
// without affecting the expected signature from _safeDeploy.

function _wrappedDeployModularAccount(bytes32 salt) internal returns (address) {
return _deployModularAccount(salt, entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate));
return _deployModularAccount(salt, entryPoint, ExecutionInstallDelegate(executionInstallDelegate));
}

function _wrappedDeploySemiModularAccountBytecode(bytes32 salt) internal returns (address) {
return _deploySemiModularAccountBytecode(
salt, entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate)
);
return
_deploySemiModularAccountBytecode(salt, entryPoint, ExecutionInstallDelegate(executionInstallDelegate));
}

function _wrappedDeploySemiModularAccountStorageOnly(bytes32 salt) internal returns (address) {
return _deploySemiModularAccountStorageOnly(
salt, entryPoint, ExecutionInstallDelegate(expectedExecutionInstallDelegate)
);
function _wrappedDeploySemiModularAccount7702(bytes32 salt) internal returns (address) {
return _deploySemiModularAccount7702(salt, entryPoint, ExecutionInstallDelegate(executionInstallDelegate));
}

function _ensureNonzeroArgs() internal view {
bool shouldRevert;

if (address(executionInstallDelegate) == address(0)) {
console.log(
"Env Variable 'EXECUTION_INSTALL_DELEGATE' not found or invalid during accounts deployment."
);
shouldRevert = true;
} else {
console.log("Using user-defined ExecutionInstallDelegate at: %x", executionInstallDelegate);
}

if (shouldRevert) {
revert("Missing or invalid env variables during factory deployment");
}
}
}
2 changes: 1 addition & 1 deletion script/DeployFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract DeployFactoryScript is ScriptBase, Artifacts {
factorySalt = _getSaltOrZero("ACCOUNT_FACTORY");
}

function run() public onlyProfile("optimized-build") {
function run() public onlyProfile("optimized-build-standalone") {
console.log("******** Deploying Factory *********");

vm.startBroadcast();
Expand Down
Loading
Loading