/
ECDSAMultichainValidator.sol
102 lines (90 loc) · 3.69 KB
/
ECDSAMultichainValidator.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import {BaseAuthorizationModule, UserOperation, ISignatureValidator} from "./BaseAuthorizationModule.sol";
import {EcdsaOwnershipRegistryModule} from "./EcdsaOwnershipRegistryModule.sol";
import {UserOperationLib} from "@account-abstraction/contracts/interfaces/UserOperation.sol";
import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import {calldataKeccak, _packValidationData} from "@account-abstraction/contracts/core/Helpers.sol";
/**
* @title ECDSA Multichain Validator module for Biconomy Smart Accounts.
* @dev Biconomy’s Multichain Validator module enables use cases which
* require several actions to be authorized for several chains with just one
* signature required from user.
* - Leverages Merkle Trees to efficiently manage large datasets
* - Inherits from the ECDSA Ownership Registry Module
* - Compatible with Biconomy Modular Interface v 0.1
* - Does not introduce any additional security trade-offs compared to the
* vanilla ERC-4337 flow.
* @author Fil Makarov - <filipp.makarov@biconomy.io>
*/
contract MultichainECDSAValidator is EcdsaOwnershipRegistryModule {
using UserOperationLib for UserOperation;
/**
* @dev Validates User Operation.
* leaf = validUntil + validAfter + userOpHash
* If the leaf is the part of the Tree with a root provided, userOp considered
* to be authorized by user
* @param userOp user operation to be validated
* @param userOpHash hash of the userOp provided by the EP
*/
function validateUserOp(
UserOperation calldata userOp,
bytes32 userOpHash
) external view virtual override returns (uint256) {
(bytes memory moduleSignature, ) = abi.decode(
userOp.signature,
(bytes, address)
);
address sender;
//read sender from userOp, which is first userOp member (saves gas)
assembly {
sender := calldataload(userOp)
}
if (moduleSignature.length == 65) {
//it's not a multichain signature
return
_verifySignature(
userOpHash,
moduleSignature,
address(uint160(sender))
)
? VALIDATION_SUCCESS
: SIG_VALIDATION_FAILED;
}
//otherwise it is a multichain signature
(
uint48 validUntil,
uint48 validAfter,
bytes32 merkleTreeRoot,
bytes32[] memory merkleProof,
bytes memory multichainSignature
) = abi.decode(
moduleSignature,
(uint48, uint48, bytes32, bytes32[], bytes)
);
//make a leaf out of userOpHash, validUntil and validAfter
bytes32 leaf = keccak256(
abi.encodePacked(validUntil, validAfter, userOpHash)
);
if (!MerkleProof.verify(merkleProof, merkleTreeRoot, leaf)) {
revert("Invalid UserOp");
}
return
_verifySignature(
merkleTreeRoot,
multichainSignature,
address(uint160(sender))
)
? _packValidationData(
false, //sigVerificationFailed = false
validUntil == 0 ? type(uint48).max : validUntil,
validAfter
)
: SIG_VALIDATION_FAILED;
}
/**
* Inherits isValideSignature method from EcdsaOwnershipRegistryModule
* isValidSignature is intended to work not with a multichain signature
* but with a regular ecdsa signature over a message hash
*/
}