Skip to content

Commit 10c0997

Browse files
adnparkleekt
andauthored
feat: change contract name and add dummy signature verification (#109)
* feat: change contract name and add dummy signature verification * feat: add dummy signature verification to multi chain signer * fmt --------- Co-authored-by: leekt <[email protected]>
1 parent 6681a2b commit 10c0997

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ struct ECDSAValidatorStorage {
2020
address owner;
2121
}
2222

23-
contract MultiSignatureECDSASigner is SignerBase {
23+
bytes constant DUMMY_ECDSA_SIG =
24+
hex"fffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
25+
26+
contract MultiChainSigner is SignerBase {
2427
mapping(address => uint256) public usedIds;
2528
mapping(bytes32 id => mapping(address wallet => address)) public signer;
2629

@@ -70,8 +73,15 @@ contract MultiSignatureECDSASigner is SignerBase {
7073
}
7174
bytes memory ecdsaSig = sig[0:65];
7275
bytes32 merkleRoot = bytes32(sig[65:97]);
73-
bytes32[] memory proof = abi.decode(sig[97:], (bytes32[]));
74-
require(MerkleProofLib.verify(proof, merkleRoot, userOpHash), "hash is not in proof");
76+
// if the signature is a dummy signature, then use dummyUserOpHash instead of real userOpHash
77+
if (keccak256(ecdsaSig) == keccak256(DUMMY_ECDSA_SIG)) {
78+
(bytes32 dummyUserOpHash, bytes32[] memory proof) = abi.decode(sig[97:], (bytes32, bytes32[]));
79+
require(MerkleProofLib.verify(proof, merkleRoot, dummyUserOpHash), "hash is not in proof");
80+
// otherwise, use real userOpHash
81+
} else {
82+
bytes32[] memory proof = abi.decode(sig[97:], (bytes32[]));
83+
require(MerkleProofLib.verify(proof, merkleRoot, userOpHash), "hash is not in proof");
84+
}
7585
// simple ecdsa verification
7686
if (owner == ECDSA.recover(merkleRoot, ecdsaSig)) {
7787
return SIG_VALIDATION_SUCCESS_UINT;

src/validator/MultiSignatureECDSAValidator.sol renamed to src/validator/MultiChainValidator.sol

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ struct ECDSAValidatorStorage {
1919
address owner;
2020
}
2121

22-
contract MultiSignatureECDSAValidator is IValidator, IHook {
22+
bytes constant DUMMY_ECDSA_SIG =
23+
hex"fffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c";
24+
25+
contract MultiChainValidator is IValidator, IHook {
2326
event OwnerRegistered(address indexed kernel, address indexed owner);
2427

2528
mapping(address => ECDSAValidatorStorage) public ecdsaValidatorStorage;
@@ -69,8 +72,15 @@ contract MultiSignatureECDSAValidator is IValidator, IHook {
6972
}
7073
bytes memory ecdsaSig = sig[0:65];
7174
bytes32 merkleRoot = bytes32(sig[65:97]);
72-
bytes32[] memory proof = abi.decode(sig[97:], (bytes32[]));
73-
require(MerkleProofLib.verify(proof, merkleRoot, userOpHash), "hash is not in proof");
75+
// if the signature is a dummy signature, then use dummyUserOpHash instead of real userOpHash
76+
if (keccak256(ecdsaSig) == keccak256(DUMMY_ECDSA_SIG)) {
77+
(bytes32 dummyUserOpHash, bytes32[] memory proof) = abi.decode(sig[97:], (bytes32, bytes32[]));
78+
require(MerkleProofLib.verify(proof, merkleRoot, dummyUserOpHash), "hash is not in proof");
79+
// otherwise, use real userOpHash
80+
} else {
81+
bytes32[] memory proof = abi.decode(sig[97:], (bytes32[]));
82+
require(MerkleProofLib.verify(proof, merkleRoot, userOpHash), "hash is not in proof");
83+
}
7484
// simple ecdsa verification
7585
if (owner == ECDSA.recover(merkleRoot, ecdsaSig)) {
7686
return SIG_VALIDATION_SUCCESS_UINT;

0 commit comments

Comments
 (0)