Skip to content

Commit

Permalink
Adjust safe signerlaunchpad to packed userop
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Mar 6, 2024
1 parent 9c8fe00 commit cc915e4
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/4337-gas-metering/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
"outDir": "./dist" /* Redirect output structure to the directory. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */
},
"exclude": ["node_modules"],
"exclude": ["node_modules"]
}
4 changes: 2 additions & 2 deletions modules/passkey/.env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Entrypoint address to use for the Safe 4337 module deployment in 4337 tests
TESTS_4337_MODULE_DEPLOYMENT_ENTRY_POINT_ADDRESS=""
# Entrypoint address to use for the Safe 4337 module deployment in 4337 tests. Default is the canonical EntryPoint v0.7 address
TESTS_4337_MODULE_DEPLOYMENT_ENTRY_POINT_ADDRESS="0x0000000071727De22E5E9d8BAf0edAc6f37da032"
4 changes: 3 additions & 1 deletion modules/passkey/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ services:
build:
context: .
dockerfile: docker/bundler/Dockerfile
args:
TAG: 26e4f4c433916a6a2ea8ecc91ba8a56cd904f27f
restart: always
command: ['--auto', '--network=http://geth:8545']
ports:
Expand All @@ -28,7 +30,7 @@ services:
context: .
dockerfile: docker/bundler/Dockerfile
args:
TAG: main
TAG: 26e4f4c433916a6a2ea8ecc91ba8a56cd904f27f
restart: always
command: ['--auto', '--network=http://geth:8545']
ports:
Expand Down
4 changes: 3 additions & 1 deletion modules/passkey/docker/bundler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM docker.io/library/node:18

ARG TAG=v0.6.1
# v0.7.0
ARG TAG=26e4f4c
RUN git clone https://github.com/eth-infinitism/bundler /src/bundler
WORKDIR /src/bundler
RUN git checkout ${TAG}
RUN git submodule init && git submodule update

RUN yarn && yarn preprocess
ENTRYPOINT ["yarn", "bundler"]
Expand Down
2 changes: 1 addition & 1 deletion modules/passkey/src/deploy/4337.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const deploy: DeployFunction = async ({ deployments, getNamedAccounts, network }
contract: EntryPoint,
args: [],
log: true,
deterministicDeployment: true,
deterministicDeployment: '0x90d8084deab30c2a37c45e8d47f49f2f7965183cb6990a98943ef94940681de3',
})
} else if (!ENTRY_POINT) {
throw new Error('TESTS_4337_MODULE_DEPLOYMENT_ENTRY_POINT_ADDRESS must be set')
Expand Down
25 changes: 17 additions & 8 deletions modules/passkey/test/4337-e2e/WebAuthnSigner.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from 'chai'
import { deployments, ethers, network } from 'hardhat'
import { packGasParameters, unpackUserOperation } from '@safe-global/safe-erc4337/src/utils/userOp'
import { bundlerRpc, prepareAccounts, waitForUserOp } from '../utils/e2e'
import { chainId } from '../utils/encoding'
import {
Expand All @@ -9,6 +10,7 @@ import {
extractPublicKey,
extractSignature,
} from '../utils/webauthn'
import { PackedUserOperationStruct } from '../../typechain-types/@account-abstraction/contracts/interfaces/IAccount'

describe('E2E - WebAuthn Signers', () => {
before(function () {
Expand Down Expand Up @@ -135,7 +137,7 @@ describe('E2E - WebAuthn Signers', () => {
const safeSalt = Date.now()
const safe = await proxyFactory.createProxyWithNonce.staticCall(signerLaunchpad.target, launchpadInitializer, safeSalt)

const userOp = {
const packedUserOp: PackedUserOperationStruct = {
sender: safe,
nonce: ethers.toBeHex(await entryPoint.getNonce(safe, 0)),
initCode: ethers.solidityPacked(
Expand All @@ -156,16 +158,19 @@ describe('E2E - WebAuthn Signers', () => {
safeInit.fallbackHandler,
module.interface.encodeFunctionData('executeUserOp', [user.address, ethers.parseEther('0.5'), '0x', 0]),
]),
callGasLimit: ethers.toBeHex(2000000),
verificationGasLimit: ethers.toBeHex(500000),
...packGasParameters({
verificationGasLimit: 500000,
callGasLimit: 2000000,
maxFeePerGas: 10000000000,
maxPriorityFeePerGas: 10000000000,
}),
preVerificationGas: ethers.toBeHex(60000),
maxFeePerGas: ethers.toBeHex(10000000000),
maxPriorityFeePerGas: ethers.toBeHex(10000000000),
paymasterAndData: '0x',
signature: '0x',
}

const safeInitOp = {
userOpHash: await entryPoint.getUserOpHash({ ...userOp, signature: '0x' }),
userOpHash: await entryPoint.getUserOpHash(packedUserOp),
validAfter: 0,
validUntil: 0,
entryPoint: entryPoint.target,
Expand All @@ -182,6 +187,9 @@ describe('E2E - WebAuthn Signers', () => {
},
safeInitOp,
)
expect(await signerLaunchpad.getOperationHash(safeInitOp.userOpHash, safeInitOp.validAfter, safeInitOp.validUntil)).to.equal(
safeInitOpHash,
)

const assertion = navigator.credentials.get({
publicKey: {
Expand Down Expand Up @@ -212,9 +220,10 @@ describe('E2E - WebAuthn Signers', () => {
expect(await ethers.provider.getCode(safe)).to.equal('0x')
expect(await ethers.provider.getCode(signerAddress)).to.equal('0x')

await bundler.sendUserOperation({ ...userOp, signature }, await entryPoint.getAddress())

const userOp = await unpackUserOperation({ ...packedUserOp, signature })
await bundler.sendUserOperation(userOp, await entryPoint.getAddress())
await waitForUserOp(userOp)

expect(await ethers.provider.getBalance(safe)).to.be.lessThanOrEqual(ethers.parseEther('0.5'))
expect(await ethers.provider.getCode(safe)).to.not.equal('0x')
expect(await ethers.provider.getCode(signerAddress)).to.not.equal('0x')
Expand Down
4 changes: 2 additions & 2 deletions modules/passkey/test/utils/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deployments, ethers } from 'hardhat'
import { MultiProvider4337 } from '@safe-global/safe-erc4337/dist/src/utils/safe'
import { UserOperation } from '@safe-global/safe-erc4337/dist/src/utils/userOp'
import { AddressLike, BigNumberish, BytesLike, HDNodeWallet } from 'ethers'
import { PackedUserOperationStruct } from '../../typechain-types/@account-abstraction/contracts/interfaces/IAccount'

export const BUNDLER_URL = process.env.TEST_BUNLDER_URL || 'http://localhost:3000/rpc'
export const BUNDLER_MNEMONIC = process.env.TEST_BUNDLER_MNEMONIC || 'test test test test test test test test test test test junk'
Expand All @@ -27,7 +27,7 @@ export function bundlerRpc(url = BUNDLER_URL) {
return new MultiProvider4337(url, ethers.provider)
}

export async function waitForUserOp({ sender, nonce }: Pick<UserOperation, 'sender' | 'nonce'>, timeout = 10_000) {
export async function waitForUserOp({ sender, nonce }: Pick<PackedUserOperationStruct, 'sender' | 'nonce'>, timeout = 10_000) {
const { address: entryPointAddress } = await deployments.get('EntryPoint')
const entryPoint = await ethers.getContractAt('INonceManager', entryPointAddress)
const start = performance.now()
Expand Down

0 comments on commit cc915e4

Please sign in to comment.