Skip to content

Commit

Permalink
Merge pull request #73 from 0xPolygonHermez/feature/fixMultipleBatche…
Browse files Browse the repository at this point in the history
…sHash

Feature/fix multiple batches hash
  • Loading branch information
krlosMata authored Nov 24, 2022
2 parents 8f92a1a + 28240c9 commit 3ee7983
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 395 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@0xpolygonhermez/zkevm-commonjs",
"description": "Javascript library implementing common utilities for zkevm",
"version": "0.5.0.0",
"version": "0.5.0.1",
"main": "index.js",
"scripts": {
"setup": "npm i",
Expand Down
7 changes: 7 additions & 0 deletions src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = class Processor {
* @param {Number} timestamp - Timestamp of the batch
* @param {Number} chainID - L2 chainID
* @param {Object} vm - vm instance
* @param {Object} options - batch options
* @param {Bool} options.skipUpdateSystemStorage Skips updates on system smrt contract at the end of processable transactions
*/
constructor(
db,
Expand All @@ -45,6 +47,7 @@ module.exports = class Processor {
timestamp,
chainID,
vm,
options,
) {
this.db = db;
this.newNumBatch = numBatch;
Expand Down Expand Up @@ -76,6 +79,7 @@ module.exports = class Processor {
this.evmSteps = [];
this.updatedAccounts = {};
this.isLegacyTx = false;
this.options = options;
}

/**
Expand Down Expand Up @@ -195,6 +199,7 @@ module.exports = class Processor {
const newStorageEntry = {};
const globalExitRootPos = ethers.utils.solidityKeccak256(['uint256', 'uint256'], [smtUtils.h4toString(this.globalExitRoot), Constants.GLOBAL_EXIT_ROOT_STORAGE_POS]);
newStorageEntry[globalExitRootPos] = this.timestamp;

this.currentStateRoot = await stateUtils.setContractStorage(
Constants.ADDRESS_GLOBAL_EXIT_ROOT_MANAGER_L2,
this.smt,
Expand Down Expand Up @@ -470,6 +475,8 @@ module.exports = class Processor {
* Updates system storage with new state root after finishing transaction
*/
async _updateSystemStorage() {
if (this.options.skipUpdateSystemStorage) return;

// Set system addres storage with updated values
const lastTxCount = await stateUtils.getContractStorage(
Constants.ADDRESS_SYSTEM,
Expand Down
7 changes: 5 additions & 2 deletions src/zkevm-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ class ZkEVMDB {
* @param {String} sequencerAddress - ethereum address represented as hex
* @param {Array[Field]} globalExitRoot - global exit root
* @param {Scalar} maxNTx - Maximum number of transactions (optional)
* @param {Object} options - additional batch options
* @param {Bool} options.skipUpdateSystemStorage - Skips updates on system smrt contract at the end of processable transactions
*/
async buildBatch(timestamp, sequencerAddress, globalExitRoot, maxNTx = Constants.DEFAULT_MAX_TX) {
async buildBatch(timestamp, sequencerAddress, globalExitRoot, maxNTx = Constants.DEFAULT_MAX_TX, options = {}) {
return new Processor(
this.db,
this.lastBatch + 1,
Expand All @@ -56,6 +58,7 @@ class ZkEVMDB {
timestamp,
this.chainID,
clone(this.vm),
options,
);
}

Expand Down Expand Up @@ -227,9 +230,9 @@ class ZkEVMDB {
dataVerify.inputSnark = `0x${Scalar.toString(await calculateSnarkInput(
dataVerify.oldStateRoot,
dataVerify.newStateRoot,
dataVerify.newLocalExitRoot,
dataVerify.oldAccInputHash,
dataVerify.newAccInputHash,
dataVerify.newLocalExitRoot,
dataVerify.oldNumBatch,
dataVerify.newNumBatch,
dataVerify.chainID,
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/test-vectors/zkevm-db/recursive.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@
"finalLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"finalAccInputHash": "0x87f958227c38bcf883025f5fda2dee19460cff48ca3c4d48d3a48f55c1258e60",
"finalNumBatch": 2,
"inputSnark": "0x2cd31ede38a42ee7034bf454c07f843db6b20cc0bbac092f3b6a4df2ff037877"
"inputSnark": "0x0aef7431c3060a724238693fea11a846f2d71827f5f64fa24b1dd72b27f8681d"
}
]
248 changes: 0 additions & 248 deletions tools/fill-genesis/create-genesis.js

This file was deleted.

Loading

0 comments on commit 3ee7983

Please sign in to comment.