From 53b38face021d3c60d6d8d14ce3e92989cfea45a Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Thu, 2 Mar 2023 20:35:37 +0200 Subject: [PATCH] Fix little-endian serialization in compute_challenge() (#168) --- src/c_kzg_4844.c | 7 +++---- tests/compute_blob_kzg_proof/success/proof.txt | 2 +- tests/verify_blob_kzg_proof/success/ok.txt | 2 +- tests/verify_blob_kzg_proof_batch/success/ok.txt | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/c_kzg_4844.c b/src/c_kzg_4844.c index 32c18b9..bbce7ec 100644 --- a/src/c_kzg_4844.c +++ b/src/c_kzg_4844.c @@ -722,12 +722,11 @@ static void compute_challenge( /* Copy domain separator */ memcpy(offset, FIAT_SHAMIR_PROTOCOL_DOMAIN, 16); offset += 16; - bytes_from_uint64( - offset, 0 - ); /* need to fill 16 bytes with the degree in little-endian */ - offset += 8; bytes_from_uint64(offset, FIELD_ELEMENTS_PER_BLOB); offset += 8; + /* Set all other bytes of this 16-byte (little-endian) field to zero */ + bytes_from_uint64(offset, 0); + offset += 8; /* Copy blob */ memcpy(offset, blob->bytes, BYTES_PER_BLOB); diff --git a/tests/compute_blob_kzg_proof/success/proof.txt b/tests/compute_blob_kzg_proof/success/proof.txt index e2ddc38..34639e6 100644 --- a/tests/compute_blob_kzg_proof/success/proof.txt +++ b/tests/compute_blob_kzg_proof/success/proof.txt @@ -1 +1 @@ -a1b505e8e7e1779eb2077464f5d793e4f36e5060970797c936370266095d048976557826ae0397d7d70256aff13cc6b0 \ No newline at end of file +9057e4724ea7b27acaae09b56155c86452a3c034b049d2d13fc2701845d2dcfa8d33612c1f9ecbaba7f7a920458eb5b8 \ No newline at end of file diff --git a/tests/verify_blob_kzg_proof/success/ok.txt b/tests/verify_blob_kzg_proof/success/ok.txt index 27ba77d..c508d53 100644 --- a/tests/verify_blob_kzg_proof/success/ok.txt +++ b/tests/verify_blob_kzg_proof/success/ok.txt @@ -1 +1 @@ -true +false diff --git a/tests/verify_blob_kzg_proof_batch/success/ok.txt b/tests/verify_blob_kzg_proof_batch/success/ok.txt index 27ba77d..c508d53 100644 --- a/tests/verify_blob_kzg_proof_batch/success/ok.txt +++ b/tests/verify_blob_kzg_proof_batch/success/ok.txt @@ -1 +1 @@ -true +false