Skip to content

Commit

Permalink
Fix some issues with RIP-7560
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Jan 21, 2025
1 parent 6f61c92 commit da7f986
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/bundler/src/modules/ExecutionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class ExecutionManager {
const { configuration, entryPoint, unsafe } = this.validationManager._getDebugConfiguration()
const mergedConfiguration = Object.assign({}, configuration, configOverrides)
const pvgc = new PreVerificationGasCalculator(mergedConfiguration)
const erc7562Parser = new ERC7562Parser(entryPoint.address, mergedConfiguration.senderCreator ?? '', true)
const erc7562Parser = new ERC7562Parser(entryPoint.address, mergedConfiguration.senderCreator ?? '')
this.validationManager = new ValidationManager(
entryPoint,
unsafe,
Expand Down
5 changes: 3 additions & 2 deletions packages/bundler/src/modules/initServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MempoolManager } from './MempoolManager'
import { BundleManager } from './BundleManager'
import {
AA_ENTRY_POINT,
AA_NONCE_MANAGER,
AA_SENDER_CREATOR,
AA_STAKE_MANAGER,
IValidationManager,
Expand Down Expand Up @@ -42,13 +43,13 @@ export function initServer (config: BundlerConfig, signer: Signer): [ExecutionMa
let validationManager: IValidationManager
let bundleManager: IBundleManager
if (!config.rip7560) {
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator, true)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator)
const tracerProvider = config.tracerRpcUrl == null ? undefined : getNetworkProvider(config.tracerRpcUrl)
validationManager = new ValidationManager(entryPoint, config.unsafe, preVerificationGasCalculator, erc7562Parser, tracerProvider)
bundleManager = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, signer, eventsManager, mempoolManager, validationManager, reputationManager,
config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, config.conditionalRpc)
} else {
const erc7562Parser = new ERC7562Parser(AA_ENTRY_POINT, AA_SENDER_CREATOR, true)
const erc7562Parser = new ERC7562Parser(AA_ENTRY_POINT, AA_SENDER_CREATOR, AA_NONCE_MANAGER)
const stakeManager = IRip7560StakeManager__factory.connect(AA_STAKE_MANAGER, signer)
validationManager = new ValidationManagerRIP7560(stakeManager, entryPoint.provider as JsonRpcProvider, erc7562Parser, config.unsafe)
bundleManager = new BundleManagerRIP7560(entryPoint.provider as JsonRpcProvider, signer, eventsManager, mempoolManager, validationManager, reputationManager,
Expand Down
4 changes: 2 additions & 2 deletions packages/bundler/test/BundlerManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('#BundlerManager', () => {
const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator, true)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator)
const validMgr = new ValidationManager(entryPoint, config.unsafe, preVerificationGasCalculator, erc7562Parser)
const evMgr = new EventsManager(entryPoint, mempoolMgr, repMgr)
bm = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, config.conditionalRpc)
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('#BundlerManager', () => {
const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator, true)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator)
const validMgr = new ValidationManager(_entryPoint, config.unsafe, preVerificationGasCalculator, erc7562Parser)
const evMgr = new EventsManager(_entryPoint, mempoolMgr, repMgr)
bundleMgr = new BundleManager(_entryPoint, _entryPoint.provider as JsonRpcProvider, _entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/test/BundlerServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('BundleServer', function () {
const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator, true)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator)
const validMgr = new ValidationManager(entryPoint, config.unsafe, preVerificationGasCalculator, erc7562Parser)
const evMgr = new EventsManager(entryPoint, mempoolMgr, repMgr)
const bundleMgr = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/test/DebugMethodHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('#DebugMethodHandler', () => {
const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
const mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator, true)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator)
const validMgr = new ValidationManager(entryPoint, config.unsafe, preVerificationGasCalculator, erc7562Parser)
const eventsManager = new EventsManager(entryPoint, mempoolMgr, repMgr)
const bundleMgr = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, eventsManager, mempoolMgr, validMgr, repMgr,
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/test/UserOpMethodHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('UserOpMethodHandler', function () {
const repMgr = new ReputationManager(provider, BundlerReputationParams, parseEther(config.minStake), config.minUnstakeDelay)
mempoolMgr = new MempoolManager(repMgr)
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator, true)
const erc7562Parser = new ERC7562Parser(entryPoint.address, config.senderCreator)
const validMgr = new ValidationManager(entryPoint, config.unsafe, preVerificationGasCalculator, erc7562Parser)
const evMgr = new EventsManager(entryPoint, mempoolMgr, repMgr)
const bundleMgr = new BundleManager(entryPoint, entryPoint.provider as JsonRpcProvider, entryPoint.signer, evMgr, mempoolMgr, validMgr, repMgr, config.beneficiary, parseEther(config.minBalance), config.maxBundleGas, false)
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler/test/ValidateManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe('#ValidationManager', () => {
const preVerificationGasCalculator = new PreVerificationGasCalculator(MainnetConfig)

const senderCreator = '0xefc2c1444ebcc4db75e7613d20c6a62ff67a167c'
const erc7562Parser = new ERC7562Parser(entryPoint.address, senderCreator, true)
const erc7562Parser = new ERC7562Parser(entryPoint.address, senderCreator)
vm = new ValidationManager(entryPoint, unsafe, preVerificationGasCalculator, erc7562Parser)

if (!await supportsDebugTraceCall(ethers.provider, false)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export enum AccountAbstractionEntity {
senderCreator = 'SenderCreator',
entryPoint = 'EntryPoint',
nativeEntryPoint = 'NativeEntryPoint',
nativeNonceManager = 'NativeNonceManager',
none = 'none'
}
24 changes: 15 additions & 9 deletions packages/validation-manager/src/ERC7562Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,12 @@ export class ERC7562Parser {
private contractAddresses: string[] = []
private storageMap: StorageMap = {}

private bailOnViolation: boolean = false

constructor (
readonly entryPointAddress: string,
readonly senderCreatorAddress: string,
readonly bailOnViolation: boolean
readonly nonceManagerAddress?: string,
) {}

private _init (erc7562Call: ERC7562Call): void {
Expand Down Expand Up @@ -364,6 +366,9 @@ export class ERC7562Parser {
} else if (this.senderCreatorAddress.toLowerCase() === call.to.toLowerCase()) {
this.currentEntity = AccountAbstractionEntity.senderCreator
this.currentEntityAddress = this.senderCreatorAddress
} else if (this.nonceManagerAddress?.toLowerCase() === call.to.toLowerCase()) {
this.currentEntity = AccountAbstractionEntity.nativeNonceManager
this.currentEntityAddress = this.nonceManagerAddress!
} else {
throw new RpcError(`could not find entity name for address ${call.to}. This should not happen. This is a bug.`, 0)
}
Expand Down Expand Up @@ -394,8 +399,8 @@ export class ERC7562Parser {
private _parseEntitySlots (
userOp: OperationBase
): {
[addr: string]: Set<string>
} {
[addr: string]: Set<string>
} {
// for each entity (sender, factory, paymaster), hold the valid slot addresses
const entityAddresses = [userOp.sender.toLowerCase(), userOp.paymaster?.toLowerCase(), userOp.factory?.toLowerCase()]
const entitySlots: { [addr: string]: Set<string> } = {}
Expand Down Expand Up @@ -426,11 +431,9 @@ export class ERC7562Parser {
tracerResults: ERC7562Call,
validationResult: ValidationResult
): ERC7562ValidationResults {
this.bailOnViolation = true
const results = this.parseResults(userOp, tracerResults, validationResult)
if (results.ruleViolations.length > 0) {
// TODO: human-readable description of which rules were violated.
throw new Error('Rules Violated')
}
this.bailOnViolation = false
return results
}

Expand Down Expand Up @@ -713,8 +716,11 @@ export class ERC7562Parser {
userOp: OperationBase,
tracerResults: ERC7562Call
): void {
if (tracerResults.to.toLowerCase() === this.entryPointAddress.toLowerCase()) {
// Currently inside the EntryPoint deposit code, no access control applies here
if (
tracerResults.to.toLowerCase() === this.entryPointAddress.toLowerCase() ||
tracerResults.to.toLowerCase() === this.nonceManagerAddress?.toLowerCase()
) {
// Currently inside system code, no access control applies here
return
}
const allSlots: string[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ERC7562Parser } from './ERC7562Parser'
export const AA_ENTRY_POINT = '0x0000000000000000000000000000000000007560'
export const AA_SENDER_CREATOR = '0x00000000000000000000000000000000ffff7560'
export const AA_STAKE_MANAGER = '0x570Aa568b6cf62ff08c6C3a3b3DB1a0438E871Fb'
export const AA_NONCE_MANAGER = '0x632fafb21910d6c8b4a3995063dd984f2b829c02'

export class ValidationManagerRIP7560 implements IValidationManager {
constructor (
Expand Down
2 changes: 1 addition & 1 deletion packages/validation-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export async function checkRulesViolations (
}
const entryPoint = IEntryPoint__factory.connect(entryPointAddress, provider)
const senderCreator = '0xefc2c1444ebcc4db75e7613d20c6a62ff67a167c'
const erc7562Parser = new ERC7562Parser(entryPointAddress, senderCreator, true)
const erc7562Parser = new ERC7562Parser(entryPointAddress, senderCreator)
const validationManager = new ValidationManager(
entryPoint,
false,
Expand Down

0 comments on commit da7f986

Please sign in to comment.