Update C tests to support minimal config (#263)
This commit is contained in:
parent
b022f30c24
commit
47ddabde63
|
@ -7,6 +7,11 @@ on:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
working-directory: src
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
runs-on: ${{matrix.os}}
|
runs-on: ${{matrix.os}}
|
||||||
|
@ -17,33 +22,76 @@ jobs:
|
||||||
- macos-latest
|
- macos-latest
|
||||||
- windows-latest
|
- windows-latest
|
||||||
steps:
|
steps:
|
||||||
|
# Checkout repository and blst submodule.
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
|
# Check formatting.
|
||||||
|
# Only need to check this once.
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
if: matrix.os == 'ubuntu-latest'
|
if: matrix.os == 'ubuntu-latest'
|
||||||
working-directory: src
|
|
||||||
run: |
|
run: |
|
||||||
make format
|
make format
|
||||||
git diff --exit-code
|
git diff --exit-code
|
||||||
- name: Build/Test
|
|
||||||
working-directory: src
|
# Build and test with minimal preset.
|
||||||
run: make
|
- name: Build (minimal)
|
||||||
|
run: |
|
||||||
|
export FIELD_ELEMENTS_PER_BLOB=4
|
||||||
|
make clean && make test_c_kzg_4844
|
||||||
|
unset FIELD_ELEMENTS_PER_BLOB
|
||||||
|
- name: Save test binary (minimal)
|
||||||
|
if: matrix.os == 'windows-latest'
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: test_minimal_${{matrix.os}}
|
||||||
|
path: src/test_c_kzg_4844.exe
|
||||||
|
- name: Test (minimal)
|
||||||
|
run: make test
|
||||||
|
|
||||||
|
# Build and test with mainnet preset.
|
||||||
|
- name: Build (mainnet)
|
||||||
|
run: |
|
||||||
|
export FIELD_ELEMENTS_PER_BLOB=4096
|
||||||
|
make clean && make test_c_kzg_4844
|
||||||
|
unset FIELD_ELEMENTS_PER_BLOB
|
||||||
|
- name: Save test binary (mainnet)
|
||||||
|
if: matrix.os == 'windows-latest'
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: test_mainnet_${{matrix.os}}
|
||||||
|
path: src/test_c_kzg_4844.exe
|
||||||
|
- name: Test (mainnet)
|
||||||
|
run: make test
|
||||||
|
|
||||||
|
# Run sanitizers.
|
||||||
|
# Doesn't work on Windows.
|
||||||
- name: Clang Sanitizers
|
- name: Clang Sanitizers
|
||||||
if: matrix.os != 'windows-latest'
|
if: matrix.os != 'windows-latest'
|
||||||
working-directory: src
|
|
||||||
run: make sanitize
|
run: make sanitize
|
||||||
|
|
||||||
|
# Run static analyzer.
|
||||||
|
# Doesn't work on Windows.
|
||||||
- name: Clang Static Analyzer
|
- name: Clang Static Analyzer
|
||||||
if: matrix.os != 'windows-latest'
|
if: matrix.os != 'windows-latest'
|
||||||
working-directory: src
|
|
||||||
run: make analyze
|
run: make analyze
|
||||||
|
|
||||||
|
# Install LLVM for coverage report.
|
||||||
|
# Already installed on macOS.
|
||||||
|
# Doesn't work on Windows.
|
||||||
- name: Install LLVM
|
- name: Install LLVM
|
||||||
if: matrix.os == 'ubuntu-latest'
|
if: matrix.os == 'ubuntu-latest'
|
||||||
uses: egor-tensin/setup-clang@v1
|
uses: egor-tensin/setup-clang@v1
|
||||||
|
|
||||||
|
# Generate the coverage report.
|
||||||
|
# Doesn't work on Windows.
|
||||||
- name: Generate coverage report
|
- name: Generate coverage report
|
||||||
if: matrix.os != 'windows-latest'
|
if: matrix.os != 'windows-latest'
|
||||||
working-directory: src
|
|
||||||
run: make coverage
|
run: make coverage
|
||||||
|
|
||||||
|
# Upload the coverage report.
|
||||||
|
# Didn't generate it for Windows.
|
||||||
- name: Save coverage report
|
- name: Save coverage report
|
||||||
if: matrix.os != 'windows-latest'
|
if: matrix.os != 'windows-latest'
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
|
|
|
@ -31,7 +31,6 @@ CFLAGS += -O2 -Wall -Wextra
|
||||||
ifeq ($(PLATFORM),Windows)
|
ifeq ($(PLATFORM),Windows)
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS += -D_CRT_SECURE_NO_WARNINGS
|
CFLAGS += -D_CRT_SECURE_NO_WARNINGS
|
||||||
CFLAGS += -Wl,--stack,8388608 # 8MB
|
|
||||||
else
|
else
|
||||||
CC = clang
|
CC = clang
|
||||||
CFLAGS += -fPIC -Werror
|
CFLAGS += -fPIC -Werror
|
||||||
|
@ -66,7 +65,7 @@ c_kzg_4844.o: c_kzg_4844.c $(BLST_LIBRARY)
|
||||||
@$(CC) $(CFLAGS) -c $<
|
@$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
test_c_kzg_4844: CFLAGS += -O0
|
test_c_kzg_4844: CFLAGS += -O0
|
||||||
test_c_kzg_4844: test_c_kzg_4844.c c_kzg_4844.c
|
test_c_kzg_4844: test_c_kzg_4844.c c_kzg_4844.c $(BLST_LIBRARY)
|
||||||
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
|
|
@ -12,6 +12,22 @@
|
||||||
#include <gperftools/profiler.h>
|
#include <gperftools/profiler.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Macros
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#if FIELD_ELEMENTS_PER_BLOB == 4096
|
||||||
|
#define MAINNET
|
||||||
|
#define TRUSTED_SETUP_FILE "trusted_setup.txt"
|
||||||
|
#define MAX_WIDTH 32
|
||||||
|
#elif FIELD_ELEMENTS_PER_BLOB == 4
|
||||||
|
#define MINIMAL
|
||||||
|
#define TRUSTED_SETUP_FILE "trusted_setup_4.txt"
|
||||||
|
#define MAX_WIDTH 4
|
||||||
|
#else
|
||||||
|
#error FIELD_ELEMENTS_PER_BLOB must be 4096 or 4
|
||||||
|
#endif
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Globals
|
// Globals
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -517,8 +533,13 @@ static void test_blob_to_kzg_commitment__succeeds_expected_commitment(void) {
|
||||||
*/
|
*/
|
||||||
bytes48_from_hex(
|
bytes48_from_hex(
|
||||||
&expected_commitment,
|
&expected_commitment,
|
||||||
|
#ifdef MAINNET
|
||||||
"9815ded2101b6d233fdf31d826ba0557778506df8526f42a"
|
"9815ded2101b6d233fdf31d826ba0557778506df8526f42a"
|
||||||
"87ccd82db36a238b50f8965c25d4484782097436d29e458e"
|
"87ccd82db36a238b50f8965c25d4484782097436d29e458e"
|
||||||
|
#else
|
||||||
|
"95d2d20379b60c353a9c2c75333a5d7d26d5ef5137c5200b"
|
||||||
|
"51bc9d0fd82d0270e98ac9d41a44c366684089e385e815e6"
|
||||||
|
#endif
|
||||||
);
|
);
|
||||||
diff = memcmp(c.bytes, expected_commitment.bytes, BYTES_PER_COMMITMENT);
|
diff = memcmp(c.bytes, expected_commitment.bytes, BYTES_PER_COMMITMENT);
|
||||||
ASSERT_EQUALS(diff, 0);
|
ASSERT_EQUALS(diff, 0);
|
||||||
|
@ -1053,8 +1074,13 @@ static void test_compute_kzg_proof__succeeds_expected_proof(void) {
|
||||||
|
|
||||||
bytes48_from_hex(
|
bytes48_from_hex(
|
||||||
&expected_proof,
|
&expected_proof,
|
||||||
|
#ifdef MAINNET
|
||||||
"899b7e1e7ff2e9b28c631d2f9d6b9ae828749c9dbf84f3f4"
|
"899b7e1e7ff2e9b28c631d2f9d6b9ae828749c9dbf84f3f4"
|
||||||
"3b910bda9558f360f2fa0dac1143460b55908406038eb538"
|
"3b910bda9558f360f2fa0dac1143460b55908406038eb538"
|
||||||
|
#else
|
||||||
|
"a846d83184f6d5b67bbbe905a875f6cfaf1c905e527ea49c"
|
||||||
|
"0616992fb8cce56d202c702b83d6fbe1fa75cacb050ffc27"
|
||||||
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
/* Compare the computed proof to the expected proof */
|
/* Compare the computed proof to the expected proof */
|
||||||
|
@ -1462,9 +1488,13 @@ static void test_verify_kzg_proof_batch__succeeds_round_trip(void) {
|
||||||
const int n_samples = 16;
|
const int n_samples = 16;
|
||||||
Bytes48 proofs[n_samples];
|
Bytes48 proofs[n_samples];
|
||||||
KZGCommitment commitments[n_samples];
|
KZGCommitment commitments[n_samples];
|
||||||
Blob blobs[n_samples];
|
Blob *blobs = NULL;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
|
||||||
|
/* Allocate blobs because they are big */
|
||||||
|
ret = c_kzg_malloc((void **)&blobs, n_samples * sizeof(Blob));
|
||||||
|
ASSERT_EQUALS(ret, C_KZG_OK);
|
||||||
|
|
||||||
/* Some preparation */
|
/* Some preparation */
|
||||||
for (int i = 0; i < n_samples; i++) {
|
for (int i = 0; i < n_samples; i++) {
|
||||||
get_rand_blob(&blobs[i]);
|
get_rand_blob(&blobs[i]);
|
||||||
|
@ -1478,13 +1508,16 @@ static void test_verify_kzg_proof_batch__succeeds_round_trip(void) {
|
||||||
|
|
||||||
/* Verify batched proofs for 0,1,2..16 blobs */
|
/* Verify batched proofs for 0,1,2..16 blobs */
|
||||||
/* This should still work with zero blobs */
|
/* This should still work with zero blobs */
|
||||||
for (int count = 0; count <= 16; count++) {
|
for (int count = 0; count <= n_samples; count++) {
|
||||||
ret = verify_blob_kzg_proof_batch(
|
ret = verify_blob_kzg_proof_batch(
|
||||||
&ok, blobs, commitments, proofs, count, &s
|
&ok, blobs, commitments, proofs, count, &s
|
||||||
);
|
);
|
||||||
ASSERT_EQUALS(ret, C_KZG_OK);
|
ASSERT_EQUALS(ret, C_KZG_OK);
|
||||||
ASSERT_EQUALS(ok, true);
|
ASSERT_EQUALS(ok, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Free the blobs */
|
||||||
|
c_kzg_free(blobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_verify_kzg_proof_batch__fails_with_incorrect_proof(void) {
|
static void test_verify_kzg_proof_batch__fails_with_incorrect_proof(void) {
|
||||||
|
@ -1619,19 +1652,19 @@ static void test_verify_kzg_proof_batch__fails_invalid_blob(void) {
|
||||||
|
|
||||||
static void test_fft_g1__succeeds_round_trip(void) {
|
static void test_fft_g1__succeeds_round_trip(void) {
|
||||||
C_KZG_RET ret;
|
C_KZG_RET ret;
|
||||||
g1_t original[32], transformed[32], inversed[32];
|
g1_t original[MAX_WIDTH], transformed[MAX_WIDTH], inversed[MAX_WIDTH];
|
||||||
|
|
||||||
for (size_t i = 0; i < 32; i++) {
|
for (size_t i = 0; i < MAX_WIDTH; i++) {
|
||||||
get_rand_g1(&original[i]);
|
get_rand_g1(&original[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = fft_g1(transformed, original, false, 32, s.fs);
|
ret = fft_g1(transformed, original, false, MAX_WIDTH, s.fs);
|
||||||
ASSERT_EQUALS(ret, C_KZG_OK);
|
ASSERT_EQUALS(ret, C_KZG_OK);
|
||||||
|
|
||||||
ret = fft_g1(inversed, transformed, true, 32, s.fs);
|
ret = fft_g1(inversed, transformed, true, MAX_WIDTH, s.fs);
|
||||||
ASSERT_EQUALS(ret, C_KZG_OK);
|
ASSERT_EQUALS(ret, C_KZG_OK);
|
||||||
|
|
||||||
for (size_t i = 0; i < 32; i++) {
|
for (size_t i = 0; i < MAX_WIDTH; i++) {
|
||||||
ASSERT(
|
ASSERT(
|
||||||
"same as original", blst_p1_is_equal(&original[i], &inversed[i])
|
"same as original", blst_p1_is_equal(&original[i], &inversed[i])
|
||||||
);
|
);
|
||||||
|
@ -1640,15 +1673,15 @@ static void test_fft_g1__succeeds_round_trip(void) {
|
||||||
|
|
||||||
static void test_fft_g1__n_not_power_of_two(void) {
|
static void test_fft_g1__n_not_power_of_two(void) {
|
||||||
C_KZG_RET ret;
|
C_KZG_RET ret;
|
||||||
g1_t original[32], transformed[32];
|
g1_t original[MAX_WIDTH], transformed[MAX_WIDTH];
|
||||||
|
|
||||||
ret = fft_g1(transformed, original, false, 31, s.fs);
|
ret = fft_g1(transformed, original, false, MAX_WIDTH - 1, s.fs);
|
||||||
ASSERT_EQUALS(ret, C_KZG_BADARGS);
|
ASSERT_EQUALS(ret, C_KZG_BADARGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_fft_g1__n_too_large(void) {
|
static void test_fft_g1__n_too_large(void) {
|
||||||
C_KZG_RET ret;
|
C_KZG_RET ret;
|
||||||
g1_t original[32], transformed[32];
|
g1_t original[MAX_WIDTH], transformed[MAX_WIDTH];
|
||||||
|
|
||||||
ret = fft_g1(transformed, original, false, 2 * s.fs->max_width, s.fs);
|
ret = fft_g1(transformed, original, false, 2 * s.fs->max_width, s.fs);
|
||||||
ASSERT_EQUALS(ret, C_KZG_BADARGS);
|
ASSERT_EQUALS(ret, C_KZG_BADARGS);
|
||||||
|
@ -1799,7 +1832,7 @@ static void setup(void) {
|
||||||
C_KZG_RET ret;
|
C_KZG_RET ret;
|
||||||
|
|
||||||
/* Open the mainnet trusted setup file */
|
/* Open the mainnet trusted setup file */
|
||||||
fp = fopen("trusted_setup.txt", "r");
|
fp = fopen(TRUSTED_SETUP_FILE, "r");
|
||||||
assert(fp != NULL);
|
assert(fp != NULL);
|
||||||
|
|
||||||
/* Load that trusted setup file */
|
/* Load that trusted setup file */
|
||||||
|
|
Loading…
Reference in New Issue