zksync-sdk / zksync2-python

zksync2 is a web3.py library adapted to work with the ZKsync Era.
Apache License 2.0
323 stars 199 forks source link

Example deposit testnet transaction fails on chain: "Fail with error 'qp'" #19

Closed driesvb closed 9 months ago

driesvb commented 1 year ago

Hi everyone

I am trying out the Deposit example (https://github.com/zksync-sdk/zksync2-python/blob/master/examples/01_deposit.py). However, the processed transaction fails on chain with the error "Fail with error 'qp'" (example transaction: https://goerli.etherscan.io/tx/0xfd2e00f9bec156ba7bf5fdfcbfd4a4e178a3907993a723e8b871db7406111183).

Reproducable code

from eth_account import Account
from eth_account.signers.local import LocalAccount
from web3 import Web3

from zksync2.core.types import Token, EthBlockParams
from zksync2.module.module_builder import ZkSyncBuilder
from zksync2.provider.eth_provider import EthereumProvider

PRIVATE_KEY = open("./private-keys/testnet-test-account.key", "r").read()
ZKSYNC_TEST_URL = "https://zksync2-testnet.zksync.dev"
RCP_ENDPOINT = "https://rpc.ankr.com/eth_goerli/<REDACTED API KEY>"

def deposit(amount: float):
    zksync = ZkSyncBuilder.build(ZKSYNC_TEST_URL)
    eth_web3 = Web3(Web3.HTTPProvider(RCP_ENDPOINT))
    account: LocalAccount = Account.from_key(PRIVATE_KEY)
    eth_provider = EthereumProvider(zksync, eth_web3, account)
    wei_amount = Web3.to_wei(amount, "ether")
    eth_token = Token.create_eth()
    gas_price = eth_web3.eth.gas_price
    before_deposit = eth_provider.get_l1_balance(eth_token, EthBlockParams.LATEST)

    print(f"Before: {before_deposit}")

    l1_tx_receipt = eth_provider.deposit(token=Token.create_eth(),
                                         amount=wei_amount,
                                         gas_price=gas_price)
    print(l1_tx_receipt)

if __name__ == "__main__":
    deposit(0.01)

Any ideas? Could it be the suggested gas constants in the SDK?

dayout1024 commented 1 year ago

I'am getting this error too, can anyone help with this?

sparck69 commented 1 year ago

I'am getting this error too, can anyone help with this?

I think its just broken rn

danijelTxFusion commented 1 year ago

The 0.5.0 version of SDK has been released and should fix this issue. Here is the example how to deposit assets to zksync.

dayout1024 commented 1 year ago

The 0.5.0 version of SDK has been released and should fix this issue. Here is the example how to deposit assets to zksync.

still same error, Fail with error 'mv'

danijelTxFusion commented 1 year ago

The 0.5.0 version of SDK has been released and should fix this issue. Here is the example how to deposit assets to zksync.

still same error, Fail with error 'mv'

I successfully ran the deposit example on the Goerli testnet and ZkSync Era testnet without any issues.

L1 transaction: 0x24c3932a7c5aacbe5896007ea0c2ed3e609b43264c4c00e0af42bfb8b6518025 L2 transaction: 0x9b2a1c76786f50383d66e155ff1321968ef734ad25d87dfb818ded31b9a0d247

The mv error code in smart contract indicates that specified transaction value is lower than deposit transaction fee (tx value < base cost + l2Value). The deposit function in sdk follows the same logic, so transaction value is calculated correctly.

The possible issue here is that the base cost might have increased due to the high traffic on the Goerli testnet, which has been ongoing for some time.

I also noticed in the posted example that a custom RPC endpoint is used to submit the deposit transaction. There might be a possibility that, due to high traffic, the custom RPC node experiences latency and is temporarily out of sync. This situation could result in the calculation of an outdated base cost for the transaction.

lusharenck commented 1 year ago

The 0.5.0 version of SDK has been released and should fix this issue. Here is the example how to deposit assets to zksync.

still same error, Fail with error 'mv'

I successfully ran the deposit example on the Goerli testnet and ZkSync Era testnet without any issues.

L1 transaction: 0x24c3932a7c5aacbe5896007ea0c2ed3e609b43264c4c00e0af42bfb8b6518025 L2 transaction: 0x9b2a1c76786f50383d66e155ff1321968ef734ad25d87dfb818ded31b9a0d247

The mv error code in smart contract indicates that specified transaction value is lower than deposit transaction fee (tx value < base cost + l2Value). The deposit function in sdk follows the same logic, so transaction value is calculated correctly.

The possible issue here is that the base cost might have increased due to the high traffic on the Goerli testnet, which has been ongoing for some time.

I also noticed in the posted example that a custom RPC endpoint is used to submit the deposit transaction. There might be a possibility that, due to high traffic, the custom RPC node experiences latency and is temporarily out of sync. This situation could result in the calculation of an outdated base cost for the transaction.

This is the correct solution

This is the solution your team found, but the solution was not updated to the latest code package. I lost hundreds of dollars using the 0.5.0 version of the package because of this

The solution is in this github link: https://github.com/zksync-sdk/zksync2-python/issues/10#issuecomment-1496664167

petarTxFusion commented 9 months ago

This is fixed in the next release. This is how we are calculating value now.

gas_price_for_estimation: int
        if transaction.max_priority_fee_per_gas is not None:
            gas_price_for_estimation = transaction.max_fee_per_gas
        else:
            gas_price_for_estimation = transaction.gas_price

        base_cost = self.get_base_cost(transaction.l2_gas_limit, transaction.gas_per_pubdata_byte, gas_price_for_estimation)

        if transaction.token.is_eth():
            transaction.value = base_cost + transaction.operator_tip + transaction.amount
        else:
            transaction.value = base_cost + transaction.operator_tip

        check_base_cost(base_cost, transaction.value)