From 2d86b13d99540e642566899d8f558f08b00376f9 Mon Sep 17 00:00:00 2001 From: Lior Agnin Date: Wed, 11 Dec 2024 14:23:02 +0200 Subject: [PATCH 1/2] fix: do not modify any of the fields of the user operation after the paymaster signs over it --- example/pubspec.lock | 2 +- lib/src/4337/wallet.dart | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 9c46e8f..979e942 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -683,7 +683,7 @@ packages: path: ".." relative: true source: path - version: "0.1.5" + version: "0.1.6" vector_math: dependency: transitive description: diff --git a/lib/src/4337/wallet.dart b/lib/src/4337/wallet.dart index 41336dc..8ad2bf3 100644 --- a/lib/src/4337/wallet.dart +++ b/lib/src/4337/wallet.dart @@ -149,7 +149,6 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase { @override Future sendUserOperation(UserOperation op) => prepareUserOperation(op) - .then(applyCustomGasSettings) .then(signUserOperation) .then(sendSignedUserOperation); @@ -158,6 +157,10 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase { {bool update = true}) async { // Update the user operation with the latest nonce and gas prices if needed if (update) op = await _updateUserOperation(op); + + // Apply custom gas settings + op = applyCustomGasSettings(op); + // If the 'paymaster' plugin is enabled, intercept the user operation if (hasPlugin('paymaster')) { op = await plugin('paymaster').intercept(op); From ac04611f63de738b5a61001d5e76397d9a60f846 Mon Sep 17 00:00:00 2001 From: Lior Agnin Date: Wed, 11 Dec 2024 14:29:25 +0200 Subject: [PATCH 2/2] keep the functions leaner --- lib/src/4337/wallet.dart | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/src/4337/wallet.dart b/lib/src/4337/wallet.dart index 8ad2bf3..70aa268 100644 --- a/lib/src/4337/wallet.dart +++ b/lib/src/4337/wallet.dart @@ -148,28 +148,33 @@ class SmartWallet with _PluginManager, _GasSettings implements SmartWalletBase { @override Future sendUserOperation(UserOperation op) => - prepareUserOperation(op) - .then(signUserOperation) - .then(sendSignedUserOperation); + _prepareAndSignOperation(op).then(sendSignedUserOperation); + + Future _prepareAndSignOperation(UserOperation op) async { + final prepared = await prepareUserOperation(op); + return signUserOperation(prepared); + } @override Future prepareUserOperation(UserOperation op, {bool update = true}) async { - // Update the user operation with the latest nonce and gas prices if needed - if (update) op = await _updateUserOperation(op); - - // Apply custom gas settings - op = applyCustomGasSettings(op); - - // If the 'paymaster' plugin is enabled, intercept the user operation - if (hasPlugin('paymaster')) { - op = await plugin('paymaster').intercept(op); - } - // Validate the user operation + op = await _updateIfNeeded(op, update); + op = await _applyPlugins(op); op.validate(op.nonce > BigInt.zero, initCode); return op; } + Future _updateIfNeeded(UserOperation op, bool update) async { + if (!update) return op; + op = await _updateUserOperation(op); + return applyCustomGasSettings(op); + } + + Future _applyPlugins(UserOperation op) async { + if (!hasPlugin('paymaster')) return op; + return plugin('paymaster').intercept(op); + } + @override Future signUserOperation(UserOperation op, {int? index}) async {