Skip to content

Commit

Permalink
Change hash function from the MD5 to the SHA256
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrom131 committed Nov 15, 2024
1 parent c6aa722 commit 5f2a383
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solarity/hardhat-zkit",
"version": "0.5.1",
"version": "0.5.2",
"description": "The ultimate TypeScript environment for Circom development",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/core/dependencies/CircomFilesResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
import { assertHardhatInvariant, HardhatError } from "hardhat/internal/core/errors";
import { ERRORS } from "hardhat/internal/core/errors-list";
import { getRealPath } from "hardhat/internal/util/fs-utils";
import { createNonCryptographicHashBasedIdentifier } from "hardhat/internal/util/hash";

import { CircomFilesParser } from "./parser/CircomFilesParser";
import { CIRCOM_FILE_REG_EXP, NODE_MODULES, NODE_MODULES_REG_EXP, URI_SCHEME_REG_EXP } from "../../constants";
import { getSHA256Hash } from "../../utils";
import { HardhatZKitError } from "../../errors";

import {
Expand Down Expand Up @@ -385,7 +385,7 @@ export class CircomFilesResolver {
const stats = await fsExtra.stat(absolutePath);
const lastModificationDate = new Date(stats.ctime);

const contentHash = createNonCryptographicHashBasedIdentifier(Buffer.from(rawContent)).toString("hex");
const contentHash = getSHA256Hash(rawContent);

const fileData = this._parser.parse(rawContent, absolutePath, contentHash);

Expand Down
11 changes: 8 additions & 3 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import fsExtra from "fs-extra";
import https from "https";
import { createHash } from "crypto";
import { exec } from "child_process";

import * as snarkjs from "snarkjs";

import { createNonCryptographicHashBasedIdentifier } from "hardhat/internal/util/hash";

import { ProvingSystemType } from "@solarity/zkit";

import { Reporter } from "../reporter";
Expand Down Expand Up @@ -105,7 +104,13 @@ export async function execCall(execFile: string, callArgs: string[]): Promise<Ex
}

export function getFileHash(filePath: string): string {
return createNonCryptographicHashBasedIdentifier(Buffer.from(fsExtra.readFileSync(filePath))).toString("hex");
return getSHA256Hash(fsExtra.readFileSync(filePath, "utf-8"));
}

export function getSHA256Hash(rawFileData: string): string {
const fileData: Buffer = Buffer.from(rawFileData);

return createHash("sha256").update(fileData).digest().toString("hex");
}

export function getUniqueProvingSystems(provingSystems: ProvingSystemType | ProvingSystemType[]): ProvingSystemType[] {
Expand Down

0 comments on commit 5f2a383

Please sign in to comment.