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

Anvil zksync does not emulate node behavior in at least one case: nonce too low #526

Open
alphathis opened this issue Jan 9, 2025 · 0 comments

Comments

@alphathis
Copy link

🐛 Bug Report for anvil-zksync

When a transaction is sent that fails for an issue such as 'nonce too low' on Abstract testnet, an error response is returned which, when using ethers v6.13.1 will cause an error to be thrown. The ethers behavior is secondary to this issue, i mention it because the specific behavior of a package like ethers is important for developers when designing around block chain systems. This error response is not returned by anvil zksync for such a transaction when running in fork mode. When sent with an ethers signer, the normal transaction response is returned including a hash.

🔄 Reproduction Steps

  1. run
anvil-zksync --port 8545 fork --fork-url https://api.testnet.abs.xyz
  1. run the below script with a funded abstract testnet account
import { parseEther, TransactionRequest } from "ethers"
import { Provider, Wallet } from "zksync-ethers"
require('dotenv').config()

export const testEthers = async () => {
    const provider = new Provider('https://api.testnet.abs.xyz')
    const localProvider = new Provider('http://localhost:8545')
    const wallet = new Wallet(process.env.TESTNET_PK!, provider)
    const txnType0: TransactionRequest = {
        to: await wallet.getAddress(),
        value: parseEther('0.0001'),
        gasPrice: await provider.getGasPrice(),
        nonce: await wallet.getNonce() - 1,
        gasLimit: 100000,
    }
    const txnType1: TransactionRequest= {
        to: await wallet.getAddress(),
        value: parseEther('0.0001'),
        maxFeePerGas: (await provider.getFeeData()).maxFeePerGas,
        nonce: await wallet.getNonce() - 1,
        gasLimit: 100000,
    }

    try {
        const res1 = await wallet.sendTransaction(txnType0)
        console.log(res1)
    } catch (e) {
        console.log(e)
    }

    try {
        const res2 = await wallet.sendTransaction(txnType1)
        console.log(res2)
    } catch (e) {
        console.log(e)
    }

    const localWallet = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80', localProvider)
    const localtxnType0: TransactionRequest = {
        to: await localWallet.getAddress(),
        value: parseEther('0.0001'),
        gasPrice: await localProvider.getGasPrice()*2n,
        nonce: await localWallet.getNonce() - 1,
        gasLimit: 100000,
        type: 0
    }
    try {
        const res3 = await localWallet.sendTransaction(localtxnType0)
        console.log(res3)
    } catch (e) {
        console.log(e)
    }
}

testEthers()

🤔 Expected Behavior

  1. send a txn with too low of a nonce.
  2. network returns error response:
{
  jsonrpc: "2.0",
  error: {
    code: 3,
    message: "nonce too low. allowed nonce range: 6 - 26, actual: 5",
    data: "0x",
  },
  id: 17,
}

expected logs:

Error: nonce too low. allowed nonce range: 6 - 26, actual: 5 (payload={ "id": 22, "jsonrpc": "2.0", "method": "eth_sendRawTransaction", "params": [ "0x71f88f058408c628bc8408c628bc830186a094fe95eefb9993fdfe8c397fe986b95f4e56bbf210865af3107a400080822b748080822b7494fe95eefb9993fdfe8c397fe986b95f4e56bbf21009c0b841bde7b6d29348a574aa83b7b4aaab12191c2c27b2c4798640457ecb14878e3f71147c536296e52b31a8ef4925d620f7b335cf5cffb51185aa4b5efcc4650e3cc01cc0" ] }, error={ "code": 3, "data": "0x", "message": "nonce too low. allowed nonce range: 6 - 26, actual: 5" }, code=3, version=6.13.4)
    at makeError (/Users/matthewrivas/Programming/Alphabot/Paymaster/node_modules/ethers/src.ts/utils/errors.ts:694:21)
    at Provider.getRpcError (/Users/matthewrivas/Programming/Alphabot/Paymaster/node_modules/zksync-ethers/src/provider.ts:2394:21)
    at /Users/matthewrivas/Programming/Alphabot/Paymaster/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:563:45
    at processTicksAndRejections (node:internal/process/task_queues:105:5) {
  code: 3,
  payload: {
    method: 'eth_sendRawTransaction',
    params: [
      '0x71f88f058408c628bc8408c628bc830186a094fe95eefb9993fdfe8c397fe986b95f4e56bbf210865af3107a400080822b748080822b7494fe95eefb9993fdfe8c397fe986b95f4e56bbf21009c0b841bde7b6d29348a574aa83b7b4aaab12191c2c27b2c4798640457ecb14878e3f71147c536296e52b31a8ef4925d620f7b335cf5cffb51185aa4b5efcc4650e3cc01cc0'
    ],
    id: 22,
    jsonrpc: '2.0'
  },
  error: {
    code: 3,
    message: 'nonce too low. allowed nonce range: 6 - 26, actual: 5',
    data: '0x'
  },
  shortMessage: 'nonce too low. allowed nonce range: 6 - 26, actual: 5'
}

😯 Current Behavior

anvil returns a response indicating success and a txn hash rather than an error response. the transaction fails with logs:

zkSync Node Output: 17:52:02  INFO 
17:52:02  INFO ⏸️  [HALTED] Hash: 0x70d4afc8055cff4b1b3bd3fe04bdbed567cef67ba1e10f14f6812e9ce661e244
17:52:02  INFO Initiator: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
17:52:02  INFO Payer: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
17:52:02  INFO Gas Limit: 100_000 | Used: 100_000 | Refunded: 0
17:52:02  INFO Paid: 0.0000084677 ETH (100000 gas * 0.08467655 gwei)
17:52:02  INFO Refunded: 0.0000000000 ETH
17:52:02  INFO 
17:52:02 ERROR Error while executing transaction: Transaction HALT: Account validation error: Error function_selector = 0xe90aded4, data = 0xe90aded4000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb922660000000000000000000000000000000000000000000000000000000000000019

this indicates the transaction is being bailed at #

anyhow::bail!("Transaction HALT: {reason}");
during execution rather than erroring in validation or elsewhere before the response containing the hash is returned.

🖥️ Environment

cargo 1.81.0 (2dbb1af80 2024-08-20)

  • Operating System & Version: macOs Sonoma 14.6.1 (23G93)
  • Other relevant environment details:
  • anvil-zksync version: 0.2.2
  • zksync-ethers: 6.13.1
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

1 participant