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

question: are the blobVersionedHash and commitment hash always unique? #337

Open
tunnckoCore opened this issue Mar 14, 2024 · 3 comments
Open

Comments

@tunnckoCore
Copy link

tunnckoCore commented Mar 14, 2024

I mean, if i send 2 transactions with the same blob, will their blob hash and or commitment match?

How you track "unique blobs"? Can we have such endpoint?

I kinda want some endpoint to check based on versioneHash, transaction hash, or the hexed data that's submitted.

@tunnckoCore
Copy link
Author

Okay, i figured out that the blob hashes are the same if the blob content is the same, cool.

BUT, how can we calculate these hashes? I read that it's sha256 of the KZG, but what specifically? Can we do it from the hex data, without any much processing?

cc @PJColombo 🤔

@tunnckoCore
Copy link
Author

tunnckoCore commented Mar 15, 2024

okay, figure that out too haha... 😆

import { sha256, blobsToCommitments, toBlobs, setupKzg, stringToHex } from "viem";
// import { mainnetTrustedSetupPath } from "viem/node";
import * as cKzg from "c-kzg";

export const kzg = setupKzg(
	cKzg,
	// mainnetTrustedSetupPath
	"./node_modules/viem/trusted-setups/mainnet.json"
);

const blobs = toBlobs({ data: stringToHex("data:,hello world") });
const commitments = blobsToCommitments({ blobs, kzg });

// demo blob
const kzg_commitment = `0x94b54333b009e1e0f12f46282dfd786d5a9a8c17090341430fe265c5cfd493372459d6ec2b33d6af7cbcef92a934e9eb`;
const blob_hash = `0x01b0eb9326690d1dc82e34a5eccefca7713d078d1d0a2a56521d2cbab9ca820a`;
const sha_of_comm = sha256(kzg_commitment).slice(2); // first 2 are `0x`

console.log("commitments", commitments);
console.log(sha_of_comm);
console.log(blob_hash);
console.log(blob_hash === "0x01" + sha_of_comm.slice(2));

for someone else if needed

@PJColombo
Copy link
Member

PJColombo commented Mar 29, 2024

Hi @tunnckoCore. Again, sorry for the late reply but I suppose you didn't need me at all to begin with 😅.

Yes, everything you said it's correct.

A blob hash is the versioned hash of the kzg commitment. The version is contained in the first byte of the hash and the rest of it contains the hashed commitment (see here). You can find the rationale behind it here

You can find the rationale behind using kzg commitments here.

How do you track "unique blobs"? Is there an endpoint for this?

Our database schema defines a blob table where we store only unique blobs.

The many-to-many relational table blobs_on_transactions tracks each blob contained in a transaction.

Currently, our /blobs endpoint returns data from a join between the relational table and the blob table, so it does not return unique blobs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants