Sitelet https://github.com/erigontech/silkpre/commit/4ee57ebe1b5cb4f25cc8c38a6a87a63bd614efcb
Skip to content

Commit 4ee57eb

Browse files
committed
Encode size as array size
1 parent 7407b9b commit 4ee57eb

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎lib/silkpre/snark.cpp‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ void init_libff() noexcept {
3434
}();
3535
}
3636

37-
Scalar to_scalar(const uint8_t* bytes32_be) noexcept {
37+
Scalar to_scalar(const uint8_t bytes_be[32]) noexcept {
3838
mpz_t m;
3939
mpz_init(m);
40-
mpz_import(m, 32, /*order=*/1, /*size=*/1, /*endian=*/0, /*nails=*/0, bytes32_be);
40+
mpz_import(m, 32, /*order=*/1, /*size=*/1, /*endian=*/0, /*nails=*/0, bytes_be);
4141
Scalar out{m};
4242
mpz_clear(m);
4343
return out;
@@ -49,13 +49,13 @@ static bool valid_element_of_fp(const Scalar& x) noexcept {
4949
return mpn_cmp(x.data, libff::alt_bn128_modulus_q.data, libff::alt_bn128_q_limbs) < 0;
5050
}
5151

52-
std::optional<libff::alt_bn128_G1> decode_g1_element(const uint8_t* bytes64_be) noexcept {
53-
Scalar x{to_scalar(bytes64_be)};
52+
std::optional<libff::alt_bn128_G1> decode_g1_element(const uint8_t bytes_be[64]) noexcept {
53+
Scalar x{to_scalar(bytes_be)};
5454
if (!valid_element_of_fp(x)) {
5555
return {};
5656
}
5757

58-
Scalar y{to_scalar(bytes64_be + 32)};
58+
Scalar y{to_scalar(bytes_be + 32)};
5959
if (!valid_element_of_fp(y)) {
6060
return {};
6161
}
@@ -71,10 +71,10 @@ std::optional<libff::alt_bn128_G1> decode_g1_element(const uint8_t* bytes64_be)
7171
return point;
7272
}
7373

74-
static std::optional<libff::alt_bn128_Fq2> decode_fp2_element(const uint8_t* bytes64_be) noexcept {
74+
static std::optional<libff::alt_bn128_Fq2> decode_fp2_element(const uint8_t bytes_be[64]) noexcept {
7575
// big-endian encoding
76-
Scalar c0{to_scalar(bytes64_be + 32)};
77-
Scalar c1{to_scalar(bytes64_be)};
76+
Scalar c0{to_scalar(bytes_be + 32)};
77+
Scalar c1{to_scalar(bytes_be)};
7878

7979
if (!valid_element_of_fp(c0) || !valid_element_of_fp(c1)) {
8080
return {};
@@ -83,13 +83,13 @@ static std::optional<libff::alt_bn128_Fq2> decode_fp2_element(const uint8_t* byt
8383
return libff::alt_bn128_Fq2{c0, c1};
8484
}
8585

86-
std::optional<libff::alt_bn128_G2> decode_g2_element(const uint8_t* bytes128_be) noexcept {
87-
std::optional<libff::alt_bn128_Fq2> x{decode_fp2_element(bytes128_be)};
86+
std::optional<libff::alt_bn128_G2> decode_g2_element(const uint8_t bytes_be[128]) noexcept {
87+
std::optional<libff::alt_bn128_Fq2> x{decode_fp2_element(bytes_be)};
8888
if (!x) {
8989
return {};
9090
}
9191

92-
std::optional<libff::alt_bn128_Fq2> y{decode_fp2_element(bytes128_be + 64)};
92+
std::optional<libff::alt_bn128_Fq2> y{decode_fp2_element(bytes_be + 64)};
9393
if (!y) {
9494
return {};
9595
}

‎lib/silkpre/snark.hpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ using Scalar = libff::bigint<libff::alt_bn128_q_limbs>;
4141
// May be called many times from multiple threads.
4242
void init_libff() noexcept;
4343

44-
Scalar to_scalar(const uint8_t* bytes32_be) noexcept;
44+
Scalar to_scalar(const uint8_t bytes_be[32]) noexcept;
4545

46-
std::optional<libff::alt_bn128_G1> decode_g1_element(const uint8_t* bytes64_be) noexcept;
46+
std::optional<libff::alt_bn128_G1> decode_g1_element(const uint8_t bytes_be[64]) noexcept;
4747

48-
std::optional<libff::alt_bn128_G2> decode_g2_element(const uint8_t* bytes128_be) noexcept;
48+
std::optional<libff::alt_bn128_G2> decode_g2_element(const uint8_t bytes_be[128]) noexcept;
4949

5050
std::basic_string<uint8_t> encode_g1_element(libff::alt_bn128_G1 p) noexcept;
5151

0 commit comments

Comments
 (0)