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

Fix findings from Dmitry's review #508

Merged
merged 21 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bindings/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id "application"
id "java-test-fixtures"
id "me.champeau.jmh" version "0.7.0"
id "com.diffplug.spotless" version "6.17.0"
id "com.diffplug.spotless" version "6.25.0"
}

repositories {
Expand Down Expand Up @@ -45,4 +45,4 @@ spotless {

test {
useJUnitPlatform()
}
}
12 changes: 12 additions & 0 deletions bindings/java/src/main/java/ethereum/ckzg4844/CKZG4844JNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,40 @@ public static void loadNativeLibrary() {
public static final BigInteger BLS_MODULUS =
new BigInteger(
"52435875175126190479447740508185965837690552500527637822603658699938581184513");

/** The number of bytes in a g1 point. */
protected static final int BYTES_PER_G1 = 48;

/** The number of bytes in a g2 point. */
protected static final int BYTES_PER_G2 = 96;

/** The number of bytes in a BLS scalar field element. */
public static final int BYTES_PER_FIELD_ELEMENT = 32;

/** The number of bits in a BLS scalar field element. */
protected static final int BITS_PER_FIELD_ELEMENT = 255;

/** The number of field elements in a blob. */
public static final int FIELD_ELEMENTS_PER_BLOB = 4096;

/** The number of field elements in an extended blob. */
protected static final int FIELD_ELEMENTS_PER_EXT_BLOB = FIELD_ELEMENTS_PER_BLOB * 2;

/** The number of field elements in a cell. */
public static final int FIELD_ELEMENTS_PER_CELL = 64;

/** The number of bytes in a KZG commitment. */
public static final int BYTES_PER_COMMITMENT = 48;

/** The number of bytes in a KZG proof. */
public static final int BYTES_PER_PROOF = 48;

/** The number of bytes in a blob. */
public static final int BYTES_PER_BLOB = FIELD_ELEMENTS_PER_BLOB * BYTES_PER_FIELD_ELEMENT;

/** The number of bytes in a single cell. */
public static final int BYTES_PER_CELL = BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_CELL;

/** The number of cells in an extended blob. */
public static final int CELLS_PER_EXT_BLOB =
FIELD_ELEMENTS_PER_EXT_BLOB / FIELD_ELEMENTS_PER_CELL;
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This directory contains Python bindings for the C-KZG-4844 library.
These bindings require `python3`, `PyYAML` and `make`.
```
sudo apt install python3 python3-pip
python3 -m pip install PyYAML
python3 -m pip install build PyYAML
```

## Build & test
Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/src/bindings/generated.rs

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

3 changes: 0 additions & 3 deletions src/eip4844/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
/** The number of field elements in a blob. */
#define FIELD_ELEMENTS_PER_BLOB 4096

/** The number of field elements in an extended blob */
#define FIELD_ELEMENTS_PER_EXT_BLOB (FIELD_ELEMENTS_PER_BLOB * 2)

/** The number of bytes in a blob. */
#define BYTES_PER_BLOB (FIELD_ELEMENTS_PER_BLOB * BYTES_PER_FIELD_ELEMENT)

Expand Down
5 changes: 4 additions & 1 deletion src/eip4844/eip4844.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <assert.h> /* For assert */
#include <stdlib.h> /* For NULL */
#include <string.h> /* For memcpy */
#include <string.h> /* For memcpy & strlen */

////////////////////////////////////////////////////////////////////////////////////////////////////
// Macros
Expand Down Expand Up @@ -612,6 +612,9 @@ static C_KZG_RET compute_r_powers_for_verify_kzg_proof_batch(
/* Pointer tracking `bytes` for writing on top of it */
uint8_t *offset = bytes;

/* Ensure that the domain string is the correct length */
assert(strlen(RANDOM_CHALLENGE_DOMAIN_VERIFY_BLOB_KZG_PROOF_BATCH) == DOMAIN_STR_LENGTH);

/* Copy domain separator */
memcpy(offset, RANDOM_CHALLENGE_DOMAIN_VERIFY_BLOB_KZG_PROOF_BATCH, DOMAIN_STR_LENGTH);
offset += DOMAIN_STR_LENGTH;
Expand Down
4 changes: 2 additions & 2 deletions src/eip7594/cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
void print_cell(const Cell *cell) {
for (size_t i = 0; i < FIELD_ELEMENTS_PER_CELL; i++) {
const Bytes32 *field = (const Bytes32 *)&cell->bytes[i * BYTES_PER_FIELD_ELEMENT];
print_bytes32(field);
const Bytes32 *element_bytes = (const Bytes32 *)&cell->bytes[i * BYTES_PER_FIELD_ELEMENT];
print_bytes32(element_bytes);
}
}
6 changes: 6 additions & 0 deletions src/eip7594/cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
/** The number of bytes in a single cell. */
#define BYTES_PER_CELL (FIELD_ELEMENTS_PER_CELL * BYTES_PER_FIELD_ELEMENT)

/** The number of field elements in an extended blob. */
#define FIELD_ELEMENTS_PER_EXT_BLOB (FIELD_ELEMENTS_PER_BLOB * 2)

/** The number of cells in a blob. */
#define CELLS_PER_BLOB (FIELD_ELEMENTS_PER_BLOB / FIELD_ELEMENTS_PER_CELL)

/** The number of cells in an extended blob. */
#define CELLS_PER_EXT_BLOB (FIELD_ELEMENTS_PER_EXT_BLOB / FIELD_ELEMENTS_PER_CELL)

Expand Down
Loading
Loading