Skip to content

Commit

Permalink
Use Arachnid CREATE2 Deployer For Some Contracts
Browse files Browse the repository at this point in the history
Fixes #481

Some contracts included in our deployment script are expected to use the
Arachnid CREATE deployment proxy instead of the Safe singleton factory.
We change our deployment scripts to manually use the Arachnid
CREATE2 deployer in those specific cases, so the contracts end up at the
expected addresses.

Affected contracts:
- ERC-4337 entry point
- Daimo P-256 verifier
  • Loading branch information
nlordell committed Aug 14, 2024
1 parent b3c5e66 commit 5ae188e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
5 changes: 1 addition & 4 deletions modules/passkey/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ EVM target: Paris

- `SafeWebAuthnSignerFactory` at `0x1d31F259eE307358a26dFb23EB365939E8641195`
- `SafeWebAuthnSharedSigner` at `0x94a4F6affBd8975951142c3999aEAB7ecee555c2`
- `DaimoP256Verifier` at `0xc2b78104907F722DABAc4C69f826a522B2754De4` ([source](https://p256.eth.limo/))
- `FCLP256Verifier` at `0xA86e0054C51E4894D88762a017ECc5E5235f5DBA`

### Official Deployment Address from 3rd party

- `DaimoP256Verifier` at `0xc2b78104907F722DABAc4C69f826a522B2754De4` ([Source](https://p256.eth.limo/))

## Changes

### Security Fixes
Expand Down
35 changes: 27 additions & 8 deletions modules/passkey/src/deploy/verifiers.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import type { HardhatRuntimeEnvironment } from 'hardhat/types'
import type { DeployFunction } from 'hardhat-deploy/types'

import DaimoP256Verifier from '../vendor/daimo-eth/P256Verifier.json'

const deploy: DeployFunction = async ({ deployments, getNamedAccounts }) => {
const deploy: DeployFunction = async (hre) => {
const { deployments, getNamedAccounts } = hre

const { deployer } = await getNamedAccounts()
const { deploy } = deployments

await deploy('DaimoP256Verifier', {
from: deployer,
contract: DaimoP256Verifier,
args: [],
deterministicDeployment: true,
log: true,
})
// The official Daimo P-256 verifier contract is deployed using the Arachnid CREATE2 deployer.
await withArachnidDeterministicDeploymentProxy(hre, () =>
deploy('DaimoP256Verifier', {
from: deployer,
contract: DaimoP256Verifier,
args: [],
deterministicDeployment: true,
log: true,
}),
)

await deploy('FCLP256Verifier', {
from: deployer,
Expand All @@ -22,4 +28,17 @@ const deploy: DeployFunction = async ({ deployments, getNamedAccounts }) => {
})
}

function withArachnidDeterministicDeploymentProxy<T>({ config }: HardhatRuntimeEnvironment, f: () => Promise<T>): Promise<T> {
// This is a bit hacky - but the `hardhat-deploy` package reads that deterministic deployment
// configuration before deploying each contract. This means that we can temporarily override the
// the configuration to `undefined` so that it uses the (default) Arachnid deterministic
// deployment proxy for a specific deployment, and then restore the configuration afterwards so
// that remaining contracts use the deterministic deployment factory from `hardhat.config.ts`.
const existingConfig = config.deterministicDeployment
config.deterministicDeployment = undefined
return f().finally(() => {
config.deterministicDeployment = existingConfig
})
}

export default deploy
34 changes: 26 additions & 8 deletions packages/4337-local-bundler/src/deploy/entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
import EntryPoint from '@account-abstraction/contracts/artifacts/EntryPoint.json'
import { DeployFunction } from 'hardhat-deploy/types'
import type { HardhatRuntimeEnvironment } from 'hardhat/types'
import type { DeployFunction } from 'hardhat-deploy/types'

const deploy: DeployFunction = async ({ deployments, getNamedAccounts, network }) => {
const deploy: DeployFunction = async (hre) => {
const { deployments, getNamedAccounts, network } = hre
if (!network.tags.entrypoint) {
return
}

const { deployer } = await getNamedAccounts()
const { deploy } = deployments

await deploy('EntryPoint', {
from: deployer,
contract: EntryPoint,
args: [],
log: true,
deterministicDeployment: '0x90d8084deab30c2a37c45e8d47f49f2f7965183cb6990a98943ef94940681de3',
// The official ERC-4337 entry point contract is deployed using the Arachnid CREATE2 deployer.
await withArachnidDeterministicDeploymentProxy(hre, () =>
deploy('EntryPoint', {
from: deployer,
contract: EntryPoint,
args: [],
log: true,
deterministicDeployment: '0x90d8084deab30c2a37c45e8d47f49f2f7965183cb6990a98943ef94940681de3',
}),
)
}

function withArachnidDeterministicDeploymentProxy<T>({ config }: HardhatRuntimeEnvironment, f: () => Promise<T>): Promise<T> {
// This is a bit hacky - but the `hardhat-deploy` package reads that deterministic deployment
// configuration before deploying each contract. This means that we can temporarily override the
// the configuration to `undefined` so that it uses the (default) Arachnid deterministic
// deployment proxy for a specific deployment, and then restore the configuration afterwards so
// that remaining contracts use the deterministic deployment factory from `hardhat.config.ts`.
const existingConfig = config.deterministicDeployment
config.deterministicDeployment = undefined
return f().finally(() => {
config.deterministicDeployment = existingConfig
})
}

Expand Down

0 comments on commit 5ae188e

Please sign in to comment.