Use BYTES_PER_FIELD_ELEMENT

This commit is contained in:
dancoffman 2022-11-04 11:44:57 -07:00
parent 8ca4fd9e83
commit ac65930b15
No known key found for this signature in database
GPG Key ID: 47B1F53E36A9B3CC
5 changed files with 8 additions and 9 deletions

View File

@ -135,7 +135,7 @@ Napi::Value BlobToKzgCommitment(const Napi::CallbackInfo& info) {
Polynomial polynomial; Polynomial polynomial;
for (size_t i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++) for (size_t i = 0; i < FIELD_ELEMENTS_PER_BLOB; i++)
bytes_to_bls_field(&polynomial[i], &blob[i * BYTES_PER_FIELD]); bytes_to_bls_field(&polynomial[i], &blob[i * BYTES_PER_FIELD_ELEMENT]);
KZGCommitment commitment; KZGCommitment commitment;
blob_to_kzg_commitment(&commitment, polynomial, kzg_settings); blob_to_kzg_commitment(&commitment, polynomial, kzg_settings);
@ -168,7 +168,7 @@ Napi::Value ComputeAggregateKzgProof(const Napi::CallbackInfo& info) {
for (size_t field_index = 0; field_index < FIELD_ELEMENTS_PER_BLOB; field_index++) { for (size_t field_index = 0; field_index < FIELD_ELEMENTS_PER_BLOB; field_index++) {
bytes_to_bls_field( bytes_to_bls_field(
&polynomial[blob_index][field_index], &polynomial[blob_index][field_index],
&blob_bytes[field_index * BYTES_PER_FIELD] &blob_bytes[field_index * BYTES_PER_FIELD_ELEMENT]
); );
} }
} }
@ -222,7 +222,7 @@ Napi::Value VerifyAggregateKzgProof(const Napi::CallbackInfo& info) {
// Populate the polynomial with a BLS field for each field element in the blob // Populate the polynomial with a BLS field for each field element in the blob
for (size_t field_index = 0; field_index < FIELD_ELEMENTS_PER_BLOB; field_index++) { for (size_t field_index = 0; field_index < FIELD_ELEMENTS_PER_BLOB; field_index++) {
bytes_to_bls_field(&polynomial[blob_index][field_index], &blob_bytes[field_index * BYTES_PER_FIELD]); bytes_to_bls_field(&polynomial[blob_index][field_index], &blob_bytes[field_index * BYTES_PER_FIELD_ELEMENT]);
} }
// Extract a G1 point for each commitment // Extract a G1 point for each commitment
@ -358,7 +358,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
// Constants // Constants
exports["FIELD_ELEMENTS_PER_BLOB"] = Napi::Number::New(env, FIELD_ELEMENTS_PER_BLOB); exports["FIELD_ELEMENTS_PER_BLOB"] = Napi::Number::New(env, FIELD_ELEMENTS_PER_BLOB);
exports["BYTES_PER_FIELD"] = Napi::Number::New(env, BYTES_PER_FIELD); exports["BYTES_PER_FIELD_ELEMENT"] = Napi::Number::New(env, BYTES_PER_FIELD_ELEMENT);
return exports; return exports;
} }

View File

@ -14,7 +14,7 @@ type SetupHandle = Object;
// The C++ native addon interface // The C++ native addon interface
type KZG = { type KZG = {
FIELD_ELEMENTS_PER_BLOB: number; FIELD_ELEMENTS_PER_BLOB: number;
BYTES_PER_FIELD: number; BYTES_PER_FIELD_ELEMENT: number;
loadTrustedSetup: (filePath: string) => SetupHandle; loadTrustedSetup: (filePath: string) => SetupHandle;
@ -45,7 +45,7 @@ type KZG = {
}; };
export const FIELD_ELEMENTS_PER_BLOB = kzg.FIELD_ELEMENTS_PER_BLOB; export const FIELD_ELEMENTS_PER_BLOB = kzg.FIELD_ELEMENTS_PER_BLOB;
export const BYTES_PER_FIELD = kzg.BYTES_PER_FIELD; export const BYTES_PER_FIELD_ELEMENT = kzg.BYTES_PER_FIELD_ELEMENT;
// Stored as internal state // Stored as internal state
let setupHandle: SetupHandle | undefined; let setupHandle: SetupHandle | undefined;

View File

@ -5,12 +5,12 @@ import {
blobToKzgCommitment, blobToKzgCommitment,
computeAggregateKzgProof, computeAggregateKzgProof,
verifyAggregateKzgProof, verifyAggregateKzgProof,
BYTES_PER_FIELD, BYTES_PER_FIELD_ELEMENT,
FIELD_ELEMENTS_PER_BLOB, FIELD_ELEMENTS_PER_BLOB,
} from "./kzg"; } from "./kzg";
const SETUP_FILE_PATH = "../../src/trusted_setup.txt"; const SETUP_FILE_PATH = "../../src/trusted_setup.txt";
const BLOB_BYTE_COUNT = FIELD_ELEMENTS_PER_BLOB * BYTES_PER_FIELD; const BLOB_BYTE_COUNT = FIELD_ELEMENTS_PER_BLOB * BYTES_PER_FIELD_ELEMENT;
const generateRandomBlob = () => new Uint8Array(randomBytes(BLOB_BYTE_COUNT)); const generateRandomBlob = () => new Uint8Array(randomBytes(BLOB_BYTE_COUNT));

0
inc/.gitignore vendored Normal file
View File

View File

@ -36,7 +36,6 @@ extern "C" {
#define BYTES_PER_COMMITMENT 48 #define BYTES_PER_COMMITMENT 48
#define BYTES_PER_PROOF 48 #define BYTES_PER_PROOF 48
#define BYTES_PER_FIELD 32
#define FIELD_ELEMENTS_PER_BLOB 4096 #define FIELD_ELEMENTS_PER_BLOB 4096
#define BYTES_PER_FIELD_ELEMENT 32 #define BYTES_PER_FIELD_ELEMENT 32
static const uint8_t FIAT_SHAMIR_PROTOCOL_DOMAIN[] = {70, 83, 66, 76, 79, 66, 86, 69, 82, 73, 70, 89, 95, 86, 49, 95}; // "FSBLOBVERIFY_V1_" static const uint8_t FIAT_SHAMIR_PROTOCOL_DOMAIN[] = {70, 83, 66, 76, 79, 66, 86, 69, 82, 73, 70, 89, 95, 86, 49, 95}; // "FSBLOBVERIFY_V1_"