-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sma 46 multichain validation module #257
Merged
livingrockrises
merged 10 commits into
SMA-58-BSA-V2-class
from
SMA-46-Multichain-Validation-Module
Aug 22, 2023
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c49217c
init
livingrockrises 1d87be7
signUserOps in multichain validation module
livingrockrises 6a7ff6c
type change
livingrockrises 0cc977e
dev notes
livingrockrises da0015c
updated constants
livingrockrises a0bebd8
dev notes + update multichain signing
livingrockrises f67e339
fix: signing issue
livingrockrises 24dd399
make dummy sig dynamic based on module address
livingrockrises 1b8581c
refactor
livingrockrises bf4479e
make multichain validation module not inherit from ecdsa
livingrockrises File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,103 @@ | ||
import { UserOperation, ChainId } from '@biconomy/core-types' | ||
import { Logger, getUserOpHash } from '@biconomy/common' | ||
import { ethers } from 'ethers' | ||
import MerkleTree from 'merkletreejs' | ||
import { ECDSAOwnershipValidationModule } from './ECDSAOwnershipValidationModule' | ||
import { MULTICHAIN_VALIDATION_MODULE_ADDRESSES_BY_VERSION } from './utils/Constants' | ||
import { keccak256, arrayify, defaultAbiCoder, hexConcat, hexZeroPad } from 'ethers/lib/utils' | ||
import { | ||
ECDSAOwnershipValidationModuleConfig, | ||
ModuleVersion, | ||
MultiChainUserOpDto | ||
} from './utils/Types' | ||
export class MultiChainValidationModule extends ECDSAOwnershipValidationModule { | ||
// Review: this.chainId should not be in spec of this class | ||
AmanRaj1608 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// May not inherit from ECDSAOwnershipValidationModule | ||
|
||
constructor(moduleConfig: ECDSAOwnershipValidationModuleConfig) { | ||
super(moduleConfig) | ||
|
||
if (moduleConfig.moduleAddress) { | ||
this.moduleAddress = moduleConfig.moduleAddress | ||
} else if (moduleConfig.version) { | ||
const moduleAddr = MULTICHAIN_VALIDATION_MODULE_ADDRESSES_BY_VERSION[moduleConfig.version] | ||
if (!moduleAddr) { | ||
throw new Error(`Invalid version ${moduleConfig.version}`) | ||
} | ||
this.moduleAddress = moduleAddr | ||
this.version = moduleConfig.version as ModuleVersion | ||
} | ||
} | ||
|
||
getDummySignature(): string { | ||
const moduleAddress = ethers.utils.getAddress(this.getAddress()) | ||
const dynamicPart = moduleAddress.substring(2).padEnd(40, '0') | ||
return `0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000${dynamicPart}000000000000000000000000000000000000000000000000000000000000004181d4b4981670cb18f99f0b4a66446df1bf5b204d24cfcb659bf38ba27a4359b5711649ec2423c5e1247245eba2964679b6a1dbb85c992ae40b9b00c6935b02ff1b00000000000000000000000000000000000000000000000000000000000000` | ||
} | ||
|
||
async signUserOp(userOp: UserOperation): Promise<string> { | ||
Logger.log('userOp', userOp) | ||
throw new Error('Method not implemented.') | ||
} | ||
|
||
async signUserOps(multiChainUserOps: MultiChainUserOpDto[]): Promise<UserOperation[]> { | ||
const leaves: string[] = [] | ||
|
||
// TODO | ||
const validUntil = 0 // unlimited | ||
const validAfter = 0 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these should be taken by the user as param There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// TODO // error handling | ||
|
||
// Iterate over each userOp and process them | ||
for (const multiChainOp of multiChainUserOps) { | ||
const leaf = hexConcat([ | ||
hexZeroPad(ethers.utils.hexlify(validUntil), 6), | ||
hexZeroPad(ethers.utils.hexlify(validAfter), 6), | ||
hexZeroPad( | ||
getUserOpHash(multiChainOp.userOp, this.entryPointAddress, multiChainOp.chainId), | ||
32 | ||
) | ||
]) | ||
|
||
leaves.push(keccak256(leaf)) | ||
} | ||
|
||
// Create a new Merkle tree using the leaves array | ||
const merkleTree = new MerkleTree(leaves, keccak256, { sortPairs: true }) | ||
|
||
const multichainSignature = await this.signer.signMessage(arrayify(merkleTree.getHexRoot())) | ||
|
||
// Create an array to store updated userOps | ||
const updatedUserOps: UserOperation[] = [] | ||
|
||
Logger.log('merkle root ', merkleTree.getHexRoot()) | ||
|
||
for (let i = 0; i < leaves.length; i++) { | ||
const merkleProof = merkleTree.getHexProof(leaves[i]) | ||
|
||
Logger.log('merkle proof ', merkleProof) | ||
|
||
// Create the moduleSignature | ||
const moduleSignature = defaultAbiCoder.encode( | ||
['uint48', 'uint48', 'bytes32', 'bytes32[]', 'bytes'], | ||
[validUntil, validAfter, merkleTree.getHexRoot(), merkleProof, multichainSignature] | ||
) | ||
|
||
// add validation module address to the signature | ||
const signatureWithModuleAddress = defaultAbiCoder.encode( | ||
['bytes', 'address'], | ||
[moduleSignature, this.getAddress()] | ||
) | ||
|
||
// Update userOp with the final signature | ||
const updatedUserOp: UserOperation = { | ||
...(multiChainUserOps[i].userOp as UserOperation), | ||
signature: signatureWithModuleAddress | ||
} | ||
|
||
updatedUserOps.push(updatedUserOp) | ||
} | ||
return updatedUserOps | ||
} | ||
} |
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,6 +1,6 @@ | ||
export * from './interfaces/IValidationModule' | ||
export * from './BaseValidationModule' | ||
export * from './ECDSAOwnershipValidationModule' | ||
export * from './MultichainValidationModule' | ||
// export * from './SessionKeyManagerModule' | ||
// export * from './MultiChainValidationModule' | ||
// export * from './PasskeyValidationModule' |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AmanRaj1608 @tomarsachin2271 since it extends the ECDSAModule chainId becomes mandatory but in real sense this module itself doesn't need to maintain chainId as it will receive it as part of dto (array of objects - userop + chainId) in singUserOps method.
what should I do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the extend part as the
MultiChainValidationModule
is different module and not really depends on ECDSAOwnershipValidationModuleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok let me do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done