question: are the blobVersionedHash and commitment hash always unique?
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.
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 :thinking:
okay, figure that out too haha... :laughing:
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
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.