Skip to content
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

Txfusion - ZKSync support #1

Open
wants to merge 66 commits into
base: main
Choose a base branch
from

Conversation

ljankovic-txfusion
Copy link
Collaborator

Description

PR for reviewing zksync specific changes

@mshojaei-txfusion mshojaei-txfusion changed the title Txfusion/sending messages Txfusion - ZKSync support Oct 15, 2024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this?

Comment on lines +53 to +65
# Find most recently modified JSON build artifact
if [ "$(uname)" = "Darwin" ]; then
# for local flow
jsonFiles=$(find "$artifactsDir" -type f -name "*.json" -exec stat -f "%m %N" {} \; | sort -rn | head -n 1 | cut -d' ' -f2-)
else
# for CI flow
jsonFiles=$(find "$artifactsDir" -type f -name "*.json" -exec stat -c "%Y %n" {} \; | sort -rn | head -n 1 | cut -d' ' -f2-)
fi

if [ ! -f "$jsonFiles" ]; then
echo 'Failed to find build artifact'
exit 1
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to deduplicate this recently modified artifact finding/checking

Comment on lines 53 to 54
"./artifacts": "./dist/zksync/artifacts/index.js",
"./artifacts/*": "./dist/zksync/artifacts/*.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps ./artifacts -> ./zksync-artifacts/, to leave the door open for other types of VM artifacts

Comment on lines +27 to +38
solidity: {
version: '0.8.19',
settings: {
optimizer: {
enabled: true,
runs: 999_999,
},
},
},
gasReporter: {
currency: 'USD',
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible/worth the effort to reuse solidity/gasReporter/mocha/warnings config from the main hardhat.config.cts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be possible in theory but not worth the effort.

Comment on lines +9 to +10
"@hyperlane-xyz/sdk": "workspace:^",
"@hyperlane-xyz/utils": "workspace:^",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to revert this? it should already be using your local versions of packages

Comment on lines +2 to +3
import { Signer } from 'ethers';
import { Wallet } from 'zksync-ethers';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe say explicitly whether it's ethers/zksync, for easier reading in the rest of the file?

Suggested change
import { Signer } from 'ethers';
import { Wallet } from 'zksync-ethers';
import { Signer as ethersSigner } from 'ethers';
import { Wallet zkSyncWallet } from 'zksync-ethers';

Comment on lines +10 to +11
"@hyperlane-xyz/core": "file:../../solidity",
"@hyperlane-xyz/utils": "workspace:^",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to prev comment, should revert

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the hardhat import might break in published packages, as we only specify it as a dev dependency. also this doesn't seem specific to zksync, and I can't see where this is currently being used

@@ -77,14 +78,14 @@ async function addressToImpersonatedSigner(
* @param key a private key
* @returns a signer for the private key
*/
function privateKeyToSigner(key: string): ethers.Wallet {
function privateKeyToSigner(key: string): Wallet {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we can use zksync ethers here and it'll still be backwards compatible with non-zksync chains?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the testing that we have done so far, zksync wallet is fully compatible with ethers.Wallet. Also, in the getContext function, the function for getting signer is called before MultiProvider is instantiated, so there is not way of passing ProtocolType to the getSigner function.

For now this works, but in the future it would require heavier refactoring for supporting different types of signers per protocol.

@@ -21,10 +21,12 @@ import type {
Transaction as VTransaction,
TransactionReceipt as VTransactionReceipt,
} from 'viem';
import * as zk from 'zksync-ethers';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need everything? would be nice to have it similar to the existing format by only importing the relevant items and adding the zk prefix

e.g

  • zk.Contract ends up being ZKSyncContract or something to that effect
  • zk.types.TransactionRequest -> ZKSyncTransactionRequest

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know there's some differences, but would be good to deduplicate as much as possible with the existing ContractVerifier - perhaps there's an abstract verifier with the base functionality that the default + zksync verifier inherit from

this.addVerificationArtifacts({ chain, artifacts: [verificationInput] });

// try verifying contract
try {
await this.contractVerifier?.verifyContract(chain, verificationInput);
if (isZKSyncChain) {
const verifier = new ZKSyncContractVerifier(this.multiProvider);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set it up once at the start when we set up the base contractVerifier? that we we don't need to create a new one for every verifyContract call

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants