Skip to content

Commit

Permalink
fix: [CL ALCHEMY-004] enforce unique deferred action nonce per UO val…
Browse files Browse the repository at this point in the history
…idation (#299)
  • Loading branch information
adamegyed authored Nov 25, 2024
1 parent bf9e53a commit 74bd948
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 373 deletions.
28 changes: 14 additions & 14 deletions gas-snapshots/ModularAccount.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"Runtime_AccountCreation": "176376",
"Runtime_BatchTransfers": "92817",
"Runtime_Erc20Transfer": "78271",
"Runtime_InstallSessionKey_Case1": "423293",
"Runtime_NativeTransfer": "54420",
"Runtime_UseSessionKey_Case1_Counter": "78542",
"Runtime_UseSessionKey_Case1_Token": "111855",
"UserOp_BatchTransfers": "197788",
"UserOp_Erc20Transfer": "184784",
"UserOp_InstallSessionKey_Case1": "531124",
"UserOp_NativeTransfer": "161029",
"UserOp_UseSessionKey_Case1_Counter": "194521",
"UserOp_UseSessionKey_Case1_Token": "225505",
"UserOp_deferredValidation": "257223"
"Runtime_AccountCreation": "176354",
"Runtime_BatchTransfers": "92886",
"Runtime_Erc20Transfer": "78318",
"Runtime_InstallSessionKey_Case1": "423362",
"Runtime_NativeTransfer": "54467",
"Runtime_UseSessionKey_Case1_Counter": "78531",
"Runtime_UseSessionKey_Case1_Token": "111844",
"UserOp_BatchTransfers": "197706",
"UserOp_Erc20Transfer": "184680",
"UserOp_InstallSessionKey_Case1": "531042",
"UserOp_NativeTransfer": "160925",
"UserOp_UseSessionKey_Case1_Counter": "194415",
"UserOp_UseSessionKey_Case1_Token": "225399",
"UserOp_deferredValidation": "233002"
}
26 changes: 13 additions & 13 deletions gas-snapshots/SemiModularAccount.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"Runtime_AccountCreation": "97767",
"Runtime_BatchTransfers": "89019",
"Runtime_Erc20Transfer": "74521",
"Runtime_InstallSessionKey_Case1": "422024",
"Runtime_NativeTransfer": "50680",
"Runtime_UseSessionKey_Case1_Counter": "78809",
"Runtime_UseSessionKey_Case1_Token": "112122",
"UserOp_BatchTransfers": "193097",
"UserOp_Erc20Transfer": "180176",
"UserOp_InstallSessionKey_Case1": "528787",
"UserOp_NativeTransfer": "156451",
"UserOp_UseSessionKey_Case1_Counter": "194821",
"UserOp_UseSessionKey_Case1_Token": "225805",
"UserOp_deferredValidation": "253169"
"Runtime_BatchTransfers": "88758",
"Runtime_Erc20Transfer": "74238",
"Runtime_InstallSessionKey_Case1": "421513",
"Runtime_NativeTransfer": "50397",
"Runtime_UseSessionKey_Case1_Counter": "78834",
"Runtime_UseSessionKey_Case1_Token": "112147",
"UserOp_BatchTransfers": "192875",
"UserOp_Erc20Transfer": "179932",
"UserOp_InstallSessionKey_Case1": "528315",
"UserOp_NativeTransfer": "156207",
"UserOp_UseSessionKey_Case1_Counter": "194667",
"UserOp_UseSessionKey_Case1_Token": "225651",
"UserOp_deferredValidation": "228953"
}
7 changes: 3 additions & 4 deletions gas/modular-account/ModularAccount.gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {Vm} from "forge-std/Vm.sol";

import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol";
import {AccountFactory} from "../../src/factory/AccountFactory.sol";
import {ValidationLocatorLib} from "../../src/libraries/ValidationLocatorLib.sol";
import {SingleSignerValidationModule} from "../../src/modules/validation/SingleSignerValidationModule.sol";

import {ModularAccountBenchmarkBase} from "./ModularAccountBenchmarkBase.sol";
Expand Down Expand Up @@ -270,11 +271,10 @@ contract ModularAccountGasTest is ModularAccountBenchmarkBase("ModularAccount")
(newUOValidation, new bytes4[](0), abi.encode(newEntityId, owner2), new bytes[](0))
);

uint256 deferredInstallNonce = 0;
uint48 deferredInstallDeadline = 0;

bytes32 digest = _getDeferredInstallStruct(
account1, deferredInstallNonce, deferredInstallDeadline, newUOValidation, deferredValidationInstallCall
account1, userOp.nonce, deferredInstallDeadline, deferredValidationInstallCall
);

bytes memory deferredValidationSig = _signRawHash(
Expand All @@ -285,9 +285,8 @@ contract ModularAccountGasTest is ModularAccountBenchmarkBase("ModularAccount")

userOp.signature = _encodeDeferredInstallUOSignature(
_packDeferredInstallData(
deferredInstallNonce,
deferredInstallDeadline,
ValidationConfigLib.pack(signerValidation, true, false, false),
ValidationLocatorLib.packFromModuleEntity(signerValidation, true, false),
deferredValidationInstallCall
),
deferredValidationSig,
Expand Down
7 changes: 3 additions & 4 deletions gas/modular-account/SemiModularAccount.gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ModularAccountBase} from "../../src/account/ModularAccountBase.sol";
import {AccountFactory} from "../../src/factory/AccountFactory.sol";
import {SingleSignerValidationModule} from "../../src/modules/validation/SingleSignerValidationModule.sol";

import {ValidationLocatorLib} from "../../src/libraries/ValidationLocatorLib.sol";
import {ModularAccountBenchmarkBase} from "./ModularAccountBenchmarkBase.sol";

contract ModularAccountGasTest is ModularAccountBenchmarkBase("SemiModularAccount") {
Expand Down Expand Up @@ -264,20 +265,18 @@ contract ModularAccountGasTest is ModularAccountBenchmarkBase("SemiModularAccoun
(newUOValidation, new bytes4[](0), abi.encode(newEntityId, owner2), new bytes[](0))
);

uint256 deferredInstallNonce = 0;
uint48 deferredInstallDeadline = 0;

bytes32 digest = _getDeferredInstallStruct(
account1, deferredInstallNonce, deferredInstallDeadline, newUOValidation, deferredValidationInstallCall
account1, userOp.nonce, deferredInstallDeadline, deferredValidationInstallCall
);

bytes memory deferredValidationSig = _signRawHash(vm, owner1Key, digest);

userOp.signature = _encodeDeferredInstallUOSignature(
_packDeferredInstallData(
deferredInstallNonce,
deferredInstallDeadline,
ValidationConfigLib.pack(signerValidation, true, false, false),
ValidationLocatorLib.packFromModuleEntity(signerValidation, true, false),
deferredValidationInstallCall
),
deferredValidationSig,
Expand Down
2 changes: 0 additions & 2 deletions src/account/AccountStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ struct AccountStorage {
mapping(ValidationLookupKey lookupKey => ValidationStorage) validationStorage;
// Module-defined ERC-165 interfaces installed on the account.
mapping(bytes4 => uint256) supportedIfaces;
// Nonce usage state for deferred actions.
mapping(uint256 => bool) deferredActionNonceUsed;
}

function getAccountStorage() pure returns (AccountStorage storage _storage) {
Expand Down
Loading

0 comments on commit 74bd948

Please sign in to comment.