Skip to content

Commit

Permalink
fix certora conf
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Jun 24, 2024
1 parent dd6697c commit 12304ad
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion modules/4337/certora/conf/Safe4337Module.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"verify": "Safe4337Module:certora/specs/Safe4337Module.spec",
"packages": [
"@account-abstraction=../../node_modules/.pnpm/@account-abstraction+contracts@0.7.0/node_modules/@account-abstraction",
"@safe-global=../../node_modules/.pnpm/@safe-global+safe-contracts@1.4.1-build.0_ethers@6.12.1_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/@safe-global"
"@safe-global=../../node_modules/.pnpm/@safe-global+safe-contracts@1.4.1-build.0_ethers@6.13.1_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/@safe-global"
]
}
2 changes: 1 addition & 1 deletion modules/4337/certora/conf/TransactionExecutionMethods.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"verify": "Safe4337Module:certora/specs/TransactionExecutionMethods.spec",
"packages": [
"@account-abstraction=../../node_modules/.pnpm/@account-abstraction+contracts@0.7.0/node_modules/@account-abstraction",
"@safe-global=../../node_modules/.pnpm/@safe-global+safe-contracts@1.4.1-build.0_ethers@6.12.1_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/@safe-global"
"@safe-global=../../node_modules/.pnpm/@safe-global+safe-contracts@1.4.1-build.0_ethers@6.13.1_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/@safe-global"
]
}
2 changes: 1 addition & 1 deletion modules/4337/certora/conf/ValidationDataLastBitOne.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"verify": "Safe4337Module:certora/specs/ValidationDataLastBitOne.spec",
"packages": [
"@account-abstraction=../../node_modules/.pnpm/@account-abstraction+contracts@0.7.0/node_modules/@account-abstraction",
"@safe-global=../../node_modules/.pnpm/@safe-global+safe-contracts@1.4.1-build.0_ethers@6.12.1_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/@safe-global"
"@safe-global=../../node_modules/.pnpm/@safe-global+safe-contracts@1.4.1-build.0_ethers@6.13.1_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/@safe-global"
]
}
61 changes: 39 additions & 22 deletions modules/4337/test/utils/simulations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,28 @@ import { ethers } from 'ethers'
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'
import { buildPackedUserOperationFromSafeUserOperation, PLACEHOLDER_SIGNATURE, SafeUserOperation } from '../../src/utils/userOp'
import { EntryPointSimulations } from '../../typechain-types'

export interface GasOverheads {
/**
* fixed overhead for entire handleOp bundle.
*/
// fixed overhead for entire handleOp bundle.
fixed: number

/**
* per userOp overhead, added on top of the above fixed per-bundle.
*/
// The per userOp overhead, added on top of the above fixed per-bundle.
perUserOp: number

/**
* overhead for userOp word (32 bytes) block
*/
// The overhead for userOp word (32 bytes) block.
perUserOpWord: number

// perCallDataWord: number

/**
* zero byte cost, for calldata gas cost calculations
*/
// The gas cost for zero bytes, used in calldata gas cost calculations.
zeroByte: number

/**
* non-zero byte cost, for calldata gas cost calculations
*/
// The gas cost for non-zero bytes, used in calldata gas cost calculations.
nonZeroByte: number

/**
* expected bundle size, to split per-bundle overhead between all ops.
*/
// The expected bundle size, used to split per-bundle overhead between all ops.
bundleSize: number

/**
* expected length of the userOp signature.
*/
// The expected length of the userOp signature.
sigSize: number
}

Expand Down Expand Up @@ -121,6 +106,12 @@ export type ExecutionResultStructOutput = [
targetResult: string
}

/**
* Calculates the verification gas limit and call gas limit based on the user operation and execution result.
* @param userOperation - The user operation object.
* @param executionResult - The execution result object.
* @returns An object containing the verification gas limit and call gas limit.
*/
export const calcVerificationGasAndCallGasLimit = (userOperation: SafeUserOperation, executionResult: ExecutionResultStructOutput) => {
const verificationGasLimit = BigInt(executionResult.preOpGas) - BigInt(userOperation.preVerificationGas)

Expand All @@ -131,6 +122,32 @@ export const calcVerificationGasAndCallGasLimit = (userOperation: SafeUserOperat
return { verificationGasLimit, callGasLimit }
}

/**
* Estimates gas for a user operation on a Safe account.
*

Check failure on line 127 in modules/4337/test/utils/simulations.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* This function performs a simulation of the user operation to estimate User Operation gas parameters
* required for executing the operation on the blockchain. It uses state overrides to replace the EntryPoint code
* with the EntryPointSimulations contract, which allows for gas estimation without actually executing the operation.
*

Check failure on line 131 in modules/4337/test/utils/simulations.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* TODO: This function doesn't support the case where multiple user operations are bundled together. To implement this,
* we can use Pimlico's EntryPointSimulations contract to simulate the execution of multiple user operations:
* https://github.com/pimlicolabs/alto/blob/5f0fb585870cfca3d081e962989c682aa3c02ff4/contracts/src/PimlicoEntryPointSimulations/PimlicoEntryPointSimulations.sol
*

Check failure on line 135 in modules/4337/test/utils/simulations.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* @param provider - The Hardhat Ethers provider used for blockchain interactions.
* @param entryPointSimulations - An instance of EntryPointSimulations contract for simulating operations.
* @param safeOp - The Safe user operation to estimate gas for.
* @param entryPointAddress - The address of the EntryPoint contract.
*

Check failure on line 140 in modules/4337/test/utils/simulations.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* @returns A promise that resolves to an EstimateUserOpGasResult object containing:
* - preVerificationGas: The gas required for pre-verification steps.
* - callGasLimit: The gas limit for the main execution call.
* - verificationGasLimit: The gas limit for the verification step.
* - totalGasPaid: The total amount of gas paid for the operation.
* - maxFeePerGas: The maximum fee per gas unit.
* - maxPriorityFeePerGas: The maximum priority fee per gas unit.
*

Check failure on line 148 in modules/4337/test/utils/simulations.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
* @throws Error if fee data is missing from the provider.
*/
export const estimateUserOperationGas = async (
provider: HardhatEthersProvider,
entryPointSimulations: EntryPointSimulations,
Expand Down

0 comments on commit 12304ad

Please sign in to comment.