From 54f7d42121f424d951e13ce61aad88afda9708f6 Mon Sep 17 00:00:00 2001 From: Laia Soler Date: Thu, 25 Apr 2024 16:30:49 +0200 Subject: [PATCH] add hash blobData type 3 --- package.json | 2 +- src/sm/sm_main/sm_main_exec.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3b54b64a..349e1ff8 100644 --- a/package.json +++ b/package.json @@ -185,7 +185,7 @@ "license": "UNLICENSED", "dependencies": { "@0xpolygonhermez/zkasmcom": "github:0xPolygonHermez/zkasmcom#develop-feijoa", - "@0xpolygonhermez/zkevm-commonjs": "github:0xpolygonhermez/zkevm-commonjs#feature/fix-computez", + "@0xpolygonhermez/zkevm-commonjs": "github:0xpolygonhermez/zkevm-commonjs#feature/add-blob-type-3", "@grpc/grpc-js": "^1.8.14", "chalk": "^3.0.0", "circomlib": "^2.0.3", diff --git a/src/sm/sm_main/sm_main_exec.js b/src/sm/sm_main/sm_main_exec.js index d2f21cd6..88887c60 100644 --- a/src/sm/sm_main/sm_main_exec.js +++ b/src/sm/sm_main/sm_main_exec.js @@ -34,6 +34,7 @@ const Prints = require("./debug/prints"); const StatsTracer = require("./debug/stats-tracer"); const Constants = require('./const-sm-main-exec'); const Helpers = require("../../helpers.js"); +const { computeBlobL2HashKData, computeBlobL2HashPData } = require("@0xpolygonhermez/zkevm-commonjs/src/blob-inner/blob-utils.js"); const twoTo255 = Scalar.shl(Scalar.one, 255); const twoTo256 = Scalar.shl(Scalar.one, 256); @@ -158,13 +159,23 @@ module.exports = async function execute(pols, input, rom, config = {}, metadata } else if (blob && (input.blobType === ConstantsBlob.BLOB_TYPE.CALLDATA || input.blobType === ConstantsBlob.BLOB_TYPE.FORCED)) { // Load keccak256BlobData into DB - const blobL2HashData = await ethers.utils.keccak256(input.blobData); + const blobL2HashData = await computeBlobL2HashKData(input.blobData); if (typeof input.blobL2HashData === 'undefined') { input.blobL2HashData = blobL2HashData; } else if (input.blobL2HashData !== blobL2HashData) { throw new Error('input.blobL2HashData != keccak(input.blobData)'); } await db.setProgram(stringToH4(blobL2HashData), hexString2byteArray(input.blobData)); + + } else if (blob && input.blobType === ConstantsBlob.BLOB_TYPE.VALIDIUM) { + // Load poseidonBlobData into DB + const blobL2HashData = await computeBlobL2HashPData(input.blobData); + if (typeof input.blobL2HashData === 'undefined') { + input.blobL2HashData = blobL2HashData; + } else if (input.blobL2HashData !== blobL2HashData) { + throw new Error('input.blobL2HashData != poseidon(input.blobData)'); + } + await db.setProgram(stringToH4(blobL2HashData), hexString2byteArray(input.blobData)); } // load smt const smt = new SMT(db, poseidon, Fr);