Skip to content

Commit

Permalink
Merge pull request #337 from 0xPolygonHermez/feature/read-write-final…
Browse files Browse the repository at this point in the history
…-root

set read wrire addresses from final root
  • Loading branch information
ignasirv committed Apr 18, 2024
1 parent ebba680 commit f3d9824
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/sm/sm_main/debug/full-tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/* eslint-disable camelcase */
const fs = require('fs');
const path = require('path');
const { fea2scalar, fea2String } = require('@0xpolygonhermez/zkevm-commonjs').smtUtils;
const { Constants } = require('@0xpolygonhermez/zkevm-commonjs');
const { fea2scalar, fea2String, stringToH4 } = require('@0xpolygonhermez/zkevm-commonjs').smtUtils;
const { Constants, stateUtils } = require('@0xpolygonhermez/zkevm-commonjs');
const { ethers } = require('ethers');
const { Scalar } = require('ffjavascript');
const {
Expand Down Expand Up @@ -89,6 +89,7 @@ class FullTracer {
this.options = options;
this.setTracerOptions();

this.smt = smt;
this.verbose = new Verbose(options.verbose, smt, logFileName);
this.reservedCounters = reservedCounters;

Expand Down Expand Up @@ -143,6 +144,7 @@ class FullTracer {
try {
if (tag.params[0].varName === 'onFinishBatch') {
await this.printStates();
await this.fillInReadWriteAddresses();
}
} catch (e) {
console.log(e);
Expand Down Expand Up @@ -653,9 +655,6 @@ class FullTracer {
cnt_reserve_arithmetics: Number(this.reservedCounters.outOfCountersArith.reserved),
cnt_reserve_binaries: Number(this.reservedCounters.outOfCountersBinary.reserved),
};

// Create output files and dirs
this.exportTrace();
}

/**
Expand Down Expand Up @@ -1004,6 +1003,23 @@ class FullTracer {
}
}

async fillInReadWriteAddresses() {
const keys = Object.keys(this.finalTrace.read_write_addresses);
const rootArray = stringToH4(this.finalTrace.new_state_root);

// get balance and nonce
for (const address of keys) {
const state = await stateUtils.getState(address, this.smt, rootArray);
this.finalTrace.read_write_addresses[address] = {
balance: Scalar.e(state.balance).toString(),
nonce: Number(Scalar.e(state.nonce)).toString(),
};
}

// Create output files and dirs
this.exportTrace();
}

/**
* Export the current trace to a file
*/
Expand Down

0 comments on commit f3d9824

Please sign in to comment.