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

Deploy v1 Factory and Implementation #66

Merged
merged 8 commits into from
Apr 23, 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
16 changes: 8 additions & 8 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CoinbaseSmartWalletFactoryTest:test_implementation_returnsExpectedAddress() (gas
CoinbaseSmartWalletFactoryTest:test_initCodeHash() (gas: 7912)
CoinbaseSmartWalletFactoryTest:test_revertsIfNoOwners() (gas: 29232)
ERC1271Test:test_returnsExpectedDomainHashWhenProxy() (gas: 29243)
ERC1271Test:test_static() (gas: 3240637)
ERC1271Test:test_static() (gas: 3247131)
MultiOwnableInitializeTest:testRevertsIfLength32ButLargerThanAddress() (gas: 81111)
MultiOwnableInitializeTest:testRevertsIfLength32NotAddress() (gas: 81092)
MultiOwnableInitializeTest:testRevertsIfLengthNot32Or64() (gas: 103395)
Expand All @@ -45,8 +45,8 @@ TestCanSkipChainIdValidation:test_approvedSelectorsReturnTrue() (gas: 17781)
TestCanSkipChainIdValidation:test_otherSelectorsReturnFalse() (gas: 12579)
TestExecuteWithoutChainIdValidation:testExecute() (gas: 403873)
TestExecuteWithoutChainIdValidation:testExecuteBatch() (gas: 728942)
TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3608152, ~: 3468946)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 50179)
TestExecuteWithoutChainIdValidation:testExecuteBatch(uint256) (runs: 256, μ: 3640157, ~: 3767417)
TestExecuteWithoutChainIdValidation:test__codesize() (gas: 50211)
TestExecuteWithoutChainIdValidation:test_revertsWithReservedNonce() (gas: 81941)
TestExecuteWithoutChainIdValidation:test_reverts_whenCallerNotEntryPoint() (gas: 11031)
TestExecuteWithoutChainIdValidation:test_reverts_whenOneCallReverts() (gas: 467783)
Expand All @@ -55,18 +55,18 @@ TestExecuteWithoutChainIdValidation:test_reverts_whenSelectorNotApproved() (gas:
TestExecuteWithoutChainIdValidation:test_succeeds_whenSelectorAllowed() (gas: 423963)
TestImplementation:testImplementation() (gas: 12558)
TestInitialize:testInitialize() (gas: 21012)
TestInitialize:test_cannotInitImplementation() (gas: 2889926)
TestInitialize:test_cannotInitImplementation() (gas: 2896342)
TestIsValidSignature:testReturnsInvalidIfPasskeySigButWrongOwnerLength() (gas: 40165)
TestIsValidSignature:testRevertsIfEthereumSignatureButWrongOwnerLength() (gas: 24018)
TestIsValidSignature:testRevertsIfOwnerIsInvalidEthereumAddress() (gas: 21999)
TestIsValidSignature:testSmartWalletSigner() (gas: 3171533)
TestIsValidSignature:testSmartWalletSigner() (gas: 3177948)
TestIsValidSignature:testValidateSignatureWithEOASigner() (gas: 24900)
TestIsValidSignature:testValidateSignatureWithEOASignerFailsWithWrongSigner() (gas: 23855)
TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 423216)
TestIsValidSignature:testValidateSignatureWithPasskeySigner() (gas: 423221)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsBadOwnerIndex() (gas: 35642)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 430682)
TestIsValidSignature:testValidateSignatureWithPasskeySignerFailsWithWrongBadSignature() (gas: 430687)
TestUpgradeToAndCall:testUpgradeToAndCall() (gas: 25499)
TestValidateUserOp:test_reverts_whenReplayableNonceKeyInvalidForSelector() (gas: 14211)
TestValidateUserOp:test_reverts_whenSelectorInvalidForReplayableNonceKey() (gas: 14476)
TestValidateUserOp:test_succeedsWithEOASigner() (gas: 448010)
TestValidateUserOp:test_succeedsWithPasskeySigner() (gas: 785193)
TestValidateUserOp:test_succeedsWithPasskeySigner() (gas: 785198)
3 changes: 2 additions & 1 deletion .github/workflows/certora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ jobs:
max-parallel: 4
matrix:
params:
- {name: ERC4337Account, command: 'ERC4337Account.conf'}
- {name: ERC4337Account, command: 'ERC4337Account.conf --rule cantInitTwice'}
- {name: ERC4337Account, command: 'ERC4337Account.conf --exclude_rule cantInitTwice'}
- {name: ERC4337AccountInv, command: 'ERC4337AccountInv.conf'}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Check snapshot
run: |
forge snapshot --check
forge snapshot --check --tolerance 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's find a better fix later for noisy fuzz tests

id: snapshot

forge-coverage:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ out/
/broadcast/*/31337/
/broadcast/**/dry-run/

/broadcast
/broadcast/DeployERC4337Factory.s.sol

# Docs
docs/
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
[submodule "lib/account-abstraction"]
path = lib/account-abstraction
url = https://github.com/eth-infinitism/account-abstraction
[submodule "lib/FreshCryptoLib"]
path = lib/FreshCryptoLib
url = https://github.com/rdubois-crypto/FreshCryptoLib
[submodule "lib/solady"]
path = lib/solady
url = https://github.com/vectorized/solady
Expand All @@ -19,3 +16,6 @@
[submodule "lib/webauthn-sol"]
path = lib/webauthn-sol
url = https://github.com/base-org/webauthn-sol
[submodule "lib/safe-singleton-deployer-sol"]
path = lib/safe-singleton-deployer-sol
url = https://github.com/wilsoncusack/safe-singleton-deployer-sol
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ Today, allowed are
- UUPSUpgradeable.upgradeToAndCall

## Deployments

| Network | CoinbaseSmartWalletFactory Address |
Factory and implementation are deployed via [Safe Singleton Factory](https://github.com/safe-global/safe-singleton-factory), which today will give the same address across 248 chains. See "Deploying" below for instructions on how to deploy to new chains.
| Version | Factory Address |
|-----------|-----------------------------------------|
| Base Sepolia | [0xeD4EAeBDBBA52DBB37259a2b75AbB87abF3a19E8](https://sepolia.basescan.org/address/0xeD4EAeBDBBA52DBB37259a2b75AbB87abF3a19E8) |
| 1 | [0x0BA5ED0c6AA8c49038F819E587E2633c4A9F428a](https://basescan.org/address/0x0BA5ED0c6AA8c49038F819E587E2633c4A9F428a) |


## Developing
Expand All @@ -94,5 +94,18 @@ After cloning the repo, run the tests using Forge, from [Foundry](https://github
forge test
```

## Deploying
To deploy on a new chain, in your `.env` set
```bash
FOUNDRY_PROFILE=deploy
```

Then run
```
forge script script/DeployFactory.s.sol --rpc-url https://...
```

As written, the script uses a private key that is loaded from env (`PRIVATE_KEY`). However the deployer can configure the deploy key as they wish, see [here](https://book.getfoundry.sh/reference/forge/forge-script?highlight=script#wallet-options---keystore).

## Influences
Much of the code in this repository started from Solady's [ERC4337](https://github.com/Vectorized/solady/blob/main/src/accounts/ERC4337.sol) implementation. We were also influenced by [DaimoAccount](https://github.com/daimo-eth/daimo/blob/master/packages/contract/src/DaimoAccount.sol), which pioneered using passkey signers on ERC-4337 accounts, and [LightAccount](https://github.com/alchemyplatform/light-account).
113 changes: 113 additions & 0 deletions broadcast/DeployFactory.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions broadcast/DeployFactory.s.sol/8453/run-1713818220.json

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions broadcast/DeployFactory.s.sol/8453/run-latest.json

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions broadcast/DeployFactory.s.sol/84532/run-1713816554.json

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions broadcast/DeployFactory.s.sol/84532/run-latest.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion certora/confs/ERC4337Account.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"packages": [
"solady=lib/solady/src",
"account-abstraction=lib/account-abstraction/contracts",
"FreshCryptoLib=lib/FreshCryptoLib/solidity/src",
"webauthn-sol=lib/webauthn-sol/src",
"FreshCryptoLib/=lib/webauthn-sol/lib/FreshCryptoLib/solidity/src/",
"openzeppelin-contracts=lib/openzeppelin-contracts"
],
"prover_args": [
Expand Down
2 changes: 1 addition & 1 deletion certora/confs/ERC4337AccountInv.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"packages": [
"solady=lib/solady/src",
"account-abstraction=lib/account-abstraction/contracts",
"FreshCryptoLib=lib/FreshCryptoLib/solidity/src",
"webauthn-sol=lib/webauthn-sol/src",
"FreshCryptoLib/=lib/webauthn-sol/lib/FreshCryptoLib/solidity/src/",
"openzeppelin-contracts=lib/openzeppelin-contracts"
],
"prover_args": [
Expand Down
6 changes: 4 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ src = "src"
out = "out"
libs = ["lib"]

[profile.deploy]
optimizer = true
optimizer_runs = 999999

[fmt]
sort_imports = true
wrap_comments = true

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
1 change: 0 additions & 1 deletion lib/FreshCryptoLib
Submodule FreshCryptoLib deleted from d9bb3b
1 change: 1 addition & 0 deletions lib/safe-singleton-deployer-sol
10 changes: 0 additions & 10 deletions remappings.txt

This file was deleted.

21 changes: 0 additions & 21 deletions script/DeployERC4337Factory.s.sol

This file was deleted.

33 changes: 33 additions & 0 deletions script/DeployFactory.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import {Script, console2} from "forge-std/Script.sol";
import {SafeSingletonDeployer} from "safe-singleton-deployer-sol/src/SafeSingletonDeployer.sol";

import {CoinbaseSmartWallet, CoinbaseSmartWalletFactory} from "../src/CoinbaseSmartWalletFactory.sol";

contract DeployFactoryScript is Script {
address constant EXPECTED_IMPLEMENTATION = 0x000100abaad02f1cfC8Bbe32bD5a564817339E72;
address constant EXPECTED_FACTORY = 0x0BA5ED0c6AA8c49038F819E587E2633c4A9F428a;

function run() public {
console2.log("Deploying on chain ID", block.chainid);
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address implementation = SafeSingletonDeployer.broadcastDeploy({
deployerPrivateKey: deployerPrivateKey,
creationCode: type(CoinbaseSmartWallet).creationCode,
args: "",
salt: 0x3438ae5ce1ff7750c1e09c4b28e2a04525da412f91561eb5b57729977f591fbb
});
console2.log("implementation", implementation);
assert(implementation == EXPECTED_IMPLEMENTATION);
address factory = SafeSingletonDeployer.broadcastDeploy({
deployerPrivateKey: deployerPrivateKey,
creationCode: type(CoinbaseSmartWalletFactory).creationCode,
args: abi.encode(implementation),
salt: 0x278d06dab87f67bb2d83470a70c8975a2c99872f290058fb43bcc47da5f0390c
});
console2.log("factory", factory);
assert(factory == EXPECTED_FACTORY);
}
}
Loading