Use pointers for scalars too
This commit is contained in:
parent
2281cce711
commit
aab3df643b
|
@ -833,14 +833,14 @@ void bytes_to_bls_field(BLSFieldElement *out, const uint8_t bytes[32]) {
|
||||||
/**
|
/**
|
||||||
* Compute linear combinations of a sequence of vectors with some scalars
|
* Compute linear combinations of a sequence of vectors with some scalars
|
||||||
*/
|
*/
|
||||||
void vector_lincomb(fr_t out[], const fr_t *vectors[], const fr_t *scalars, uint64_t n, uint64_t m) {
|
void vector_lincomb(fr_t out[], const fr_t* vectors[], const fr_t* scalars[], uint64_t n, uint64_t m) {
|
||||||
fr_t tmp;
|
fr_t tmp;
|
||||||
uint64_t i, j;
|
uint64_t i, j;
|
||||||
for (j = 0; j < m; j++)
|
for (j = 0; j < m; j++)
|
||||||
out[j] = fr_zero;
|
out[j] = fr_zero;
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
for (j = 0; j < m; j++) {
|
for (j = 0; j < m; j++) {
|
||||||
fr_mul(&tmp, &scalars[i], vectors[i * m + j]);
|
fr_mul(&tmp, scalars[i], vectors[i * m + j]);
|
||||||
fr_add(&out[j], &out[j], &tmp);
|
fr_add(&out[j], &out[j], &tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ void free_trusted_setup(KZGSettings *s);
|
||||||
|
|
||||||
void bytes_to_bls_field(BLSFieldElement *out, const uint8_t bytes[32]);
|
void bytes_to_bls_field(BLSFieldElement *out, const uint8_t bytes[32]);
|
||||||
|
|
||||||
void vector_lincomb(BLSFieldElement out[], const BLSFieldElement *vectors[], const BLSFieldElement *scalars, uint64_t num_vectors, uint64_t vector_len);
|
void vector_lincomb(BLSFieldElement out[], const BLSFieldElement* vectors[], const BLSFieldElement* scalars[], uint64_t num_vectors, uint64_t vector_len);
|
||||||
|
|
||||||
void g1_lincomb(KZGCommitment *out, const KZGCommitment points[], const BLSFieldElement scalars[], uint64_t num_points);
|
void g1_lincomb(KZGCommitment *out, const KZGCommitment points[], const BLSFieldElement scalars[], uint64_t num_points);
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ void free_poly_l(poly_l *p);
|
||||||
// kzg_proofs.c
|
// kzg_proofs.c
|
||||||
//
|
//
|
||||||
|
|
||||||
void fr_vector_lincomb(fr_t out[], const fr_t *vectors[], const fr_t *scalars, uint64_t n, uint64_t m);
|
void fr_vector_lincomb(fr_t out[], const fr_t* vectors[], const fr_t* scalars[], uint64_t n, uint64_t m);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the setup and parameters needed for computing KZG proofs.
|
* Stores the setup and parameters needed for computing KZG proofs.
|
||||||
|
|
|
@ -31,14 +31,14 @@
|
||||||
/**
|
/**
|
||||||
* Compute linear combinations of a sequence of vectors with some scalars
|
* Compute linear combinations of a sequence of vectors with some scalars
|
||||||
*/
|
*/
|
||||||
void fr_vector_lincomb(fr_t out[], const fr_t *vectors[], const fr_t *scalars, uint64_t n, uint64_t m) {
|
void fr_vector_lincomb(fr_t out[], const fr_t* vectors[], const fr_t* scalars[], uint64_t n, uint64_t m) {
|
||||||
fr_t tmp;
|
fr_t tmp;
|
||||||
uint64_t i, j;
|
uint64_t i, j;
|
||||||
for (j = 0; j < m; j++)
|
for (j = 0; j < m; j++)
|
||||||
out[j] = fr_zero;
|
out[j] = fr_zero;
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
for (j = 0; j < m; j++) {
|
for (j = 0; j < m; j++) {
|
||||||
fr_mul(&tmp, &scalars[i], vectors[i * m + j]);
|
fr_mul(&tmp, scalars[i], vectors[i * m + j]);
|
||||||
fr_add(&out[j], &out[j], &tmp);
|
fr_add(&out[j], &out[j], &tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -748,20 +748,20 @@ void fr_vector_lincomb_simple_test(void) {
|
||||||
const fr_t* vectors[] = { &v1[0], &v1[1], &v1[2],
|
const fr_t* vectors[] = { &v1[0], &v1[1], &v1[2],
|
||||||
&v2[0], &v2[1], &v2[2] };
|
&v2[0], &v2[1], &v2[2] };
|
||||||
|
|
||||||
fr_t scalars[2] = { fr_zero, fr_one };
|
const fr_t* scalars[2] = { &fr_zero, &fr_one };
|
||||||
fr_vector_lincomb(out, (const fr_t**)vectors, (fr_t*)scalars, n, m);
|
fr_vector_lincomb(out, (const fr_t**)vectors, (const fr_t**)scalars, n, m);
|
||||||
for (i = 0; i < m; i++) {
|
for (i = 0; i < m; i++) {
|
||||||
TEST_CHECK(fr_equal(&out[i], &v2[i]));
|
TEST_CHECK(fr_equal(&out[i], &v2[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
scalars[0] = fr_one; scalars[1] = fr_zero;
|
scalars[0] = &fr_one; scalars[1] = &fr_zero;
|
||||||
fr_vector_lincomb(out, (const fr_t**)vectors, (fr_t*)scalars, n, m);
|
fr_vector_lincomb(out, (const fr_t**)vectors, (const fr_t**)scalars, n, m);
|
||||||
for (i = 0; i < m; i++) {
|
for (i = 0; i < m; i++) {
|
||||||
TEST_CHECK(fr_equal(&out[i], &v1[i]));
|
TEST_CHECK(fr_equal(&out[i], &v1[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
scalars[1] = fr_one;
|
scalars[1] = &fr_one;
|
||||||
fr_vector_lincomb(out, (const fr_t**)vectors, (fr_t*)scalars, n, m);
|
fr_vector_lincomb(out, (const fr_t**)vectors, (const fr_t**)scalars, n, m);
|
||||||
for (i = 0; i < m; i++) {
|
for (i = 0; i < m; i++) {
|
||||||
fr_add(&tmp, &v1[i], &v2[i]);
|
fr_add(&tmp, &v1[i], &v2[i]);
|
||||||
TEST_CHECK(fr_equal(&out[i], &tmp));
|
TEST_CHECK(fr_equal(&out[i], &tmp));
|
||||||
|
|
Loading…
Reference in New Issue