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

Add input param chainId #54

Merged
merged 3 commits into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
"test:counters:storage": "mocha test/counters/storage.js",
"test:all-inputs": "mocha --timeout 0 --max-old-space-size=8000 tools/run-test/run-inputs-mocha.test.js",
"test:gen-parallel": "node tools/run-test/gen-parallel-tests.js",
"test:run-parallel": "mocha --jobs 2 --timeout 0 --max-old-space-size=8000 --parallel tools/run-test/parallel-tests/*.test.js"
"test:run-parallel": "mocha --timeout 0 --max-old-space-size=8000 --parallel tools/run-test/parallel-tests/*.test.js"
},
"author": "Jordi Baylina",
"license": "UNLICENSED",
"dependencies": {
"@0xpolygonhermez/zkasmcom": "https://github.com/0xPolygonHermez/zkasmcom.git#v0.3.0.0",
"@0xpolygonhermez/zkevm-commonjs": "https://github.com/0xpolygonhermez/zkevm-commonjs.git#v0.3.0.0",
"@0xpolygonhermez/zkevm-commonjs": "https://github.com/0xpolygonhermez/zkevm-commonjs.git#v0.4.0.0",
"@0xpolygonhermez/zkevm-rom": "https://github.com/0xpolygonhermez/zkevm-rom.git#v0.3.0.0-rc.1",
"chalk": "^3.0.0",
"circomlib": "^2.0.3",
Expand Down
11 changes: 10 additions & 1 deletion src/sm/sm_main/sm_main_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,8 @@ function eval_functionCall(ctx, tag) {
return eval_getNumBatch(ctx, tag);
} else if (tag.funcName == "getTimestamp") {
return eval_getTimestamp(ctx, tag);
} else if (tag.funcName == "getChainId") {
return eval_getChainId(ctx, tag);
} else if (tag.funcName == "getBatchHashData") {
return eval_getBatchHashData(ctx, tag);
} else if (tag.funcName == "getGlobalExitRoot") {
Expand Down Expand Up @@ -2266,6 +2268,11 @@ function eval_getTimestamp(ctx, tag) {
return [ctx.Fr.e(ctx.input.timestamp), ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero];
}

function eval_getChainId(ctx, tag) {
if (tag.params.length != 0) throw new Error(`Invalid number of parameters function ${tag.funcName}: ${ctx.ln} at ${ctx.fileName}:${ctx.line}`);
return [ctx.Fr.e(ctx.input.chainID), ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero, ctx.Fr.zero];
}

function eval_eventLog(ctx, tag) {
if (tag.params.length < 1) throw new Error(`Invalid number of parameters function ${tag.funcName}: ${ctx.ln} at ${ctx.fileName}:${ctx.line}`);
if(fullTracer) fullTracer.handleEvent(ctx, tag)
Expand Down Expand Up @@ -2684,6 +2691,7 @@ function preprocessTxs(ctx) {
newStateRoot,
globalExitRoot,
timestamp,
chainID
} = ctx.input;

ctx.input.batchHashData = calculateBatchHashData(
Expand All @@ -2699,7 +2707,8 @@ function preprocessTxs(ctx) {
newLocalExitRoot,
ctx.input.batchHashData,
numBatch,
timestamp
timestamp,
chainID
);

ctx.input.accessedStorage = [new Map()]
Expand Down
7 changes: 5 additions & 2 deletions tools/build-genesis/build_genesis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const {
} = require('@0xpolygonhermez/zkevm-commonjs');

// paths files
const pathInput = path.join(__dirname, "../testvectors/input_gen.json");
const pathOutput = path.join(__dirname, "../tools/build-genesis/input_executor.json");
const pathInput = path.join(__dirname, "./input_gen.json");
const pathOutput = path.join(__dirname, "./input_executor.json");

async function main(){
// build poseidon
Expand Down Expand Up @@ -52,6 +52,9 @@ async function main(){
[F.zero, F.zero, F.zero, F.zero], // empty smt
smtUtils.stringToH4(generateData.oldLocalExitRoot),
generateData.genesis,
null,
null,
generateData.chainID
);

// start batch
Expand Down
1 change: 1 addition & 0 deletions tools/build-genesis/input_executor.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@
"globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9",
"numBatch": 1,
"timestamp": 1944498031,
"chainID": 1000,
"contractsBytecode": {}
}
1 change: 1 addition & 0 deletions tools/build-genesis/input_gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"globalExitRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9",
"numBatch": 1,
"timestamp": 1944498031,
"chainID": 1000,
"contractsBytecode": {},
"expectedLeafs": {
"0x0000000000000000000000000000000000000000": {
Expand Down