generated from zeroknots/femplate
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
3,620 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
@openzeppelin/=node_modules/@openzeppelin/ | ||
@ERC4337/=node_modules/@ERC4337/ | ||
solmate/=node_modules/solmate/src/ | ||
solady/=node_modules/solady/src/ | ||
solady/=node_modules/solady/ | ||
forge-std/=node_modules/forge-std/src/ | ||
ds-test/=node_modules/ds-test/src/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity ^0.8.24; | ||
|
||
import { IAggregator } from "@ERC4337/account-abstraction/contracts/interfaces/IAggregator.sol"; | ||
import { PackedUserOperation } from "@ERC4337/account-abstraction/contracts/interfaces/PackedUserOperation.sol"; | ||
import { ModuleType } from "../DataTypes.sol"; | ||
|
||
|
||
interface ValidatorSelection { | ||
|
||
function getValidator(PackedUserOperation calldata userOp) external view returns (address validator); | ||
|
||
} | ||
|
||
abstract contract Aggregator is IAggregator { | ||
function validateSignatures(PackedUserOperation[] calldata userOps, bytes calldata signature) external view { | ||
uint256 length = userOps.length; | ||
|
||
for (uint256 i; i < length; i++) { | ||
PackedUserOperation calldata userOp = userOps[i]; | ||
address smartAccount = userOp.sender; | ||
address validator = _getValidator(userOp); | ||
_check(smartAccount, validator, ModuleType.wrap(1)); | ||
} | ||
|
||
} | ||
function validateUserOpSignature(PackedUserOperation calldata userOp) external view returns (bytes memory sigForUserOp) { } | ||
|
||
function _getValidator(PackedUserOperation calldata userOp) internal pure returns (address validator) { | ||
uint256 nonce = userOp.nonce; | ||
assembly { | ||
validator := shr(96, nonce) | ||
} | ||
address validator = ValidatorSelection(smartAccount).getValidator(userOp); | ||
} | ||
|
||
|
||
|
||
function aggregateSignatures(PackedUserOperation[] calldata userOps) external view returns (bytes memory aggregatedSignature) { | ||
uint256 length = userOps.length; | ||
|
||
for (uint256 i; i < length; i++) { | ||
PackedUserOperation calldata userOp = userOps[i]; | ||
address validator = _getValidator(userOp); | ||
address smartAccount = userOp.sender; | ||
_check(smartAccount, validator, ModuleType.wrap(1)); | ||
|
||
} | ||
} | ||
|
||
function _check(address smartAccount, address module, ModuleType moduleType) internal view virtual; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity ^0.8.24; | ||
|
||
import "./TrustDelegation.t.sol"; | ||
import { PackedUserOperation } from "@ERC4337/account-abstraction/contracts/interfaces/PackedUserOperation.sol"; | ||
|
||
contract AggregatorTest is TrustTest { | ||
function setUp() public override { | ||
super.setUp(); | ||
|
||
address[] memory attesters = new address[](1); | ||
attesters[0] = address(attester1.addr); | ||
_make_WhenUsingValidECDSA(attester1); | ||
test_WhenSupplyingManyAttesters(1, attesters); | ||
} | ||
|
||
function test_aggregate() public { | ||
PackedUserOperation[] memory userOps = new PackedUserOperation[](1); | ||
userOps[0] = PackedUserOperation({ | ||
sender: smartAccount1.addr, | ||
nonce: getNonce(1, address(module1)), | ||
initCode: "", | ||
callData: "", | ||
accountGasLimits: bytes32(abi.encodePacked(uint128(2e6), uint128(2e6))), | ||
preVerificationGas: 2e6, | ||
gasFees: bytes32(abi.encodePacked(uint128(2e6), uint128(2e6))), | ||
paymasterAndData: bytes(""), | ||
signature: abi.encodePacked(hex"41414141") | ||
}); | ||
|
||
// userOps[1] = PackedUserOperation({ | ||
// sender: smartAccount2.addr, | ||
// nonce: getNonce(1, address(module1)), | ||
// initCode: "", | ||
// callData: "", | ||
// accountGasLimits: bytes32(abi.encodePacked(uint128(2e6), uint128(2e6))), | ||
// preVerificationGas: 2e6, | ||
// gasFees: bytes32(abi.encodePacked(uint128(2e6), uint128(2e6))), | ||
// paymasterAndData: bytes(""), | ||
// signature: abi.encodePacked(hex"41414141") | ||
// }); | ||
bytes memory sig = registry.aggregateSignatures(userOps); | ||
|
||
registry.validateSignatures(userOps, sig); | ||
} | ||
|
||
function getNonce(uint256 _nonce, address validator) internal view returns (uint256 nonce) { | ||
uint192 key = uint192(bytes24(bytes20(address(validator)))); | ||
nonce = _nonce | uint256(key) << 64; | ||
} | ||
|
||
function signatureInNonce( | ||
address account, | ||
uint256 nonce, | ||
PackedUserOperation memory userOp, | ||
address validator, | ||
bytes memory signature | ||
) | ||
internal | ||
view | ||
returns (PackedUserOperation memory) | ||
{ | ||
userOp.nonce = getNonce(nonce, validator); | ||
userOp.signature = signature; | ||
|
||
return userOp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters