Skip to content

Issue with Committing Updated Data: "wrong merkle root" Error #113

Description

@w-toguchi83

Hello,

I encountered an issue while working with the provided tutorial code for updating data in the zkDB using zkRollup. After successfully committing initial data, attempting to update a record (specifically changing "Bob's" age from 10 to 15) results in a "wrong merkle root" error during the commit phase.

Steps to Reproduce:

  1. Initialize and commit initial data to the DB.
  2. Update the age of "Bob" from 10 to 15.
  3. Attempt to commit the updated data.

Expected Result: The updated data is committed without errors, and querying "Bob's" age should return the updated value (15).

Actual Result: The commit fails with an error: "VM Exception while processing transaction: reverted with reason string 'wrong merkle root'".

I followed the documentation closely and ensured the setup for SMT levels and configurations were as recommended. Is there a specific procedure for updating data that I might have missed, or could this be a bug in the commit logic?

Thank you for looking into this issue.

    db = new DB({
      level: 100,
      size_path: 5,
      size_val: 5,
      size_json: 256,
      size_txs:10,
      level_col: 8,
      wasmRU: resolve(__dirname, "../../zkjson/circom/build/circuits/rollup/index_js/index.wasm"),
      zkeyRU: resolve(__dirname, "../../zkjson/circom/build/circuits/rollup/index_0001.zkey"),
      wasm: resolve(__dirname, "../../zkjson/circom/build/circuits/db/index_js/index.wasm"),
      zkey: resolve(__dirname, "../../zkjson/circom/build/circuits/db/index_0001.zkey"),
    });
    await db.init();

    col_id = await db.addCollection();

    const people = [
      { name: "Bob", age: 10 },
      { name: "Alice", age: 20 },
      { name: "Mike", age: 30 },
      { name: "Beth", age:40 },
    ]
    let txs = people.map(v => { return [col_id, v.name, v] })

    // batch commit write queries
    const zkp = await db.genRollupProof(txs);
    await myru.commit(zkp);

    // query Bob's age
    const zkp2 = await db.genProof({ json: people[0], col_id, path: "age", id: "Bob" });
    expect((await myru.qInt([col_id, toIndex("Bob"), ...path("age")], zkp2))).to.eql(10n)

     // How to update ?
    const people2 = [
      { name: "Bob", age: 15 }, // change age
      { name: "Alice", age: 20 },
      { name: "Mike", age: 30 },
      { name: "Beth", age:40 },
    ]
    txs = people2.map(v => { return [col_id, v.name, v] })
    const zkp3 = await db.genRollupProof(txs);
    await myru.commit(zkp3);
    // commit is faild.
    // Error: VM Exception while processing transaction: reverted with reason string 'wrong merkle root'
    // at MyRollup.commit (zkjson/contracts/ZKRollup.sol:29)

    const zkp4 = await db.genProof({ json: people2[0], col_id, path: "age", id: "Bob" });
    expect((await myru.qInt([col_id, toIndex("Bob"), ...path("age")], zkp4))).to.eql(15n)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions