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

Authorizing new public key just works on Ropsten and not on the mainnet !! #252

Closed
RasoulKhajavi opened this issue Nov 5, 2020 · 8 comments

Comments

@RasoulKhajavi
Copy link

RasoulKhajavi commented Nov 5, 2020

Here is my code :


const walletPrivateKey = new ethers.Wallet(PrivateKey) ;
const ethWallet = await walletPrivateKey.connect(ethersProvider);
const syncWallet = await zksync.Wallet.fromEthSigner(ethWallet, syncProvider);

if (! await syncWallet.isSigningKeySet()) {
    const onchainAuthTransaction = await syncWallet.onchainAuthSigningKey();
    // Wait till transaction is committed on ethereum.
    await onchainAuthTransaction.wait();

    const changePubkey= await syncWallet.setSigningKey({
        feeToken: "ETH",
        fee: ethers.utils.parseEther("0.001")
    });
    // Wait till transaction is committed 
    const receipt = await changePubkey.awaitReceipt();
}

Error for the same code on mainnet network :

Error: insufficient funds for intrinsic transaction cost (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{"jsonrpc":"2.0","id":46,"error":{"code":-32000,"message":"insufficient funds for gas * price + value"}}","error":{"code":-32000},"requestBody":"{"method":"eth_sendRawTransaction","params": ......


syncWallet.onchainAuthSigningKey();
this function perfectly works on ropsten but not on mainnet!
is this issue arising from my code or library somehow has an issue ?
thanks for your help in advance.

@popzxc
Copy link
Member

popzxc commented Nov 6, 2020

Well, the error tells that your Ethereum account doesn't have enough funds to authorize ChangePubKey operation onchain.

onchainAuthSigningKey method sends a L1 transaction which authorizes ChangePubKey operation in the zkSync smart contract.
Does the account for which you're trying to execute this code have enough funds?

@RasoulKhajavi
Copy link
Author

Thanks @popzxc for your answer
Do you mean my ETH mainnet wallet should have funds?
Well my sync wallet has enough funds both ETH and HEX token , shouldn't it be able to Authorize new pubkey with the funds of the sync wallet? How can I achieve that?

@popzxc
Copy link
Member

popzxc commented Nov 6, 2020

You invoke syncWallet.onchainAuthSigningKey() in your code.
This method is used to authorize ChangePubKey operation in the L1 (Ethereum). So, this method sends an Ethereum transaction, and for it to be executed, you should have funds on your Ethereum wallet.

If you want to perform ChangePubKey operation in L2 (zkSync) and you have access to your private key (which it seems you have, since in your example you create ethers.Wallet from private key), then you don't need to call syncWallet.onchainAuthSigningKey() at all: with a private key, this operation will use funds from your L2 account.

@RasoulKhajavi
Copy link
Author

RasoulKhajavi commented Nov 6, 2020

well if i don't call syncWallet.onchainAuthSigningKey() in my code i get this error :
(node:10868) UnhandledPromiseRejectionWarning: Error: zkSync API response error: code 203; message: Change pubkey tx is not authorized onchain

@popzxc
Copy link
Member

popzxc commented Nov 6, 2020

  1. Do you create a wallet from a private key, or are you using some kind of a smart wallet which manages your private key?
  2. Do you call setSigningKey the same way as you specified in sample above?
    const changePubkey= await syncWallet.setSigningKey({
        feeToken: "ETH",
        fee: ethers.utils.parseEther("0.001")
    });

This error ("Change pubkey tx is not authorized onchain") makes me think that you provided an onchainAuth: true argument to this call.

@RasoulKhajavi
Copy link
Author

RasoulKhajavi commented Nov 6, 2020

yes i do ,here is the whole code :

const walletPrivateKey = new ethers.Wallet(PrivateKey) ;
const ethWallet = await walletPrivateKey.connect(ethersProvider);
const syncWallet = await zksync.Wallet.fromEthSigner(ethWallet, syncProvider);

if (! await syncWallet.isSigningKeySet()) {

   const changePubkey= await syncWallet.setSigningKey({
        feeToken: "ETH",
        fee: ethers.utils.parseEther("0.001")
   });
   // Wait till transaction is committed
   const receipt = await changePubkey.awaitReceipt(); 
}

@popzxc
Copy link
Member

popzxc commented Nov 6, 2020

That looks pretty odd. This kind of error is returned if ChangePubKey transaction was sent without an Ethereum signature.
As you can see in the source code, Ethereum signature isn't added only if onchainAuth argument was passed and its value is true: relevant code in setSigningKey, relevant code in signing method.

Thus, if onchainAuth argument wasn't passed, sent transaction should not result in the error you provided above.

Is this code snippet is a complete piece of code you're running (apart of PrivateKey setting part, of course), or is there something else being executed?

@RasoulKhajavi
Copy link
Author

yeah it is odd ... that's what i'm trying to figure out .

the purpose of this code is to just Authorize the account and literally this is all of the code ( except for those lines of importing libraries and initializing providers)

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

No branches or pull requests

3 participants